<?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: Duration between events in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Duration-between-events/m-p/451381#M127829</link>
    <description>&lt;P&gt;Shouldn't that be: &lt;CODE&gt;duration=duration/60&lt;/CODE&gt;?&lt;/P&gt;

&lt;P&gt;I think my search should be: &lt;CODE&gt;my_search | streamstats window=2 global=f earliest(_time) as start latest(_time) as end earliest(stop_direction) as dir1 latest(stop_direction) as dir2 by vehicle_id | transaction vehicle_id endswith=eval(dir1!=dir2) | eval duration=duration/60&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;But I want to chart the "trip" (or the "transaction ID") by the duration. For each transaction, I'd need a monotonically increasing integer. How can I get that?&lt;/P&gt;</description>
    <pubDate>Thu, 21 Mar 2019 17:56:22 GMT</pubDate>
    <dc:creator>plucas_splunk</dc:creator>
    <dc:date>2019-03-21T17:56:22Z</dc:date>
    <item>
      <title>Duration between events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Duration-between-events/m-p/451379#M127827</link>
      <description>&lt;P&gt;Given transit data like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;2019-03-19 19:00:32 GMT vehicle_id="58" stop_direction=Inbound
2019-03-19 19:05:45 GMT vehicle_id="57" stop_direction=Outbound
2019-03-19 19:10:45 GMT vehicle_id="59" stop_direction=Outbound
2019-03-19 19:21:32 GMT vehicle_id="58" stop_direction=Inbound
2019-03-19 19:25:06 GMT vehicle_id="57" stop_direction=Outbound
2019-03-19 19:37:43 GMT vehicle_id="58" stop_direction=Outbound
2019-03-19 19:41:02 GMT vehicle_id="59" stop_direction=Inbound
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;A "trip" is starting at one end of the line and going to the other end. I want to calculate the duration of every trip. You know when a trip ends because the a particular vehicle's &lt;CODE&gt;stop_direction&lt;/CODE&gt; changes either from "Inbound" to "Outbound" or vice versa.&lt;/P&gt;

&lt;P&gt;For example, when vehicle 58 changes from "Inbound" (line 4) to "Outbound" (line 6), then it had a "trip" starting from the oldest contiguous "Inbound" (line 1) to the last "Inbound" (line 4) before changing to "Outbound" (line 6). Hence, the duration would conceptually be time_of_event(4) - time_of_event(1).&lt;/P&gt;

&lt;P&gt;Explained another way: for a given vehicle, if you were to plot its stop direction (where &lt;CODE&gt;I&lt;/CODE&gt; is "Inbound" and &lt;CODE&gt;O&lt;/CODE&gt; is "Outbound"), then:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;IIII OOOOO III OOO IIIIIIII
^^^^ ^^^^^ ^^^ ^^^ ^^^^^^^^
T1   T2    T3  T4  T5
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I.e., a run of the same stop direction constitutes a "trip." When the direction changes, it's the next trip.&lt;/P&gt;

&lt;P&gt;I want to calculate the duration of every trip and chart it such that the X-axis is the trip and the Y-axis is the duration of that trip.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 23:46:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Duration-between-events/m-p/451379#M127827</guid>
      <dc:creator>plucas_splunk</dc:creator>
      <dc:date>2020-09-29T23:46:36Z</dc:date>
    </item>
    <item>
      <title>Re: Duration between events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Duration-between-events/m-p/451380#M127828</link>
      <description>&lt;P&gt;You could look at the transaction command to help you here:&lt;BR /&gt;
&lt;A href="https://docs.splunk.com/Documentation/Splunk/7.2.4/SearchReference/Transaction"&gt;https://docs.splunk.com/Documentation/Splunk/7.2.4/SearchReference/Transaction&lt;/A&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;..your search..|transaction vehicle_id startswith=Outbound endswith=Inbound|transaction vehicle_id startswith=Inbound endswith=Outbound|eval stops=eventcount, duration=round(duration/1000,0)|table vehicle_id stops duration
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Duration will be in seconds&lt;/P&gt;</description>
      <pubDate>Thu, 21 Mar 2019 12:06:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Duration-between-events/m-p/451380#M127828</guid>
      <dc:creator>nickhills</dc:creator>
      <dc:date>2019-03-21T12:06:24Z</dc:date>
    </item>
    <item>
      <title>Re: Duration between events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Duration-between-events/m-p/451381#M127829</link>
      <description>&lt;P&gt;Shouldn't that be: &lt;CODE&gt;duration=duration/60&lt;/CODE&gt;?&lt;/P&gt;

&lt;P&gt;I think my search should be: &lt;CODE&gt;my_search | streamstats window=2 global=f earliest(_time) as start latest(_time) as end earliest(stop_direction) as dir1 latest(stop_direction) as dir2 by vehicle_id | transaction vehicle_id endswith=eval(dir1!=dir2) | eval duration=duration/60&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;But I want to chart the "trip" (or the "transaction ID") by the duration. For each transaction, I'd need a monotonically increasing integer. How can I get that?&lt;/P&gt;</description>
      <pubDate>Thu, 21 Mar 2019 17:56:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Duration-between-events/m-p/451381#M127829</guid>
      <dc:creator>plucas_splunk</dc:creator>
      <dc:date>2019-03-21T17:56:22Z</dc:date>
    </item>
  </channel>
</rss>

