<?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: Finding time between two events of a transaction in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Finding-time-between-two-events-of-a-transaction/m-p/243988#M72614</link>
    <description>&lt;P&gt;Rich , Thanks for the reply. I've tried this earlier. If I use startswith and endswith , it's giving me a count of four instead of two. &lt;/P&gt;</description>
    <pubDate>Fri, 11 Mar 2016 16:07:43 GMT</pubDate>
    <dc:creator>Kukkadapu</dc:creator>
    <dc:date>2016-03-11T16:07:43Z</dc:date>
    <item>
      <title>Finding time between two events of a transaction</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Finding-time-between-two-events-of-a-transaction/m-p/243981#M72607</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;
My events have the following structure&lt;/P&gt;

&lt;P&gt;_time=time id=[id] event=[event] &lt;/P&gt;

&lt;P&gt;For example:&lt;BR /&gt;
2016-03-09 01:47:41 id=1234 event=1 &lt;BR /&gt;
2016-03-09 01:47:42 id=1234 event=1 &lt;BR /&gt;
2016-03-09 01:47:43 id=1234 event=1 &lt;BR /&gt;
2016-03-09 01:47:44 id=1234 event=1 &lt;BR /&gt;
2016-03-09 01:47:45 id=1234 event=1 &lt;BR /&gt;
2016-03-09 01:47:46 id=1234 event=3&lt;BR /&gt;
2016-03-09 01:47:47 id=1234 event=3&lt;BR /&gt;
2016-03-09 01:47:48 id=1234 event=3 &lt;BR /&gt;
2016-03-09 01:47:49 id=1234 event=1 &lt;BR /&gt;
2016-03-09 01:47:50 id=1234 event=3 &lt;BR /&gt;
2016-03-09 01:47:51 id=1234 event=4&lt;BR /&gt;
2016-03-09 01:47:52 id=1234 event=5 &lt;BR /&gt;
2016-03-09 01:47:53 id=1234 event=2 &lt;BR /&gt;
2016-03-09 01:47:54 id=1234 event=2 &lt;BR /&gt;
2016-03-09 01:47:55 id=1234 event=1&lt;BR /&gt;&lt;BR /&gt;
2016-03-09 01:47:56 id=1234 event=1&lt;BR /&gt;
2016-03-09 01:47:57 id=1234 event=1 &lt;BR /&gt;
2016-03-09 01:47:58 id=1234 event=1 &lt;BR /&gt;
2016-03-09 01:47:59 id=1234 event=2 &lt;BR /&gt;
2016-03-09 01:47:60 id=1234 event=5  &lt;/P&gt;

&lt;P&gt;| mvcombine delim=" " event&lt;BR /&gt;
| nomv event&lt;/P&gt;

&lt;P&gt;Output&lt;BR /&gt;
1 1 1 1 1 3 3 3 1 3 4 5 2 2 1 1 1 1 2 5&lt;/P&gt;

&lt;P&gt;I need the time taken from event=1 to event=3&lt;BR /&gt;
I've used the following query but then it shows four transactions instead of two(In the data above we can see that there are only two places where the event changed from 1 to 3).&lt;/P&gt;

&lt;P&gt;| transaction Id startswith=eval(event=1) endswith=eval(event=3) maxevents=2&lt;/P&gt;

&lt;P&gt;Can you let me know how to get the time taken between the events?&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Wed, 09 Mar 2016 18:14:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Finding-time-between-two-events-of-a-transaction/m-p/243981#M72607</guid>
      <dc:creator>Kukkadapu</dc:creator>
      <dc:date>2016-03-09T18:14:53Z</dc:date>
    </item>
    <item>
      <title>Re: Finding time between two events of a transaction</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Finding-time-between-two-events-of-a-transaction/m-p/243982#M72608</link>
      <description>&lt;P&gt;So in your example above, would this be 1 of the 2 times it switches from 1 to 3?&lt;/P&gt;

&lt;P&gt;2016-03-09 01:47:45 id=1234 event=1 &lt;BR /&gt;
2016-03-09 01:47:46 id=1234 event=3&lt;/P&gt;

&lt;P&gt;If so, maybe something like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[your base search]
| sort id _time
| autoregress event as prevEvent p=1
| autoregress _time as prevTime p=1
| delta _time as delta_seconds p=1
| where event=3 AND prevEvent=1
| table id event _time prevTime prevEvent
| convert ctime(prevTime)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;So sort in ascending time order (and group id's together in case there are multiple).  Then for each event, use autoregress to store the event and time of the previous event.  And also use delta to give the difference (in seconds) between the current event and the last event.  Then filter for any rows where event is 3 and the previous event was 1.  And table out the info.&lt;/P&gt;</description>
      <pubDate>Thu, 10 Mar 2016 23:59:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Finding-time-between-two-events-of-a-transaction/m-p/243982#M72608</guid>
      <dc:creator>maciep</dc:creator>
      <dc:date>2016-03-10T23:59:45Z</dc:date>
    </item>
    <item>
      <title>Re: Finding time between two events of a transaction</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Finding-time-between-two-events-of-a-transaction/m-p/243983#M72609</link>
      <description>&lt;P&gt;Maciep, Thanks for the reply.&lt;/P&gt;

&lt;P&gt;1 to 3 is switched two times&lt;/P&gt;

&lt;P&gt;2016-03-09 01:47:45 id=1234 event=1 &lt;BR /&gt;
2016-03-09 01:47:46 id=1234 event=3 &lt;/P&gt;

&lt;P&gt;AND &lt;/P&gt;

&lt;P&gt;2016-03-09 01:47:49 id=1234 event=1 &lt;BR /&gt;
2016-03-09 01:47:50 id=1234 event=3 &lt;/P&gt;

&lt;P&gt;I need the average time  - The average time is going to be 1 second&lt;/P&gt;

&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Mar 2016 00:08:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Finding-time-between-two-events-of-a-transaction/m-p/243983#M72609</guid>
      <dc:creator>Kukkadapu</dc:creator>
      <dc:date>2016-03-11T00:08:46Z</dc:date>
    </item>
    <item>
      <title>Re: Finding time between two events of a transaction</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Finding-time-between-two-events-of-a-transaction/m-p/243984#M72610</link>
      <description>&lt;P&gt;This worked &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; Thanks Maciep. &lt;/P&gt;

&lt;P&gt;And can you help me how to have a timechart for event 1 and event 3 where it changed from event 1 to 3 (So I can display a line chart for both event 1 and event 3 ).  That would be great. &lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Fri, 11 Mar 2016 00:25:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Finding-time-between-two-events-of-a-transaction/m-p/243984#M72610</guid>
      <dc:creator>Kukkadapu</dc:creator>
      <dc:date>2016-03-11T00:25:53Z</dc:date>
    </item>
    <item>
      <title>Re: Finding time between two events of a transaction</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Finding-time-between-two-events-of-a-transaction/m-p/243985#M72611</link>
      <description>&lt;P&gt;I'm not sure I can visualize what you want to see.  You want a count of events 1 &amp;amp; 3 that were involved in the switch over time?  &lt;/P&gt;</description>
      <pubDate>Fri, 11 Mar 2016 11:58:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Finding-time-between-two-events-of-a-transaction/m-p/243985#M72611</guid>
      <dc:creator>maciep</dc:creator>
      <dc:date>2016-03-11T11:58:45Z</dc:date>
    </item>
    <item>
      <title>Re: Finding time between two events of a transaction</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Finding-time-between-two-events-of-a-transaction/m-p/243986#M72612</link>
      <description>&lt;P&gt;For this part, it might be you can do this with only a tiny change to your original search.  The idea would be to filter out the transactions that weren't a 1-3 transition.  Then just feed it to timechart.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| transaction Id startswith=eval(event=1) endswith=eval(event=3) maxevents=2
| search eventcount=2
| timechart count
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Totally untested and just a guess, but that may be all you need.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Mar 2016 12:11:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Finding-time-between-two-events-of-a-transaction/m-p/243986#M72612</guid>
      <dc:creator>Richfez</dc:creator>
      <dc:date>2016-03-11T12:11:16Z</dc:date>
    </item>
    <item>
      <title>Re: Finding time between two events of a transaction</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Finding-time-between-two-events-of-a-transaction/m-p/243987#M72613</link>
      <description>&lt;P&gt;Yes Maciep.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Mar 2016 16:06:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Finding-time-between-two-events-of-a-transaction/m-p/243987#M72613</guid>
      <dc:creator>Kukkadapu</dc:creator>
      <dc:date>2016-03-11T16:06:25Z</dc:date>
    </item>
    <item>
      <title>Re: Finding time between two events of a transaction</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Finding-time-between-two-events-of-a-transaction/m-p/243988#M72614</link>
      <description>&lt;P&gt;Rich , Thanks for the reply. I've tried this earlier. If I use startswith and endswith , it's giving me a count of four instead of two. &lt;/P&gt;</description>
      <pubDate>Fri, 11 Mar 2016 16:07:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Finding-time-between-two-events-of-a-transaction/m-p/243988#M72614</guid>
      <dc:creator>Kukkadapu</dc:creator>
      <dc:date>2016-03-11T16:07:43Z</dc:date>
    </item>
    <item>
      <title>Re: Finding time between two events of a transaction</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Finding-time-between-two-events-of-a-transaction/m-p/243989#M72615</link>
      <description>&lt;P&gt;ok, not sure if this the prettiest/best, but I &lt;EM&gt;think&lt;/EM&gt; it gets the job done, but there might be a better approach&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[your base search]
 | sort id _time
 | autoregress event as prevEvent p=1
 | autoregress _time as prevTime p=1
 | delta _time as delta_seconds p=1
 | where event=3 AND prevEvent=1
 | eval tempEvent=split("1,3",",") 
 | mvexpand tempEvent 
 | eval _time = if(tempEvent=1,prevTime,_time) 
 | timechart count by tempEvent
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;So after the original search, we have two time fields in each row, the time of event 3 and the time of the previous event 1.  If we want to map both of those times in a chart, then we need to separate them to separate events again.&lt;/P&gt;

&lt;P&gt;So the search is creating a new multi-value field called temp Event that just contains "1" and "3".  Then it uses mvexpand to break that new field into two separate events.  And for one of those two new events, _time is set to the prevTime.  And so now we can use timechart to map those counts across time.&lt;/P&gt;

&lt;P&gt;Hopefully this is kind of what you're after&lt;/P&gt;</description>
      <pubDate>Sat, 12 Mar 2016 02:26:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Finding-time-between-two-events-of-a-transaction/m-p/243989#M72615</guid>
      <dc:creator>maciep</dc:creator>
      <dc:date>2016-03-12T02:26:51Z</dc:date>
    </item>
    <item>
      <title>Re: Finding time between two events of a transaction</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Finding-time-between-two-events-of-a-transaction/m-p/243990#M72616</link>
      <description>&lt;P&gt;Yes, Perfect. Thanks Maciep &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Mar 2016 17:11:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Finding-time-between-two-events-of-a-transaction/m-p/243990#M72616</guid>
      <dc:creator>Kukkadapu</dc:creator>
      <dc:date>2016-03-14T17:11:14Z</dc:date>
    </item>
  </channel>
</rss>

