<?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 avg of number of events in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/avg-of-number-of-events/m-p/64029#M15825</link>
    <description>&lt;P&gt;Hi all, i need to count the event of today and compare with the average of the last month daily count by dest.
I'm using a query like this that separate the ip's and now i have to show the average of count by the same dest&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;eventtype="searchIPS1" DestinationIP!="N/A" Severity="Medium" |eval dest=case(DestinationIP=="1.1.1.1", "sshDMZ", DestinationIP=="1.1.1.2", "sshDMZ",  (DestinationIP!="1.1.1.1" AND DestinationIP!="1.1.1.2"), "Others") | stats last(count) as today_count avg(count) as avg_count&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;for example:&lt;/P&gt;

&lt;P&gt;dest     | today_count | avg_count&lt;BR /&gt;
sshDMZ   | 8 | 5,67&lt;BR /&gt;
others | 7 | 9,89&lt;/P&gt;

&lt;P&gt;thanks to all who can help me&lt;/P&gt;</description>
    <pubDate>Tue, 05 Oct 2010 22:46:52 GMT</pubDate>
    <dc:creator>pinzer</dc:creator>
    <dc:date>2010-10-05T22:46:52Z</dc:date>
    <item>
      <title>avg of number of events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/avg-of-number-of-events/m-p/64029#M15825</link>
      <description>&lt;P&gt;Hi all, i need to count the event of today and compare with the average of the last month daily count by dest.
I'm using a query like this that separate the ip's and now i have to show the average of count by the same dest&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;eventtype="searchIPS1" DestinationIP!="N/A" Severity="Medium" |eval dest=case(DestinationIP=="1.1.1.1", "sshDMZ", DestinationIP=="1.1.1.2", "sshDMZ",  (DestinationIP!="1.1.1.1" AND DestinationIP!="1.1.1.2"), "Others") | stats last(count) as today_count avg(count) as avg_count&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;for example:&lt;/P&gt;

&lt;P&gt;dest     | today_count | avg_count&lt;BR /&gt;
sshDMZ   | 8 | 5,67&lt;BR /&gt;
others | 7 | 9,89&lt;/P&gt;

&lt;P&gt;thanks to all who can help me&lt;/P&gt;</description>
      <pubDate>Tue, 05 Oct 2010 22:46:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/avg-of-number-of-events/m-p/64029#M15825</guid>
      <dc:creator>pinzer</dc:creator>
      <dc:date>2010-10-05T22:46:52Z</dc:date>
    </item>
    <item>
      <title>Re: avg of number of events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/avg-of-number-of-events/m-p/64030#M15826</link>
      <description>&lt;P&gt;I spent quite a while finding how to do this myself. I think the following would do what you need:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;eventtype="searchIPS1" DestinationIP!="N/A" Severity="Medium" earliest=-30d@d latest=@d
  | eval dest=case(DestinationIP=="1.1.1.1", "sshDMZ", DestinationIP=="1.1.1.2", "sshDMZ", 
        (DestinationIP!="1.1.1.1" AND DestinationIP!="1.1.1.2"), "Others")
  | bin _time span=1d
  | stats max(count) as PerDay by _time dest
  | stats avg(PerDay) as MonthlyAverage by dest
  | fields MonthlyAverage dest
  | join type=outer dest 
     [search eventtype="searchIPS1" DestinationIP!="N/A" Severity="Medium" earliest=@d latest=now 
     |eval dest=case(DestinationIP=="1.1.1.1", "sshDMZ", DestinationIP=="1.1.1.2", "sshDMZ", 
          (DestinationIP!="1.1.1.1" AND DestinationIP!="1.1.1.2"), "Others") 
     | bin _time span=1d 
     | stats last(count) as Today by dest 
     | fields Today dest
     ]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Or generically: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;#YourSearchHere# earliest=-30d@d latest=@d 
| bin _time span=1d 
| stats #PerDayStats# as PerDay by _time #SplittingField#  
| stats avg(PerDay) as MonthlyAverage by #SplittingField#  
| fields MonthlyAverage #SplittingField#  
| join type=outer #SplittingField# 
    [
     search #YourSearchHere# earliest=@d latest=now 
     | bin _time span=1d 
     | stats #Today'sStats# as Today by #SplittingField# 
     | fields Today #SplittingField#
    ]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Essentially, the above does your search for the Monthly Average first, leaves only the two relevant fields (dest and MonthlyAverage), then joins it to a second search for Today's values, based on the dest.&lt;/P&gt;

&lt;P&gt;There are a couple of other ways to do it that have come up in Splunk Answers, so one of them may be better, but give the above a shot. &lt;/P&gt;</description>
      <pubDate>Wed, 06 Oct 2010 22:04:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/avg-of-number-of-events/m-p/64030#M15826</guid>
      <dc:creator>David</dc:creator>
      <dc:date>2010-10-06T22:04:14Z</dc:date>
    </item>
  </channel>
</rss>

