<?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 can I calculate the average duration between changes of two fields / events? in Monitoring Splunk</title>
    <link>https://community.splunk.com/t5/Monitoring-Splunk/How-can-I-calculate-the-average-duration-between-changes-of-two/m-p/432815#M6501</link>
    <description>&lt;P&gt;One more question: what ist the function of &lt;CODE&gt;| eval _time=min_time&lt;/CODE&gt; ?&lt;/P&gt;</description>
    <pubDate>Wed, 12 Dec 2018 08:30:43 GMT</pubDate>
    <dc:creator>j_r</dc:creator>
    <dc:date>2018-12-12T08:30:43Z</dc:date>
    <item>
      <title>How can I calculate the average duration between changes of two fields / events?</title>
      <link>https://community.splunk.com/t5/Monitoring-Splunk/How-can-I-calculate-the-average-duration-between-changes-of-two/m-p/432809#M6495</link>
      <description>&lt;P&gt;Hi &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;My base search looks like this:&lt;BR /&gt;
&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/6238iC2C95B6D00C20702/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;BR /&gt;
I used  &lt;CODE&gt;| dedup RobotSubState&lt;/CODE&gt; for this screenshot. In reality, every 1 second, an event is output as a result.&lt;/P&gt;

&lt;P&gt;How can I calculate the average duration for a state ?&lt;/P&gt;

&lt;P&gt;For example: &lt;BR /&gt;
time 1: RobotSubState = Parked&lt;BR /&gt;
time 2: RobotSubState = Parked&lt;BR /&gt;
time 3: RobotSubState = Parked&lt;BR /&gt;
time 4: RobotSubState = Driving&lt;BR /&gt;
time 5: RobotSubState = Driving&lt;BR /&gt;
time 6: RobotSubState = Parked&lt;/P&gt;

&lt;P&gt;Here i would need the time 4 + time 5 as duration or time 1 + time 2 + time 3.&lt;/P&gt;</description>
      <pubDate>Mon, 10 Dec 2018 14:24:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Monitoring-Splunk/How-can-I-calculate-the-average-duration-between-changes-of-two/m-p/432809#M6495</guid>
      <dc:creator>j_r</dc:creator>
      <dc:date>2018-12-10T14:24:15Z</dc:date>
    </item>
    <item>
      <title>Re: How can I calculate the average duration between changes of two fields / events?</title>
      <link>https://community.splunk.com/t5/Monitoring-Splunk/How-can-I-calculate-the-average-duration-between-changes-of-two/m-p/432810#M6496</link>
      <description>&lt;P&gt;Hello @j_r,&lt;/P&gt;

&lt;P&gt;Check out this search. It consists of two parts.&lt;/P&gt;

&lt;P&gt;Here is the first part of the search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your base search
| streamstats count as sequence
| streamstats first(sequence) as group reset_on_change=true by RobotSubState
| ...
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This will give you:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;_time    RobotSubState   sequence    group
time 1   Parked          1           1
time 2   Parked          2           1
time 3   Parked          3           1
time 4   Driving         4           4
time 5   Driving         5           4
time 6   Parked          6           6
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Now here is the second part:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;...
| stats min(_time) as min_time max(_time) as max_time first(RobotSubState) as RobotSubState by group
| eval duration=max_time-min_time | eval _time=min_time
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This will get you:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;group    min_time    max_time    RobotSubState    _time      duration
1        time 3      time 1      Parked           time 1     ...
4        time 5      time 4      Driving          time 4     ...
6        time 6      time 6      Parked           time 6     ...
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 11 Dec 2018 09:53:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Monitoring-Splunk/How-can-I-calculate-the-average-duration-between-changes-of-two/m-p/432810#M6496</guid>
      <dc:creator>whrg</dc:creator>
      <dc:date>2018-12-11T09:53:10Z</dc:date>
    </item>
    <item>
      <title>Re: How can I calculate the average duration between changes of two fields / events?</title>
      <link>https://community.splunk.com/t5/Monitoring-Splunk/How-can-I-calculate-the-average-duration-between-changes-of-two/m-p/432811#M6497</link>
      <description>&lt;P&gt;This one works.&lt;BR /&gt;
I would like to display the avg duration in a chart by RobotSubstate.&lt;BR /&gt;
I tried with &lt;CODE&gt;| stats avg(duration) by RobotSubState&lt;/CODE&gt; but the time is displayed as epoch time.&lt;BR /&gt;
tostring(X) didnt work :/. &lt;BR /&gt;
Any suggestions?&lt;/P&gt;</description>
      <pubDate>Tue, 11 Dec 2018 11:55:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Monitoring-Splunk/How-can-I-calculate-the-average-duration-between-changes-of-two/m-p/432811#M6497</guid>
      <dc:creator>j_r</dc:creator>
      <dc:date>2018-12-11T11:55:33Z</dc:date>
    </item>
    <item>
      <title>Re: How can I calculate the average duration between changes of two fields / events?</title>
      <link>https://community.splunk.com/t5/Monitoring-Splunk/How-can-I-calculate-the-average-duration-between-changes-of-two/m-p/432812#M6498</link>
      <description>&lt;P&gt;In my search above, duration returns the time difference in seconds. (Not as epoch time.)&lt;BR /&gt;
So your question should be how to convert seconds to HH:MM:SS.&lt;BR /&gt;
I found this question here: &lt;A href="https://answers.splunk.com/answers/439/how-to-convert-second-to-hh-mm-ss-format-in-the-exported-search-result.html"&gt;How to convert second to HH:MM:SS format in the exported search result?&lt;/A&gt;&lt;BR /&gt;
So try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | eval duration_in_hhmmss=tostring(duration, "duration")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 11 Dec 2018 12:13:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Monitoring-Splunk/How-can-I-calculate-the-average-duration-between-changes-of-two/m-p/432812#M6498</guid>
      <dc:creator>whrg</dc:creator>
      <dc:date>2018-12-11T12:13:08Z</dc:date>
    </item>
    <item>
      <title>Re: How can I calculate the average duration between changes of two fields / events?</title>
      <link>https://community.splunk.com/t5/Monitoring-Splunk/How-can-I-calculate-the-average-duration-between-changes-of-two/m-p/432813#M6499</link>
      <description>&lt;P&gt;I also found this thread which looks similar to your question:&lt;BR /&gt;
&lt;A href="https://answers.splunk.com/answers/552002/transaction-that-ends-if-a-certain-value-changes.html"&gt;transaction that ends if a certain value changes&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Dec 2018 15:30:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Monitoring-Splunk/How-can-I-calculate-the-average-duration-between-changes-of-two/m-p/432813#M6499</guid>
      <dc:creator>whrg</dc:creator>
      <dc:date>2018-12-11T15:30:59Z</dc:date>
    </item>
    <item>
      <title>Re: How can I calculate the average duration between changes of two fields / events?</title>
      <link>https://community.splunk.com/t5/Monitoring-Splunk/How-can-I-calculate-the-average-duration-between-changes-of-two/m-p/432814#M6500</link>
      <description>&lt;P&gt;Okay so I just learnt about the &lt;EM&gt;reset_on_change&lt;/EM&gt; parameter.&lt;BR /&gt;
I edited my original answer to make the search much shorter.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 22:20:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Monitoring-Splunk/How-can-I-calculate-the-average-duration-between-changes-of-two/m-p/432814#M6500</guid>
      <dc:creator>whrg</dc:creator>
      <dc:date>2020-09-29T22:20:14Z</dc:date>
    </item>
    <item>
      <title>Re: How can I calculate the average duration between changes of two fields / events?</title>
      <link>https://community.splunk.com/t5/Monitoring-Splunk/How-can-I-calculate-the-average-duration-between-changes-of-two/m-p/432815#M6501</link>
      <description>&lt;P&gt;One more question: what ist the function of &lt;CODE&gt;| eval _time=min_time&lt;/CODE&gt; ?&lt;/P&gt;</description>
      <pubDate>Wed, 12 Dec 2018 08:30:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Monitoring-Splunk/How-can-I-calculate-the-average-duration-between-changes-of-two/m-p/432815#M6501</guid>
      <dc:creator>j_r</dc:creator>
      <dc:date>2018-12-12T08:30:43Z</dc:date>
    </item>
    <item>
      <title>Re: How can I calculate the average duration between changes of two fields / events?</title>
      <link>https://community.splunk.com/t5/Monitoring-Splunk/How-can-I-calculate-the-average-duration-between-changes-of-two/m-p/432816#M6502</link>
      <description>&lt;P&gt;It copies the value of min_time to _time.&lt;BR /&gt;
The thing about _time is that it displays time objects (epoch times) in a human readable format.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Dec 2018 09:12:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Monitoring-Splunk/How-can-I-calculate-the-average-duration-between-changes-of-two/m-p/432816#M6502</guid>
      <dc:creator>whrg</dc:creator>
      <dc:date>2018-12-12T09:12:10Z</dc:date>
    </item>
    <item>
      <title>Re: How can I calculate the average duration between changes of two fields / events?</title>
      <link>https://community.splunk.com/t5/Monitoring-Splunk/How-can-I-calculate-the-average-duration-between-changes-of-two/m-p/432817#M6503</link>
      <description>&lt;P&gt;The result looks like this and duration is not calculated. Actually the duraction can also be calculated as the difference betweeen two rows. For example:  _time(group10) - _time(group1)&lt;BR /&gt;
&lt;IMG src="https://i.ibb.co/8cF8kSt/result.png" alt="alt text" /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Dec 2018 09:22:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Monitoring-Splunk/How-can-I-calculate-the-average-duration-between-changes-of-two/m-p/432817#M6503</guid>
      <dc:creator>j_r</dc:creator>
      <dc:date>2018-12-12T09:22:45Z</dc:date>
    </item>
    <item>
      <title>Re: How can I calculate the average duration between changes of two fields / events?</title>
      <link>https://community.splunk.com/t5/Monitoring-Splunk/How-can-I-calculate-the-average-duration-between-changes-of-two/m-p/432818#M6504</link>
      <description>&lt;P&gt;Run the search step by step and see where it goes wrong.&lt;BR /&gt;
It is working for me:&lt;BR /&gt;
&lt;A href="https://ibb.co/0FsJxTG"&gt;https://ibb.co/0FsJxTG&lt;/A&gt;&lt;BR /&gt;
&lt;A href="https://ibb.co/rpGhkVC"&gt;https://ibb.co/rpGhkVC&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Dec 2018 10:16:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Monitoring-Splunk/How-can-I-calculate-the-average-duration-between-changes-of-two/m-p/432818#M6504</guid>
      <dc:creator>whrg</dc:creator>
      <dc:date>2018-12-12T10:16:00Z</dc:date>
    </item>
    <item>
      <title>Re: How can I calculate the average duration between changes of two fields / events?</title>
      <link>https://community.splunk.com/t5/Monitoring-Splunk/How-can-I-calculate-the-average-duration-between-changes-of-two/m-p/432819#M6505</link>
      <description>&lt;P&gt;i added &lt;CODE&gt;| delta _time as Diff  | eval Dauer= tostring(Diff, "duration")&lt;/CODE&gt; to calculate the difference between 2 rows. But the results are displayed in the "wrong" row. How can i shift them to previous row?&lt;/P&gt;</description>
      <pubDate>Wed, 12 Dec 2018 10:20:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Monitoring-Splunk/How-can-I-calculate-the-average-duration-between-changes-of-two/m-p/432819#M6505</guid>
      <dc:creator>j_r</dc:creator>
      <dc:date>2018-12-12T10:20:35Z</dc:date>
    </item>
    <item>
      <title>Re: How can I calculate the average duration between changes of two fields / events?</title>
      <link>https://community.splunk.com/t5/Monitoring-Splunk/How-can-I-calculate-the-average-duration-between-changes-of-two/m-p/432820#M6506</link>
      <description>&lt;P&gt;Hi, its me again &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;
how can i sum the duration and format it to a readable format?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| streamstats count as sequence
| streamstats first(sequence) as group reset_on_change=true by RobotSubState
| stats min(_time) as min_time max(_time) as max_time first(RobotSubState) as RobotSubState by group
| eval duration=max_time-min_time
|stats sum(duration) by RobotSubState
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;the result is  something like this &lt;CODE&gt;sum(duration): 5989.18&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;i already tried tostring, strptime or strftime. but it didnt work .(&lt;/P&gt;</description>
      <pubDate>Thu, 13 Dec 2018 17:34:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Monitoring-Splunk/How-can-I-calculate-the-average-duration-between-changes-of-two/m-p/432820#M6506</guid>
      <dc:creator>j_r</dc:creator>
      <dc:date>2018-12-13T17:34:41Z</dc:date>
    </item>
    <item>
      <title>Re: How can I calculate the average duration between changes of two fields / events?</title>
      <link>https://community.splunk.com/t5/Monitoring-Splunk/How-can-I-calculate-the-average-duration-between-changes-of-two/m-p/432821#M6507</link>
      <description>&lt;P&gt;Hi @j_r&lt;BR /&gt;
Try it this way:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats sum(duration) as sum_duration by RobotSubState
| eval sum_duration_in_hhmmss=tostring(sum_duration,"duration")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 14 Dec 2018 07:50:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Monitoring-Splunk/How-can-I-calculate-the-average-duration-between-changes-of-two/m-p/432821#M6507</guid>
      <dc:creator>whrg</dc:creator>
      <dc:date>2018-12-14T07:50:44Z</dc:date>
    </item>
  </channel>
</rss>

