<?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 you calculate the mean of a timewrap series? in Reporting</title>
    <link>https://community.splunk.com/t5/Reporting/How-do-you-calculate-the-mean-of-a-timewrap-series/m-p/396487#M10022</link>
    <description>&lt;P&gt;Try this!&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|timechart span=5m count(eval(like(Variable10,"%|U%"))) as U_Count
↓
|timechart span=5m count(eval(if(like(Variable10,"%|U%"),1,0))) as U_Count
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 20 Nov 2018 02:26:53 GMT</pubDate>
    <dc:creator>HiroshiSatoh</dc:creator>
    <dc:date>2018-11-20T02:26:53Z</dc:date>
    <item>
      <title>How do you calculate the mean of a timewrap series?</title>
      <link>https://community.splunk.com/t5/Reporting/How-do-you-calculate-the-mean-of-a-timewrap-series/m-p/396486#M10021</link>
      <description>&lt;P&gt;I am trying to write a query that will count the number of errors for the last 5 minutes and then I want to compare if that error total is greater than the average for the previous 15 minutes. Then I want to trigger an alert if series s0 is greater than the mean (for alerting purposes). &lt;/P&gt;

&lt;P&gt;I found part of the solution from Splunk Answers  (&lt;A href="https://answers.splunk.com/answers/151921/how-to-set-up-alert-when-error-count-of-latest-week-is-greater-than-average-of-all-weeks-in-past-30-days.html"&gt;https://answers.splunk.com/answers/151921/how-to-set-up-alert-when-error-count-of-latest-week-is-greater-than-average-of-all-weeks-in-past-30-days.html&lt;/A&gt;), but my eval expression to calculate the mean field does not seem to work; the field is just empty. What am I not doing right here?&lt;/P&gt;

&lt;P&gt;Query is below:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=cisco_uc sourcetype=RCD| where like (Variable10,"Tx|%")
| bucket _time span=5m
| stats latest(Variable10) as Variable10 by _time Variable2
|timechart span=5m count(eval(like(Variable10,"%|U%"))) as U_Count
|timewrap 5min series=short
|eval mean=(U_Count_s1 + U_Count_s2 + U_Count_s3)/3
|where U_Count_s0 &amp;gt; mean
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 19 Nov 2018 20:04:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/How-do-you-calculate-the-mean-of-a-timewrap-series/m-p/396486#M10021</guid>
      <dc:creator>mmdacutanan</dc:creator>
      <dc:date>2018-11-19T20:04:39Z</dc:date>
    </item>
    <item>
      <title>Re: How do you calculate the mean of a timewrap series?</title>
      <link>https://community.splunk.com/t5/Reporting/How-do-you-calculate-the-mean-of-a-timewrap-series/m-p/396487#M10022</link>
      <description>&lt;P&gt;Try this!&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|timechart span=5m count(eval(like(Variable10,"%|U%"))) as U_Count
↓
|timechart span=5m count(eval(if(like(Variable10,"%|U%"),1,0))) as U_Count
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 20 Nov 2018 02:26:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/How-do-you-calculate-the-mean-of-a-timewrap-series/m-p/396487#M10022</guid>
      <dc:creator>HiroshiSatoh</dc:creator>
      <dc:date>2018-11-20T02:26:53Z</dc:date>
    </item>
    <item>
      <title>Re: How do you calculate the mean of a timewrap series?</title>
      <link>https://community.splunk.com/t5/Reporting/How-do-you-calculate-the-mean-of-a-timewrap-series/m-p/396488#M10023</link>
      <description>&lt;P&gt;Try like this. I tested against an ITSI summary index, so replace line 1 with your query and replace those &lt;CODE&gt;_raw&lt;/CODE&gt; values with your field names. Also, you may not want to count the latest 5 minute bucket since it's still accepting new data and the counts may be artificially low. In the example below, I'm comparing the latest full 5 minute bucket count with the average of 3 - 15 minute buckets preceding it. It runs an hour timerange in under 1 second!&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=itsi_summary 
| bin _time span=5m
| stats count(_raw) AS _raw by _time
| streamstats sum(_raw) AS fifteen_min_window time_window=15m 
| streamstats sum(_raw) AS five_min_window time_window=5m
| streamstats count AS primary_key
| eval five_min_value=if(primary_key=2,'five_min_window',"")
| eval fifteen_min_value=if(primary_key=4,'fifteen_min_window',"")
| eval average=fifteen_min_value/3
| stats max(five_min_value) AS five_min_count max(average) AS avg_count_fifteen_min
| eval compare=if('average'&amp;gt;'five_min_value',"Avg is greater than latest bucket","Latest bucket is greater Than Average")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 20 Nov 2018 03:03:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/How-do-you-calculate-the-mean-of-a-timewrap-series/m-p/396488#M10023</guid>
      <dc:creator>skoelpin</dc:creator>
      <dc:date>2018-11-20T03:03:32Z</dc:date>
    </item>
    <item>
      <title>Re: How do you calculate the mean of a timewrap series?</title>
      <link>https://community.splunk.com/t5/Reporting/How-do-you-calculate-the-mean-of-a-timewrap-series/m-p/396489#M10024</link>
      <description>&lt;P&gt;@mmdacutanan did this solve your problem? If so, can you accept an answer to close out the question?&lt;/P&gt;</description>
      <pubDate>Mon, 26 Nov 2018 14:36:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/How-do-you-calculate-the-mean-of-a-timewrap-series/m-p/396489#M10024</guid>
      <dc:creator>skoelpin</dc:creator>
      <dc:date>2018-11-26T14:36:45Z</dc:date>
    </item>
    <item>
      <title>Re: How do you calculate the mean of a timewrap series?</title>
      <link>https://community.splunk.com/t5/Reporting/How-do-you-calculate-the-mean-of-a-timewrap-series/m-p/396490#M10025</link>
      <description>&lt;P&gt;Hi skoelpin! Thank you so much! I think this gets me close enough to what I need. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; Btw, Are you just doing the last 20 minutes?&lt;/P&gt;</description>
      <pubDate>Sat, 01 Dec 2018 01:49:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/How-do-you-calculate-the-mean-of-a-timewrap-series/m-p/396490#M10025</guid>
      <dc:creator>mmdacutanan</dc:creator>
      <dc:date>2018-12-01T01:49:12Z</dc:date>
    </item>
    <item>
      <title>Re: How do you calculate the mean of a timewrap series?</title>
      <link>https://community.splunk.com/t5/Reporting/How-do-you-calculate-the-mean-of-a-timewrap-series/m-p/396491#M10026</link>
      <description>&lt;P&gt;Hello again skoelpin! Thank you so much again for the query you provided. That gave me idea on how to come up with my own query. I don't use streamstats often but I will now! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; Here is my final query. I added some stdev calculations. I don't want to get too many false alerts so I thought of calculating upper and lower limits of the standard deviation:&lt;/P&gt;

&lt;P&gt;index=uc sourcetype=rcd| where like (Variable10,"Tx|%|NS|%")&lt;BR /&gt;
| bucket _time span=5m &lt;BR /&gt;
| stats latest(Variable10) as Variable10 by _time Variable2 &lt;BR /&gt;
| timechart span=5m count(Variable10) as NS_Count&lt;BR /&gt;
| streamstats count as pri_key&lt;BR /&gt;
| streamstats avg(NS_Count) as avg, stdev(NS_Count) as stdev window=3&lt;BR /&gt;
| eval avg=round(avg,2)&lt;BR /&gt;
| eval stdev=round(stdev,2)&lt;BR /&gt;
| eval lowerBound=(avg-stdev*2)&lt;BR /&gt;
| eval upperBound=(avg+stdev*2)&lt;BR /&gt;
| eval 5m_value=if(pri_key=4,'NS_Count',"")&lt;BR /&gt;
| eval 15m_prev_upperBound=if(pri_key=3,'upperBound',"")&lt;BR /&gt;
| eval 15m_prev_lowerBound=if(pri_key=3,'lowerBound',"")&lt;BR /&gt;
| eval 15m_prev_avg=if(pri_key=3,'avg',"")&lt;BR /&gt;
| eval 15m_prev_stdev=if(pri_key=3,'stdev',"")&lt;BR /&gt;
| stats values(5m_value) as 5m_value values(15m_prev_upperBound) as 15m_prev_upperBound values(15m_prev_lowerBound) as 15m_prev_lowerBound values(15m_prev_avg) as 15m_prev_avg values(15m_prev_stdev) as 15m_prev_stdev&lt;BR /&gt;
| eval boolean=if('5m_value'&amp;gt;'15m_prev_upperBound',"1","0")&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 22:14:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/How-do-you-calculate-the-mean-of-a-timewrap-series/m-p/396491#M10026</guid>
      <dc:creator>mmdacutanan</dc:creator>
      <dc:date>2020-09-29T22:14:13Z</dc:date>
    </item>
    <item>
      <title>Re: How do you calculate the mean of a timewrap series?</title>
      <link>https://community.splunk.com/t5/Reporting/How-do-you-calculate-the-mean-of-a-timewrap-series/m-p/396492#M10027</link>
      <description>&lt;P&gt;Thanks HiroshiSatoh! skoelpin's query actually brought me closer to the solution. I posted my final query above.&lt;/P&gt;</description>
      <pubDate>Sat, 01 Dec 2018 03:30:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/How-do-you-calculate-the-mean-of-a-timewrap-series/m-p/396492#M10027</guid>
      <dc:creator>mmdacutanan</dc:creator>
      <dc:date>2018-12-01T03:30:33Z</dc:date>
    </item>
  </channel>
</rss>

