<?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: Average and Diff per host in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Average-and-Diff-per-host/m-p/417329#M120085</link>
    <description>&lt;P&gt;Brilliant thanks.&lt;/P&gt;</description>
    <pubDate>Thu, 31 May 2018 14:25:44 GMT</pubDate>
    <dc:creator>GadgetGeek</dc:creator>
    <dc:date>2018-05-31T14:25:44Z</dc:date>
    <item>
      <title>Average and Diff per host</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Average-and-Diff-per-host/m-p/417325#M120081</link>
      <description>&lt;P&gt;Given I have multiple hosts, I'd like the host total within a bucketed time span, average of the totals across all hosts, and the percentage  difference per host compared to the average. E.g.&lt;/P&gt;

&lt;P&gt;For:&lt;BR /&gt;
    index=main "processed" | bucket _time span=5m | rex "processed\s(?&lt;NUMPROCESSED&gt;[\d]+)\smessages" | eval processed=tonumber(NumProcessed) | stats sum(processed) by _time host&lt;/NUMPROCESSED&gt;&lt;/P&gt;

&lt;P&gt;Giving:&lt;BR /&gt;
_time | host1 | host2 | host3&lt;BR /&gt;
2018-05-24 08:00:00 | 99 | 101 | 100&lt;BR /&gt;
2018-05-24 08:05:00 | 100| 99| 101&lt;/P&gt;

&lt;P&gt;I'd like to see:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;_time               | host1 | host2 | host3 | Average | host1diff% | host2diff% | host3diff%
2018-05-24 08:00:00 | 99    | 101   | 100   | 100     | -x%        | +y%        | 0.0%
2018-05-24 08:05:00 | 100   | 99    | 101   | 100     | 0.0%       | -x%        | +y%
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;(whatever x and y would be...and the number of host diff columns will depend on the number of hosts returned in the search)&lt;/P&gt;</description>
      <pubDate>Thu, 24 May 2018 09:19:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Average-and-Diff-per-host/m-p/417325#M120081</guid>
      <dc:creator>GadgetGeek</dc:creator>
      <dc:date>2018-05-24T09:19:29Z</dc:date>
    </item>
    <item>
      <title>Re: Average and Diff per host</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Average-and-Diff-per-host/m-p/417326#M120082</link>
      <description>&lt;P&gt;@GadgetGeek, as per the details and sample data, please try the following run anywhere search. The command from &lt;CODE&gt;| makeresults&lt;/CODE&gt; till &lt;CODE&gt;| fields - data&lt;/CODE&gt; generate dummy data as per question. It uses &lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Foreach"&gt;foreach&lt;/A&gt; command to iterate through host columns to get count of hosts and calculate their difference %. The &lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Addtotals"&gt;addtotals&lt;/A&gt; command is used to get the Total of Hosts for calculating average. Remaining part of the search can be plugged in to your existing search.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval data="2018-05-24 08:00:00|99|101|100;2018-05-24 08:05:00|100|99|101" 
| makemv data delim=";" 
| mvexpand data 
| makemv data delim="|" 
| eval _time=strptime(mvindex(data,0),"%Y-%m-%d %H:%M:%S"), host1=mvindex(data,1), host2=mvindex(data,2), host3=mvindex(data,3) 
| fields - data 
| rename "*" as "count*"
| rename "count_*" as "_*"
| addtotals row=t col=f labelfield=Total
| eval HostCount=0 
| foreach count* 
    [ eval HostCount=HostCount+1]
| eval Average=round(Total/HostCount,0) 
| foreach count* 
    [ eval "diff%&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;"=round(((Average-'&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;')/Average)*100,0)]
| table _time "count*" "diff*"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Please try out and confirm!&lt;/P&gt;</description>
      <pubDate>Sat, 26 May 2018 13:55:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Average-and-Diff-per-host/m-p/417326#M120082</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2018-05-26T13:55:51Z</dc:date>
    </item>
    <item>
      <title>Re: Average and Diff per host</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Average-and-Diff-per-host/m-p/417327#M120083</link>
      <description>&lt;P&gt;My original statement wasn't quite right. The output from the stated query gives:&lt;/P&gt;

&lt;P&gt;_time  | host | sum(processed)&lt;BR /&gt;
2018-05-24 08:00:00 | host1 | 99&lt;BR /&gt;
2018-05-24 08:00:00 | host2 | 100&lt;/P&gt;

&lt;P&gt;I should have put the following instead of the 'stats' command:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| chart sum(processed) over _time by host
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The desired output IS as stated:&lt;BR /&gt;
&lt;CODE&gt;_time               | host1 | host2 | host3 | Average | host1diff% | host2diff% | host3diff%&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;From your response, taking everything from (and including)    "| fields - data" and adding 'Average' to the results seems to work.&lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;What does the '| fields - data' do, and should I include it?&lt;/LI&gt;
&lt;LI&gt;If one of the hosts has no events in the time bucket, zero is not assumed - giving blank entries and no diff %, how can I get this to work?&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Tue, 29 May 2018 05:12:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Average-and-Diff-per-host/m-p/417327#M120083</guid>
      <dc:creator>GadgetGeek</dc:creator>
      <dc:date>2018-05-29T05:12:24Z</dc:date>
    </item>
    <item>
      <title>Re: Average and Diff per host</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Average-and-Diff-per-host/m-p/417328#M120084</link>
      <description>&lt;P&gt;1) Yes fields - data was only for my run anywhere example not for your search. You can remove that.&lt;/P&gt;

&lt;P&gt;2) Add following command after &lt;CODE&gt;timechart&lt;/CODE&gt; command:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| fillnull value=0
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 31 May 2018 14:21:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Average-and-Diff-per-host/m-p/417328#M120084</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2018-05-31T14:21:31Z</dc:date>
    </item>
    <item>
      <title>Re: Average and Diff per host</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Average-and-Diff-per-host/m-p/417329#M120085</link>
      <description>&lt;P&gt;Brilliant thanks.&lt;/P&gt;</description>
      <pubDate>Thu, 31 May 2018 14:25:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Average-and-Diff-per-host/m-p/417329#M120085</guid>
      <dc:creator>GadgetGeek</dc:creator>
      <dc:date>2018-05-31T14:25:44Z</dc:date>
    </item>
  </channel>
</rss>

