<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: calculate time difference between timestamps for two results on a same field in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/calculate-time-difference-between-timestamps-for-two-results-on/m-p/192582#M38388</link>
    <description>&lt;P&gt;So borrowing a trick from &lt;A href="http://conf.splunk.com/sessions/2014"&gt;Kyle Smith's conf2014 talk&lt;/A&gt;... We could do something like the following: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;serial_num="NTEST9B" | eval p_{phase} = _time | stats first(p_*) as * by serial_num,host,segment_id
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This gives us results that has the callresult time and the precall time for every host and segment id for a given serial num. &lt;/P&gt;

&lt;P&gt;The calculating the difference is as simple as&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... the above search |  eval difference=callresult-precall
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;difference being of course value in seconds since _time is epoch time.&lt;/P&gt;</description>
    <pubDate>Mon, 23 Mar 2015 18:56:44 GMT</pubDate>
    <dc:creator>acharlieh</dc:creator>
    <dc:date>2015-03-23T18:56:44Z</dc:date>
    <item>
      <title>calculate time difference between timestamps for two results on a same field</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/calculate-time-difference-between-timestamps-for-two-results-on/m-p/192581#M38387</link>
      <description>&lt;P&gt;I have data that I have currently exported from splunk by running a search on splunk as follows. The time data (in the table below) was broken down and adjusted on excel. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;serial_num="NTEST9B"  | eval sTime=strftime(_time,"%Y-%m-%d %H:%M:%S") |table serial_num host segment_id phase sTime| sort segment_id,host,phase
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;--&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;serial_num  host                          seg_id  phase        Date        time
NTEST9B  ip-typeA.slavenode.test.com   157   callresult   3/13/2015   5:06:55
NTEST9B  ip-typeA.slavenode.test.com   157   precall      3/13/2015   5:06:49
NTEST9B  ip-typeB.slavenode.test.com   158   callresult   3/13/2015   5:06:45
NTEST9B  ip-typeB.slavenode.test.com   158   precall      3/13/2015   5:06:41
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;For every device, there are segments that are run on a specific host, and I have extracted the time for precall and call result (both of which are values of the field "phase" on splunk) for each segment ID. Duration for processing time for each segment would be difference btw 'precall' and 'callresult', and they would always be from the same host. &lt;/P&gt;

&lt;P&gt;I want to modify my search such that for a given device, I get the time difference between both values for my field "phase" (precall and callresult) for a specific segment ID from a given host in the same search.  So basically, for host A and segment #157, the time difference would be timestamp (callresult) - timestamp (precall). The next step in this process would be to set an alert when the time difference exceeds a certain amount, and so I want splunk to be able to calculate time difference by itself.&lt;/P&gt;

&lt;P&gt;Any help in this regard would be great!&lt;/P&gt;</description>
      <pubDate>Mon, 23 Mar 2015 18:16:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/calculate-time-difference-between-timestamps-for-two-results-on/m-p/192581#M38387</guid>
      <dc:creator>aramakrishnan</dc:creator>
      <dc:date>2015-03-23T18:16:32Z</dc:date>
    </item>
    <item>
      <title>Re: calculate time difference between timestamps for two results on a same field</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/calculate-time-difference-between-timestamps-for-two-results-on/m-p/192582#M38388</link>
      <description>&lt;P&gt;So borrowing a trick from &lt;A href="http://conf.splunk.com/sessions/2014"&gt;Kyle Smith's conf2014 talk&lt;/A&gt;... We could do something like the following: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;serial_num="NTEST9B" | eval p_{phase} = _time | stats first(p_*) as * by serial_num,host,segment_id
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This gives us results that has the callresult time and the precall time for every host and segment id for a given serial num. &lt;/P&gt;

&lt;P&gt;The calculating the difference is as simple as&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... the above search |  eval difference=callresult-precall
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;difference being of course value in seconds since _time is epoch time.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Mar 2015 18:56:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/calculate-time-difference-between-timestamps-for-two-results-on/m-p/192582#M38388</guid>
      <dc:creator>acharlieh</dc:creator>
      <dc:date>2015-03-23T18:56:44Z</dc:date>
    </item>
    <item>
      <title>Re: calculate time difference between timestamps for two results on a same field</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/calculate-time-difference-between-timestamps-for-two-results-on/m-p/192583#M38389</link>
      <description>&lt;P&gt;Thank you, @acharlieh. If I were to set a custom conditional alert on this to set off an alert anytime "difference" &amp;gt; 20, and the column that spits out the time difference is "difference" (it's not a field on Splunk), would using "eval difference&amp;gt;20" as the 'condition' work?&lt;/P&gt;</description>
      <pubDate>Mon, 23 Mar 2015 20:53:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/calculate-time-difference-between-timestamps-for-two-results-on/m-p/192583#M38389</guid>
      <dc:creator>aramakrishnan</dc:creator>
      <dc:date>2015-03-23T20:53:06Z</dc:date>
    </item>
    <item>
      <title>Re: calculate time difference between timestamps for two results on a same field</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/calculate-time-difference-between-timestamps-for-two-results-on/m-p/192584#M38390</link>
      <description>&lt;P&gt;"difference" is not an extracted field, but the field should be in your results after the eval command. (which of course uses the fields created by the stats command which uses the fields from the previous eval command). &lt;BR /&gt;
If it is not a field, then there is a problem (you can try &lt;CODE&gt;| table *&lt;/CODE&gt; at the end of your search to force a tabular view and see what's set or not. I left off the formatting and sorting that you're doing in your original question, but it can be added in, just make sure to carry forward difference.)&lt;/P&gt;

&lt;P&gt;Conditions of &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.2.2/Alert/Definescheduledalerts#Advanced_conditional_alert" target="_blank"&gt;advanced conditional alerts&lt;/A&gt; are like splunk commands tacked on to the end of the search being run. You'd therefore want either "where difference &amp;gt; 20" or "search difference &amp;gt; 20" to alert where the events are greater than 20 seconds apart for a given serial_num, host, segment_id.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 19:19:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/calculate-time-difference-between-timestamps-for-two-results-on/m-p/192584#M38390</guid>
      <dc:creator>acharlieh</dc:creator>
      <dc:date>2020-09-28T19:19:54Z</dc:date>
    </item>
    <item>
      <title>Re: calculate time difference between timestamps for two results on a same field</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/calculate-time-difference-between-timestamps-for-two-results-on/m-p/192585#M38391</link>
      <description>&lt;P&gt;As a follow-up to this, I have a new situation where all of the fields from above are the same, except that "phase" is no longer a field. I instead have 2 eventtypes (callstart &amp;amp; callend), one of which will produce the 'precall' logs and the other the 'postcall' logs. &lt;/P&gt;

&lt;P&gt;Would eval p_{phase} = _time work if I substitute "phase" with the eventtype?&lt;/P&gt;

&lt;P&gt;I still need to perform the exact same function i.e., calculate the time difference between a specific segment ID &amp;amp; host in the callstart and callend eventtypes.&lt;/P&gt;

&lt;P&gt;I'm assuming the same eval syntax wouldn't work but if you have suggestions for a modification, please let me know!&lt;/P&gt;</description>
      <pubDate>Fri, 27 Mar 2015 23:28:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/calculate-time-difference-between-timestamps-for-two-results-on/m-p/192585#M38391</guid>
      <dc:creator>aramakrishnan</dc:creator>
      <dc:date>2015-03-27T23:28:29Z</dc:date>
    </item>
    <item>
      <title>Re: calculate time difference between timestamps for two results on a same field</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/calculate-time-difference-between-timestamps-for-two-results-on/m-p/192586#M38392</link>
      <description>&lt;P&gt;So, a bit of a difference between &lt;CODE&gt;phase&lt;/CODE&gt; and &lt;CODE&gt;eventtype&lt;/CODE&gt; is it's much more likely that &lt;CODE&gt;eventtype&lt;/CODE&gt; could be multivalued than &lt;CODE&gt;phase&lt;/CODE&gt;. (if that happens, then you wind up with all values as your new field. An alternative syntax therefore could be:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval p_precall=if(eventtype="onetype",_time,null()) |  eval p_callresult=if(eventtype="othertype",_time,null()) | 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 28 Mar 2015 04:12:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/calculate-time-difference-between-timestamps-for-two-results-on/m-p/192586#M38392</guid>
      <dc:creator>acharlieh</dc:creator>
      <dc:date>2015-03-28T04:12:35Z</dc:date>
    </item>
  </channel>
</rss>

