<?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: Stats Count with Moving AVG for a given time in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Stats-Count-with-Moving-AVG-for-a-given-time/m-p/37322#M8330</link>
    <description>&lt;P&gt;What about :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;earliest=-14d@d &amp;lt;other search stuff here&amp;gt; date_hour&amp;gt;0 date_hour&amp;lt;7 | bin _time span=1d | stats count as "Todays Count" by host _time | streamstats window=7 avg("Todays Count") as "7 day Average" by host | tail 7
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;add &lt;CODE&gt;current=false&lt;/CODE&gt; to streamstats if you dont want todays values affecting todays 7day average&lt;/P&gt;

&lt;P&gt;This gives the the 7 day average derived from the previous 7 days, per day.&lt;/P&gt;

&lt;P&gt;If this is just an operations check and you dont really need a 'rolling' average, just the average over the previous 7 days for the current day :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;earliest=-7d@d date_hour&amp;gt;0 date_hour&amp;lt;7 | bin _time span=1d | stats count by host _time | eventstats avg(count) as average by host | eval average=round(average) | where _time &amp;gt;= relative_time(now(),"@d") | eval Day=strftime(_time,"%Y-%m-%d") | table Day host count average
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 19 Nov 2012 14:35:41 GMT</pubDate>
    <dc:creator>jonuwz</dc:creator>
    <dc:date>2012-11-19T14:35:41Z</dc:date>
    <item>
      <title>Stats Count with Moving AVG for a given time</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Stats-Count-with-Moving-AVG-for-a-given-time/m-p/37320#M8328</link>
      <description>&lt;P&gt;OK this one might be a challenge&lt;/P&gt;

&lt;P&gt;I 7 services that restart at midnight. I have a report that comes out at 7 AM that shows the volume of events since midnight.  easy so far "start at 7 check back -7 hours stats count by host" simple right.  well here is the hard part.  I would like to put an AVG event number next to each reported event number line this "host   Todays_count   AVG_count".  And harder the avg count should get the avg count of events for each host from 00:00 to 07:00 each day for the last 7 days.  this will make it posable from the morning report to see A. is the server reporting event (this is the primary goal) B. is the server reporting about the right number of events (Secondary goal).&lt;/P&gt;

&lt;P&gt;Any takers!!!&lt;/P&gt;

&lt;P&gt;this is what I have now&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=foo earliest=-7h@h | stats count as events by host | sort host
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks in advance for your help&lt;/P&gt;

&lt;P&gt;Mike H.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 12:49:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Stats-Count-with-Moving-AVG-for-a-given-time/m-p/37320#M8328</guid>
      <dc:creator>hartfoml</dc:creator>
      <dc:date>2020-09-28T12:49:11Z</dc:date>
    </item>
    <item>
      <title>Re: Stats Count with Moving AVG for a given time</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Stats-Count-with-Moving-AVG-for-a-given-time/m-p/37321#M8329</link>
      <description>&lt;P&gt;This isn't elegant or efficient and someone else can hopefully make this better. This is for the last two days and you'd just have to expand it for the 7 days prior avg. I didn't know of a better way to reference your time period for the past days 7 hour window. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  sourcetype=foo earliest=-7h@h | stats count as currentDayCount by host 
    | appendcols [search sourcetype=foo earliest=-31h@h latest=-24h@h  | stats count as daybefore by host]
    | appendcols [search sourcetype=foo earliest=-55h@h latest=-48h@h | stats count as 2daysbefore by host]
    | eval avgLast2Days = (daybefore + 2daysbefore)/2 
    | table host currentDayCount avgLast2Days
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 16 Nov 2012 15:04:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Stats-Count-with-Moving-AVG-for-a-given-time/m-p/37321#M8329</guid>
      <dc:creator>sdaniels</dc:creator>
      <dc:date>2012-11-16T15:04:50Z</dc:date>
    </item>
    <item>
      <title>Re: Stats Count with Moving AVG for a given time</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Stats-Count-with-Moving-AVG-for-a-given-time/m-p/37322#M8330</link>
      <description>&lt;P&gt;What about :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;earliest=-14d@d &amp;lt;other search stuff here&amp;gt; date_hour&amp;gt;0 date_hour&amp;lt;7 | bin _time span=1d | stats count as "Todays Count" by host _time | streamstats window=7 avg("Todays Count") as "7 day Average" by host | tail 7
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;add &lt;CODE&gt;current=false&lt;/CODE&gt; to streamstats if you dont want todays values affecting todays 7day average&lt;/P&gt;

&lt;P&gt;This gives the the 7 day average derived from the previous 7 days, per day.&lt;/P&gt;

&lt;P&gt;If this is just an operations check and you dont really need a 'rolling' average, just the average over the previous 7 days for the current day :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;earliest=-7d@d date_hour&amp;gt;0 date_hour&amp;lt;7 | bin _time span=1d | stats count by host _time | eventstats avg(count) as average by host | eval average=round(average) | where _time &amp;gt;= relative_time(now(),"@d") | eval Day=strftime(_time,"%Y-%m-%d") | table Day host count average
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 19 Nov 2012 14:35:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Stats-Count-with-Moving-AVG-for-a-given-time/m-p/37322#M8330</guid>
      <dc:creator>jonuwz</dc:creator>
      <dc:date>2012-11-19T14:35:41Z</dc:date>
    </item>
    <item>
      <title>Re: Stats Count with Moving AVG for a given time</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Stats-Count-with-Moving-AVG-for-a-given-time/m-p/37323#M8331</link>
      <description>&lt;P&gt;That looks a lot cleaner to me. @hartfomi - let us know how it goes.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Nov 2012 23:24:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Stats-Count-with-Moving-AVG-for-a-given-time/m-p/37323#M8331</guid>
      <dc:creator>sdaniels</dc:creator>
      <dc:date>2012-11-19T23:24:42Z</dc:date>
    </item>
    <item>
      <title>Re: Stats Count with Moving AVG for a given time</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Stats-Count-with-Moving-AVG-for-a-given-time/m-p/37324#M8332</link>
      <description>&lt;P&gt;Worked like a champ for me!  Love it!&lt;/P&gt;</description>
      <pubDate>Tue, 11 Aug 2015 20:20:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Stats-Count-with-Moving-AVG-for-a-given-time/m-p/37324#M8332</guid>
      <dc:creator>pierrejordonnel</dc:creator>
      <dc:date>2015-08-11T20:20:17Z</dc:date>
    </item>
  </channel>
</rss>

