<?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 get the time difference between consecutive events of a host and then do the average of it? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-time-difference-between-consecutive-events-of-a/m-p/614291#M213533</link>
    <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/213957"&gt;@richgalloway&lt;/a&gt;&amp;nbsp; I dont want to look at just 2 events..I want to look at all the events in that selected time range and then do the difference and average for each host&lt;/P&gt;</description>
    <pubDate>Fri, 23 Sep 2022 12:06:28 GMT</pubDate>
    <dc:creator>vrmandadi</dc:creator>
    <dc:date>2022-09-23T12:06:28Z</dc:date>
    <item>
      <title>How to get the time difference between consecutive events of a host and then do the average of it?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-time-difference-between-consecutive-events-of-a/m-p/614222#M213529</link>
      <description>&lt;P&gt;I am using the below search to first get the difference in time everytime I see an event which has boot timestamp in it and using it first get the difference and then get the average of it by host.I am able to get the result correctly if I do one host per search like host=abc but if I use a wildcharacter for all hosts then I see the results are different (host=*) .I am assuming someother hosts having the events at same time is causing the issue .How to get the correct results for all hosts at a time .&lt;BR /&gt;&lt;BR /&gt;I get the time value as&amp;nbsp;11:50:58.59 if I use only host=abc but when I want to list all hosts (host=*.)for host abc I see value&amp;nbsp;&lt;SPAN&gt;00:18:18.67&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;index=abc "Boot timestamp" host=abc&lt;BR /&gt;| eval _time=strptime(Boot_Time,"%Y-%m-%d %H:%M:%S")&lt;BR /&gt;| reverse&lt;BR /&gt;| delta _time as difference_secs&lt;BR /&gt;| table _time difference_secs host&lt;BR /&gt;| stats avg(difference_secs) as average by host | eval average=round(average,2)&lt;BR /&gt;| eval time=tostring(average, "duration")&lt;BR /&gt;&lt;BR /&gt;is it possible to get all hosts average or it can be only individual .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in Advance&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Sep 2022 00:37:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-time-difference-between-consecutive-events-of-a/m-p/614222#M213529</guid>
      <dc:creator>vrmandadi</dc:creator>
      <dc:date>2022-09-23T00:37:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the time difference between consecutive events of a host and then do the average of it?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-time-difference-between-consecutive-events-of-a/m-p/614256#M213530</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;1st it's not a best practice to replace _time with some other values. Of course you can and should do it time but time but only if there is no other way.&lt;/P&gt;&lt;P&gt;Your issue with multiple host is command delta. It just calculates values based on _time/Boot_Time without connection to an individual host. For that reason it works with one host but not with many.&lt;/P&gt;&lt;P&gt;You could try something like this with several hosts&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=abc "Boot timestamp" host=*
| eval btEpoch=strptime(Boot_Time,"%Y-%m-%d %H:%M:%S")
| stats range(btEpoch) as difference_secs by host
| stats avg(difference_secs) as average by host
| eval average=round(average,2)
| eval time=tostring(average, "duration")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If there are many "Boot timestamp" events then maybe streamstats with some window/reset parameter could work better?&lt;/P&gt;&lt;P&gt;r. Ismo&lt;/P&gt;</description>
      <pubDate>Fri, 23 Sep 2022 07:05:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-time-difference-between-consecutive-events-of-a/m-p/614256#M213530</guid>
      <dc:creator>isoutamo</dc:creator>
      <dc:date>2022-09-23T07:05:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the time difference between consecutive events of a host and then do the average of it?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-time-difference-between-consecutive-events-of-a/m-p/614281#M213531</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/214410"&gt;@isoutamo&lt;/a&gt;&amp;nbsp; &amp;nbsp;I did try your search but it is working if there are only two&amp;nbsp; events of Boot time...if there are more than two then its showing wrong value .I am not sure how streamstats work...can you let me know how it works.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Fri, 23 Sep 2022 11:37:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-time-difference-between-consecutive-events-of-a/m-p/614281#M213531</guid>
      <dc:creator>vrmandadi</dc:creator>
      <dc:date>2022-09-23T11:37:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the time difference between consecutive events of a host and then do the average of it?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-time-difference-between-consecutive-events-of-a/m-p/614286#M213532</link>
      <description>&lt;P&gt;Use the &lt;FONT face="courier new,courier"&gt;streamstats&lt;/FONT&gt; command to look at only two events.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=abc "Boot timestamp" host=*
| eval btEpoch=strptime(Boot_Time,"%Y-%m-%d %H:%M:%S")
| streamstats window=2 range(btEpoch) as difference_secs by host
| stats avg(difference_secs) as average by host
| eval average=round(average,2)
| eval time=tostring(average, "duration")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Sep 2022 11:53:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-time-difference-between-consecutive-events-of-a/m-p/614286#M213532</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2022-09-23T11:53:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the time difference between consecutive events of a host and then do the average of it?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-time-difference-between-consecutive-events-of-a/m-p/614291#M213533</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/213957"&gt;@richgalloway&lt;/a&gt;&amp;nbsp; I dont want to look at just 2 events..I want to look at all the events in that selected time range and then do the difference and average for each host&lt;/P&gt;</description>
      <pubDate>Fri, 23 Sep 2022 12:06:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-time-difference-between-consecutive-events-of-a/m-p/614291#M213533</guid>
      <dc:creator>vrmandadi</dc:creator>
      <dc:date>2022-09-23T12:06:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the time difference between consecutive events of a host and then do the average of it?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-time-difference-between-consecutive-events-of-a/m-p/614376#M213534</link>
      <description>&lt;P&gt;On&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/213957"&gt;@richgalloway&lt;/a&gt;&amp;nbsp;'s example it use two sequential events by host and calculates difference between those times as you have asked. As you have used filter "Boot timestamp" we have assumed that there is not any other events than those.&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I think that this should be work as you have asked or otherwise there are something what we didn't know about your events.&lt;/P&gt;</description>
      <pubDate>Fri, 23 Sep 2022 19:22:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-time-difference-between-consecutive-events-of-a/m-p/614376#M213534</guid>
      <dc:creator>isoutamo</dc:creator>
      <dc:date>2022-09-23T19:22:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the time difference between consecutive events of a host and then do the average of it?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-time-difference-between-consecutive-events-of-a/m-p/614408#M213535</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/120532"&gt;@vrmandadi&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note that when using streamstats with window=X you MUST use global=f when splitting by a field, otherwise it will not keep separate range values for each host.&lt;/P&gt;&lt;P&gt;If you have 3 events, what calculations do you expect to occur between the 3 boot time values?&lt;/P&gt;&lt;P&gt;Using the example given with window=2 will calculate the difference between any pair of values, but note my comment above about using &lt;STRONG&gt;global=f&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 24 Sep 2022 03:55:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-time-difference-between-consecutive-events-of-a/m-p/614408#M213535</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2022-09-24T03:55:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the time difference between consecutive events of a host and then do the average of it?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-time-difference-between-consecutive-events-of-a/m-p/614429#M213536</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/6367"&gt;@bowesmana&lt;/a&gt;&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/214410"&gt;@isoutamo&lt;/a&gt;&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/213957"&gt;@richgalloway&lt;/a&gt;&amp;nbsp;@@I am sorry if I have not explained it correctly...But I am looking to find difference between all the events with boot time for each host..it might be two or three or ten depending on time range selected..So for instance if a host A has 10 events and host B has 6 events and host C has 5 events I want to&amp;nbsp; find firstly the time difference between each event for a particular host and then do the average of it ..I get correct value if I do this for single host but when I do same by selecting all hosts then it doesn't shows wrong value&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 24 Sep 2022 16:00:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-time-difference-between-consecutive-events-of-a/m-p/614429#M213536</guid>
      <dc:creator>vrmandadi</dc:creator>
      <dc:date>2022-09-24T16:00:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the time difference between consecutive events of a host and then do the average of it?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-time-difference-between-consecutive-events-of-a/m-p/614436#M213545</link>
      <description>&lt;P&gt;Using &lt;FONT face="courier new,courier"&gt;streamstats window=2&lt;/FONT&gt; as described in the first reply will give you the difference between adjacent events.&amp;nbsp; You than can use &lt;FONT face="courier new,courier"&gt;stats avg()&lt;/FONT&gt; to get the average of those differences.&lt;/P&gt;</description>
      <pubDate>Sun, 25 Sep 2022 00:24:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-time-difference-between-consecutive-events-of-a/m-p/614436#M213545</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2022-09-25T00:24:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the time difference between consecutive events of a host and then do the average of it?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-time-difference-between-consecutive-events-of-a/m-p/614468#M213553</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/120532"&gt;@vrmandadi&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is an example search you can run that will create a random set of events for 5 hosts and calculate the difference between each pair of events per host and then calculate the average for each host.&lt;/P&gt;&lt;P&gt;You can run this in the search window and see how it works.&amp;nbsp;&lt;/P&gt;&lt;P&gt;If this does not reflect what you are trying to do, please clarify and provide some data examples.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
``` Create 5 hosts ```
| eval host=split("A,B,C,D,E",",")
| mvexpand host
``` For each host create a random number of events up to 8 ```
| eval count=random() % 6 + 2
| eval events=mvrange(0, count, 1)
| mvexpand events
``` Now calculate a time for each host/event going back in time ```
| eval _time=now() - (random() % 43200) - (events * 86400)
| sort - _time
``` Calculate difference between each PAIR of events ```
| streamstats window=2 global=f range(_time) as range by host
``` Format the number of seconds as Days, Hours. Mins, Secs ```
| eval diff=tostring(range, "duration")
``` Now calculate the average for each host excluding the first event as it has 0 value ```
| stats list(_time) as BootTimes list(range) as range list(diff) as diff avg(eval(if(range&amp;gt;0, range, null()))) as Avg by host
``` Some formatting for ease of reading ```
| eval BootTimes=strftime(BootTimes, "%F %T")
| eval Avg=tostring(round(Avg), "duration")&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 26 Sep 2022 01:04:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-time-difference-between-consecutive-events-of-a/m-p/614468#M213553</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2022-09-26T01:04:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the time difference between consecutive events of a host and then do the average of it?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-time-difference-between-consecutive-events-of-a/m-p/614566#M213585</link>
      <description>&lt;P&gt;Thank You..this worked&lt;/P&gt;</description>
      <pubDate>Mon, 26 Sep 2022 13:44:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-time-difference-between-consecutive-events-of-a/m-p/614566#M213585</guid>
      <dc:creator>vrmandadi</dc:creator>
      <dc:date>2022-09-26T13:44:35Z</dc:date>
    </item>
  </channel>
</rss>

