<?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: How to find the time difference between the current and previous event per field? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-time-difference-between-the-current-and-previous/m-p/135348#M37011</link>
    <description>&lt;P&gt;Thanks for your answer, but I've tried that before and this search gives me the following result:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; 11/26/14 12:00:00   host='host1';app='app1';answer=90.00;answer_avg=80
 11/26/14 11:50:00   host='host1';app='app2';answer=5.00;answer_avg=5.6
 11/26/14 11:40:00   host='host1';app='app3';answer=10.00;answer_avg=11
 11/26/14 11:30:00   host='host1';app='app1';answer=80.00;answer_avg=80;delay=1800
 11/26/14 11:20:00   host='host1';app='app2';answer=4.00;answer_avg=5.6;delay=1800
 11/26/14 11:10:00   host='host1';app='app3';answer=12.00;answer_avg=11;delay=1800
 11/26/14 11:00:00   host='host1';app='app1';answer=70.00;answer_avg=80;delay=1800
 11/26/14 10:50:00   host='host1';app='app2';answer=8.00;answer_avg=5.6;delay=1800
 11/26/14 10:40:00   host='host1';app='app3';answer=11.00;answer_avg=11;delay=1800
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I.E., the delay of the first event for each app is calculated only on the second event.&lt;/P&gt;</description>
    <pubDate>Wed, 26 Nov 2014 20:07:51 GMT</pubDate>
    <dc:creator>rodrigorenie</dc:creator>
    <dc:date>2014-11-26T20:07:51Z</dc:date>
    <item>
      <title>How to find the time difference between the current and previous event per field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-time-difference-between-the-current-and-previous/m-p/135346#M37009</link>
      <description>&lt;P&gt;Hello everyone.&lt;/P&gt;

&lt;P&gt;I'm using "eventstats" to generate the average of a certain field in every event that Splunk collects, something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;host=host1 index=itcam app=* | eventstats avg(answer) as answer_avg by app
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The result is something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;11/26/14 12:00:00   host='host1';app='app1';answer=90.00;answer_avg=80
11/26/14 11:50:00   host='host1';app='app2';answer=5.00;answer_avg=5.6
11/26/14 11:40:00   host='host1';app='app3';answer=10.00;answer_avg=11
11/26/14 11:30:00   host='host1';app='app1';answer=80.00;answer_avg=80
11/26/14 11:20:00   host='host1';app='app2';answer=4.00;answer_avg=5.6
11/26/14 11:10:00   host='host1';app='app3';answer=12.00;answer_avg=11
11/26/14 11:00:00   host='host1';app='app1';answer=70.00;answer_avg=80
11/26/14 10:50:00   host='host1';app='app2';answer=8.00;answer_avg=5.6
11/26/14 10:40:00   host='host1';app='app3';answer=11.00;answer_avg=11
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Which works great, because I have the average answer per "app" field in every event.&lt;/P&gt;

&lt;P&gt;What I need to do now is calculate how long the current event took to occur based on the previous event, also separated by the "app" field. &lt;/P&gt;

&lt;P&gt;For example, in the above result, latest event is from "app1", which ocurred at "12:00". The previous event of "app1" ocurred at "11:30", which means that the latest event from "app1" (at 12:00) took 30 minutes since the last one (at 11:30).&lt;/P&gt;

&lt;P&gt;I would like to create a field, called "delay" (for example) in every event, including the latest one, with the time difference in seconds (or minutes) between an event and it's predecessor PER APP, resulting in something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; 11/26/14 12:00:00   host='host1';app='app1';answer=90.00;answer_avg=80;delay=1800
 11/26/14 11:50:00   host='host1';app='app2';answer=5.00;answer_avg=5.6;delay=1800
 11/26/14 11:40:00   host='host1';app='app3';answer=10.00;answer_avg=11;delay=1800
 11/26/14 11:30:00   host='host1';app='app1';answer=80.00;answer_avg=80;delay=1800
 11/26/14 11:20:00   host='host1';app='app2';answer=4.00;answer_avg=5.6;delay=1800
 11/26/14 11:10:00   host='host1';app='app3';answer=12.00;answer_avg=11;delay=1800
 11/26/14 11:00:00   host='host1';app='app1';answer=70.00;answer_avg=80;delay=1800
 11/26/14 10:50:00   host='host1';app='app2';answer=8.00;answer_avg=5.6;delay=1800
 11/26/14 10:40:00   host='host1';app='app3';answer=11.00;answer_avg=11;delay=1800
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;In this poor example, every app took exactly 30 minutes (or 1800 seconds) to execute.&lt;/P&gt;

&lt;P&gt;Thanks in advance!!&lt;/P&gt;</description>
      <pubDate>Wed, 26 Nov 2014 18:09:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-time-difference-between-the-current-and-previous/m-p/135346#M37009</guid>
      <dc:creator>rodrigorenie</dc:creator>
      <dc:date>2014-11-26T18:09:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the time difference between the current and previous event per field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-time-difference-between-the-current-and-previous/m-p/135347#M37010</link>
      <description>&lt;P&gt;There's a way to use &lt;CODE&gt;streamstats&lt;/CODE&gt; where it works on the previous item, not the current one, by using &lt;CODE&gt;current=f&lt;/CODE&gt;. If you add such an item to your results, you'll have what you need to do a time difference, like so:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;host=host1 index=itcam app=*
| eventstats avg(answer) as answer_avg by app
| streamstats current=f last(_time) as LastTime by app
| eval delay=LastTime-_time
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Hope this helps!&lt;/P&gt;</description>
      <pubDate>Wed, 26 Nov 2014 19:33:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-time-difference-between-the-current-and-previous/m-p/135347#M37010</guid>
      <dc:creator>aweitzman</dc:creator>
      <dc:date>2014-11-26T19:33:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the time difference between the current and previous event per field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-time-difference-between-the-current-and-previous/m-p/135348#M37011</link>
      <description>&lt;P&gt;Thanks for your answer, but I've tried that before and this search gives me the following result:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; 11/26/14 12:00:00   host='host1';app='app1';answer=90.00;answer_avg=80
 11/26/14 11:50:00   host='host1';app='app2';answer=5.00;answer_avg=5.6
 11/26/14 11:40:00   host='host1';app='app3';answer=10.00;answer_avg=11
 11/26/14 11:30:00   host='host1';app='app1';answer=80.00;answer_avg=80;delay=1800
 11/26/14 11:20:00   host='host1';app='app2';answer=4.00;answer_avg=5.6;delay=1800
 11/26/14 11:10:00   host='host1';app='app3';answer=12.00;answer_avg=11;delay=1800
 11/26/14 11:00:00   host='host1';app='app1';answer=70.00;answer_avg=80;delay=1800
 11/26/14 10:50:00   host='host1';app='app2';answer=8.00;answer_avg=5.6;delay=1800
 11/26/14 10:40:00   host='host1';app='app3';answer=11.00;answer_avg=11;delay=1800
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I.E., the delay of the first event for each app is calculated only on the second event.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Nov 2014 20:07:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-time-difference-between-the-current-and-previous/m-p/135348#M37011</guid>
      <dc:creator>rodrigorenie</dc:creator>
      <dc:date>2014-11-26T20:07:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the time difference between the current and previous event per field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-time-difference-between-the-current-and-previous/m-p/135349#M37012</link>
      <description>&lt;P&gt;Well, either the earliest or the latest one has to have no value, right? If you want the latest one to have values (but obviously, the earliest ones will not), sort and resort the data and flip the calculation:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;host=host1 index=itcam app=*
| eventstats avg(answer) as answer_avg by app
| sort 0 _time
| streamstats current=f last(_time) as LastTime by app
| eval delay=_time-LastTime
| sort 0 -_time
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 26 Nov 2014 20:15:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-time-difference-between-the-current-and-previous/m-p/135349#M37012</guid>
      <dc:creator>aweitzman</dc:creator>
      <dc:date>2014-11-26T20:15:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the time difference between the current and previous event per field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-time-difference-between-the-current-and-previous/m-p/135350#M37013</link>
      <description>&lt;P&gt;I promoted the one that worked for you from comment to answer (somehow it lost your response to it).&lt;/P&gt;</description>
      <pubDate>Wed, 26 Nov 2014 20:25:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-time-difference-between-the-current-and-previous/m-p/135350#M37013</guid>
      <dc:creator>aweitzman</dc:creator>
      <dc:date>2014-11-26T20:25:18Z</dc:date>
    </item>
  </channel>
</rss>

