<?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 do I find the average time (by day) of an event? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-find-the-average-time-by-day-of-an-event/m-p/474151#M192453</link>
    <description>&lt;P&gt;@woodcock It's not my data, or my question, just trying to learn from Master Yoda. I didn't follow the data in the question either, so I was using this to derive an answer...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval data="2-Jan-20 16:00:00,10;2-Jan-20 16:30:00,14;1-Jan-20 15:35:00,10;1-Jan-20 17:34:00,14;3-Jan-20 16:50:00,10;3-Jan-20 17:34:00,14" 
| makemv data delim=";" 
| mvexpand data 
| rex field=data "(\s|\n?)(?&amp;lt;data&amp;gt;.*)" 
| makemv data delim="," 
| eval _time=strptime(mvindex(data,0),"%d-%b-%y %H:%M:%S"),
    ErrorCount=mvindex(data,1) 
| fields _time ErrorCount 
| eval "Average Event Time"=strftime(avg_event_time, "%H:%M") 
| stats earliest(_time) as FirstAppearance by _time 
| bucket _time span=1d 
| stats avg(FirstAppearance) AS avg_FirstAppearance
| eval "Average First Appearance"=strftime(avg_FirstAppearance, "%H:%M") | table "Average First Appearance"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 02 Jan 2020 21:03:09 GMT</pubDate>
    <dc:creator>mydog8it</dc:creator>
    <dc:date>2020-01-02T21:03:09Z</dc:date>
    <item>
      <title>How do I find the average time (by day) of an event?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-find-the-average-time-by-day-of-an-event/m-p/474145#M192447</link>
      <description>&lt;P&gt;I have a search that returns the time of the first instance of a specific event (field "firstaction") by date (field "ldate"). &lt;/P&gt;

&lt;P&gt;search yadda yadda yadda | stats earliest(time) as firstaction by ldate &lt;/P&gt;

&lt;P&gt;results:&lt;/P&gt;

&lt;P&gt;ldate                   firstaction&lt;BR /&gt;
2019-12-30       09:00:00.000&lt;BR /&gt;
2019-12-31       07:00:00.000&lt;/P&gt;

&lt;P&gt;What I want is the average time (value) of all the results.... or in this case 08:00:00.000&lt;/P&gt;

&lt;P&gt;"|stats avg(firstaction) " doesn't return anything.&lt;/P&gt;

&lt;P&gt;Also, only days that have a value should be averaged.&lt;/P&gt;

&lt;P&gt;I thought about breaking out the value of the hours, minutes and seconds and converting them to a sum of seconds... then averaging the sum of seconds by day and then converting them back to a time value... but that seems overly complex and I can't be the only person that needs to know the average time of the first occurrence of something by day and alert if it falls outside a standard deviation.&lt;/P&gt;

&lt;P&gt;Any thoughts (besides purchasing behavioral analytics)?&lt;/P&gt;</description>
      <pubDate>Thu, 02 Jan 2020 14:48:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-find-the-average-time-by-day-of-an-event/m-p/474145#M192447</guid>
      <dc:creator>drmorgan78</dc:creator>
      <dc:date>2020-01-02T14:48:37Z</dc:date>
    </item>
    <item>
      <title>Re: How do I find the average time (by day) of an event?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-find-the-average-time-by-day-of-an-event/m-p/474146#M192448</link>
      <description>&lt;P&gt;If you add this to the end of a search that returns the interesting raw events, it will give you the average time the first event of each day is seen in the data:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval "Average Event Time"=strftime(avg_event_time, "%H:%M") 
| stats earliest(_time) as FirstAppearance by _time 
| bucket _time span=1d 
| stats avg(FirstAppearance) AS avg_FirstAppearance
| eval "Average First Appearance"=strftime(avg_FirstAppearance, "%H:%M") | table "Average First Appearance"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 Jan 2020 19:23:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-find-the-average-time-by-day-of-an-event/m-p/474146#M192448</guid>
      <dc:creator>mydog8it</dc:creator>
      <dc:date>2020-01-02T19:23:03Z</dc:date>
    </item>
    <item>
      <title>Re: How do I find the average time (by day) of an event?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-find-the-average-time-by-day-of-an-event/m-p/474147#M192449</link>
      <description>&lt;P&gt;Give this a try&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;search yadda yadda yadda | stats earliest(time) as firstaction by ldate
| convert dur2sec(firstaction)  
|stats avg(firstaction) as firstaction
| eval firstaction=tostring(firstaction,"duration")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 Jan 2020 19:51:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-find-the-average-time-by-day-of-an-event/m-p/474147#M192449</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2020-01-02T19:51:35Z</dc:date>
    </item>
    <item>
      <title>Re: How do I find the average time (by day) of an event?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-find-the-average-time-by-day-of-an-event/m-p/474148#M192450</link>
      <description>&lt;P&gt;Like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;search yadda yadda yadda
| eval time=strftime(strptime(time, "%H:%M:%S.%3M"), "%H%M%S%3M")
| stats min(time) AS firstaction BY ldate
| stats avg(firstaction)
| fieldformat firstaction = replace(firstaction, "^(\d\d)(\d\d)(\d\d)", "\1:\2:\3.")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 Jan 2020 19:52:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-find-the-average-time-by-day-of-an-event/m-p/474148#M192450</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2020-01-02T19:52:47Z</dc:date>
    </item>
    <item>
      <title>Re: How do I find the average time (by day) of an event?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-find-the-average-time-by-day-of-an-event/m-p/474149#M192451</link>
      <description>&lt;P&gt;@woodcock  I'm trying to follow your SPL, but getting stuck. Should line 2 read:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval time=strftime(strptime(_time, "%H:%M:%S.%3M"), "%H%M%S%3M")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 Jan 2020 20:41:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-find-the-average-time-by-day-of-an-event/m-p/474149#M192451</guid>
      <dc:creator>mydog8it</dc:creator>
      <dc:date>2020-01-02T20:41:50Z</dc:date>
    </item>
    <item>
      <title>Re: How do I find the average time (by day) of an event?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-find-the-average-time-by-day-of-an-event/m-p/474150#M192452</link>
      <description>&lt;P&gt;I hate your data; try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;search yadda yadda yadda
| stats earliest(time) as firstaction by ldate
| rex field=time mode=sed "s/[:\.]//g"
| stats avg(firstaction)
| fieldformat firstaction = replace(firstaction, "^(\d\d)(\d\d)(\d\d)", "\1:\2:\3.")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 Jan 2020 20:50:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-find-the-average-time-by-day-of-an-event/m-p/474150#M192452</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2020-01-02T20:50:00Z</dc:date>
    </item>
    <item>
      <title>Re: How do I find the average time (by day) of an event?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-find-the-average-time-by-day-of-an-event/m-p/474151#M192453</link>
      <description>&lt;P&gt;@woodcock It's not my data, or my question, just trying to learn from Master Yoda. I didn't follow the data in the question either, so I was using this to derive an answer...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval data="2-Jan-20 16:00:00,10;2-Jan-20 16:30:00,14;1-Jan-20 15:35:00,10;1-Jan-20 17:34:00,14;3-Jan-20 16:50:00,10;3-Jan-20 17:34:00,14" 
| makemv data delim=";" 
| mvexpand data 
| rex field=data "(\s|\n?)(?&amp;lt;data&amp;gt;.*)" 
| makemv data delim="," 
| eval _time=strptime(mvindex(data,0),"%d-%b-%y %H:%M:%S"),
    ErrorCount=mvindex(data,1) 
| fields _time ErrorCount 
| eval "Average Event Time"=strftime(avg_event_time, "%H:%M") 
| stats earliest(_time) as FirstAppearance by _time 
| bucket _time span=1d 
| stats avg(FirstAppearance) AS avg_FirstAppearance
| eval "Average First Appearance"=strftime(avg_FirstAppearance, "%H:%M") | table "Average First Appearance"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 Jan 2020 21:03:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-find-the-average-time-by-day-of-an-event/m-p/474151#M192453</guid>
      <dc:creator>mydog8it</dc:creator>
      <dc:date>2020-01-02T21:03:09Z</dc:date>
    </item>
    <item>
      <title>Re: How do I find the average time (by day) of an event?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-find-the-average-time-by-day-of-an-event/m-p/474152#M192454</link>
      <description>&lt;P&gt;So do you have a working solution or are you still having some trouble?&lt;/P&gt;</description>
      <pubDate>Thu, 02 Jan 2020 21:26:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-find-the-average-time-by-day-of-an-event/m-p/474152#M192454</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2020-01-02T21:26:51Z</dc:date>
    </item>
    <item>
      <title>Re: How do I find the average time (by day) of an event?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-find-the-average-time-by-day-of-an-event/m-p/474153#M192455</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval _raw="ldate firstaction
2019-12-29 06:00:00.000
2019-12-30 09:00:00.000
2019-12-31 07:00:00.000"
| multikv forceheader=1
| table ldate firstaction
| rename COMMENT as "this is sample you provided"
| rename COMMENT as "from here, the logic"
| eval temp=substr(firstaction,1,8)
| convert dur2sec(temp)
| stats mean(temp) as firstaction_avg
| eval firstaction_avg = tostring(firstaction_avg,"duration")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Since the search result is a character string once, it needs to be changed to time .&lt;BR /&gt;
This is the query to convert from your search results.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Jan 2020 21:39:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-find-the-average-time-by-day-of-an-event/m-p/474153#M192455</guid>
      <dc:creator>to4kawa</dc:creator>
      <dc:date>2020-01-02T21:39:48Z</dc:date>
    </item>
  </channel>
</rss>

