<?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: Dividingof result from two Hosts in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Dividingof-result-from-two-Hosts/m-p/145596#M40610</link>
    <description>&lt;P&gt;Oops, my bad. you need to make sure that the total_sum survives through the stats operation;&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;host=bob | eventstats sum(field_A) as total_sum | search field_B=X | stats sum(field_A) as X_sum first(total_sum) as total_sum | table X_sum total_sum&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;NB. Since the &lt;CODE&gt;eventstats&lt;/CODE&gt; only calculates one value, it does not matter much which &lt;CODE&gt;stats&lt;/CODE&gt; function (first, last, max etc) you use to  preserve it.&lt;/P&gt;</description>
    <pubDate>Tue, 11 Feb 2014 15:16:55 GMT</pubDate>
    <dc:creator>kristian_kolb</dc:creator>
    <dc:date>2014-02-11T15:16:55Z</dc:date>
    <item>
      <title>Dividingof result from two Hosts</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Dividingof-result-from-two-Hosts/m-p/145586#M40600</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;

&lt;P&gt;I would like to divide the values from 2 hosts.Is it possible.&lt;/P&gt;

&lt;P&gt;Example:&lt;BR /&gt;
Say i have HostA and HostB.&lt;BR /&gt;
HostA contains a field which can be used for calculating total.&lt;BR /&gt;
HostB which contails value to divide.&lt;/P&gt;

&lt;P&gt;Ie host=HostA|stats sum(filed) will give 1000.&lt;BR /&gt;
host=HostB|stats sum(filed)    will give 3.&lt;BR /&gt;
I want to divide 1000/3 in single search query .Is it possible?&lt;/P&gt;</description>
      <pubDate>Tue, 11 Feb 2014 08:07:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Dividingof-result-from-two-Hosts/m-p/145586#M40600</guid>
      <dc:creator>SplunkBaby</dc:creator>
      <dc:date>2014-02-11T08:07:35Z</dc:date>
    </item>
    <item>
      <title>Re: Dividingof result from two Hosts</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Dividingof-result-from-two-Hosts/m-p/145587#M40601</link>
      <description>&lt;P&gt;Hi SplunkBaby,&lt;/P&gt;

&lt;P&gt;a quick way could be the following &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.0.1/SearchReference/Multisearch"&gt;multisearch&lt;/A&gt;:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; | multisearch [ search host=HostA | stats sum(filed) AS fieldA ] [ search host=HostB | stats sum(filed) AS fieldB ] | eval division=fieldA/fieldB | table host filed fieldA fieldB division
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I'm pretty sure there are better and more efficient ways to do it, but this will get you started ...&lt;/P&gt;

&lt;P&gt;cheers, MuS&lt;/P&gt;</description>
      <pubDate>Tue, 11 Feb 2014 08:27:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Dividingof-result-from-two-Hosts/m-p/145587#M40601</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2014-02-11T08:27:24Z</dc:date>
    </item>
    <item>
      <title>Re: Dividingof result from two Hosts</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Dividingof-result-from-two-Hosts/m-p/145588#M40602</link>
      <description>&lt;P&gt;If the field name is the same you can do it like so (Different sourcetypes rather than hosts in the example below);&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=_internal sourcetype=splunkd_access OR sourcetype=splunkd | stats sum(timeendpos) as summy by sourcetype | stats values(summy) as summy2| eval foo=mvindex(summy2,0) | eval bar=mvindex(summy2,1) | eval result=foo/bar
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If the field names are different, it's even easier (&lt;CODE&gt;bytes&lt;/CODE&gt; in splunkd_access and &lt;CODE&gt;workers&lt;/CODE&gt; in splunkd);&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=_internal sourcetype=splunkd_access OR  sourcetype=splunkd | stats sum(bytes) as sumb sum(workers) as sumw | eval result = sumb/sumw
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;/k&lt;/P&gt;</description>
      <pubDate>Tue, 11 Feb 2014 08:41:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Dividingof-result-from-two-Hosts/m-p/145588#M40602</guid>
      <dc:creator>kristian_kolb</dc:creator>
      <dc:date>2014-02-11T08:41:10Z</dc:date>
    </item>
    <item>
      <title>Re: Dividingof result from two Hosts</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Dividingof-result-from-two-Hosts/m-p/145589#M40603</link>
      <description>&lt;P&gt;Oops, you're faster (again), but I'll leave my answer as it describes a different solution. &lt;/P&gt;

&lt;P&gt;/k&lt;/P&gt;</description>
      <pubDate>Tue, 11 Feb 2014 08:43:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Dividingof-result-from-two-Hosts/m-p/145589#M40603</guid>
      <dc:creator>kristian_kolb</dc:creator>
      <dc:date>2014-02-11T08:43:18Z</dc:date>
    </item>
    <item>
      <title>Re: Dividingof result from two Hosts</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Dividingof-result-from-two-Hosts/m-p/145590#M40604</link>
      <description>&lt;P&gt;Thanks I work with second solution(fields different) and it helped me to solve.&lt;/P&gt;

&lt;P&gt;For my understanding I have another doubt also.&lt;BR /&gt;
In the same example if i want to take sum of a field in hostA before and after filtering data how can i proceed.&lt;BR /&gt;
Ex:&lt;BR /&gt;
host="hostA" |sum(field) as Beforefilter|field1=A|sum(field)as Afterfilter&lt;BR /&gt;
Is the above possible?&lt;/P&gt;</description>
      <pubDate>Tue, 11 Feb 2014 10:18:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Dividingof-result-from-two-Hosts/m-p/145590#M40604</guid>
      <dc:creator>SplunkBaby</dc:creator>
      <dc:date>2014-02-11T10:18:30Z</dc:date>
    </item>
    <item>
      <title>Re: Dividingof result from two Hosts</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Dividingof-result-from-two-Hosts/m-p/145591#M40605</link>
      <description>&lt;P&gt;When i tried this i got below exception.&lt;BR /&gt;
Error in 'multisearch' command: Multisearch subsearches may only contain purely streaming operations (subsearch 1 contains a non-streaming command.)&lt;/P&gt;</description>
      <pubDate>Tue, 11 Feb 2014 10:25:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Dividingof-result-from-two-Hosts/m-p/145591#M40605</guid>
      <dc:creator>SplunkBaby</dc:creator>
      <dc:date>2014-02-11T10:25:08Z</dc:date>
    </item>
    <item>
      <title>Re: Dividingof result from two Hosts</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Dividingof-result-from-two-Hosts/m-p/145592#M40606</link>
      <description>&lt;P&gt;okay, based on /k second example which you used to get it working a &lt;CODE&gt;multisearch&lt;/CODE&gt; would look like this:&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;| multisearch [ search index=_internal sourcetype=splunkd_access | eval foo=bytes ] [ search index=_internal sourcetype=splunkd | eval bar=workers ] | stats sum(foo) as sumb sum(bar) as sumw | eval result = sumb/sumw&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;but this is really not necessary in your use case since you use fields with different names and different sourcetypes. A multisearch is used for other use cases......&lt;/P&gt;</description>
      <pubDate>Tue, 11 Feb 2014 12:27:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Dividingof-result-from-two-Hosts/m-p/145592#M40606</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2014-02-11T12:27:27Z</dc:date>
    </item>
    <item>
      <title>Re: Dividingof result from two Hosts</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Dividingof-result-from-two-Hosts/m-p/145593#M40607</link>
      <description>&lt;P&gt;Maybe I don't fully understand your question, but if you want make like this (in a pseudo-search-query);&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;find all relevant events 
| sum(field_1) as total_sum 
| filter to only keep events where user=bob
| sum(field_1) as bob_sum  
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Then you can use &lt;CODE&gt;eventstats&lt;/CODE&gt;, which puts the statistic in all events, without altering them/removing information;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;host=A | eventstats sum(field) as total_sum | search field1=X | stats sum(field) as X_sum 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;/K&lt;/P&gt;</description>
      <pubDate>Tue, 11 Feb 2014 12:38:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Dividingof-result-from-two-Hosts/m-p/145593#M40607</guid>
      <dc:creator>kristian_kolb</dc:creator>
      <dc:date>2014-02-11T12:38:58Z</dc:date>
    </item>
    <item>
      <title>Re: Dividingof result from two Hosts</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Dividingof-result-from-two-Hosts/m-p/145594#M40608</link>
      <description>&lt;P&gt;Say I  have a field Visit my host.&lt;BR /&gt;
I want to find the total of Visit  first.Then i want to filter host with some condition and again want to find the sum for Visit.&lt;BR /&gt;
I did the query like this&lt;BR /&gt;
host=ABC|eventstats  sum(Visits) as total_sum | search "EMP  Code"=BJX |stats sum(Visits) as X_sum.I am getting only second sum ie (X_sum)&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 15:51:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Dividingof-result-from-two-Hosts/m-p/145594#M40608</guid>
      <dc:creator>SplunkBaby</dc:creator>
      <dc:date>2020-09-28T15:51:42Z</dc:date>
    </item>
    <item>
      <title>Re: Dividingof result from two Hosts</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Dividingof-result-from-two-Hosts/m-p/145595#M40609</link>
      <description>&lt;P&gt;Only X_sum is showing in my result.total_sum is blank&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 15:51:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Dividingof-result-from-two-Hosts/m-p/145595#M40609</guid>
      <dc:creator>SplunkBaby</dc:creator>
      <dc:date>2020-09-28T15:51:45Z</dc:date>
    </item>
    <item>
      <title>Re: Dividingof result from two Hosts</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Dividingof-result-from-two-Hosts/m-p/145596#M40610</link>
      <description>&lt;P&gt;Oops, my bad. you need to make sure that the total_sum survives through the stats operation;&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;host=bob | eventstats sum(field_A) as total_sum | search field_B=X | stats sum(field_A) as X_sum first(total_sum) as total_sum | table X_sum total_sum&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;NB. Since the &lt;CODE&gt;eventstats&lt;/CODE&gt; only calculates one value, it does not matter much which &lt;CODE&gt;stats&lt;/CODE&gt; function (first, last, max etc) you use to  preserve it.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Feb 2014 15:16:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Dividingof-result-from-two-Hosts/m-p/145596#M40610</guid>
      <dc:creator>kristian_kolb</dc:creator>
      <dc:date>2014-02-11T15:16:55Z</dc:date>
    </item>
    <item>
      <title>Re: Dividingof result from two Hosts</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Dividingof-result-from-two-Hosts/m-p/145597#M40611</link>
      <description>&lt;P&gt;Try these&lt;/P&gt;

&lt;P&gt;Options 1&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;host=hostA | stats sum(field) as FieldTotA | appendcols [search host=hostB | stats sum(field) as FieldTotB] | eval division=round(FieldTotA/FieldTotB,2)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Option 2 &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| multisearch [search  host=hostA | eval fieldA=field | table fieldA] [search host=hostB | eval fieldB=field | table fieldB] | stats sum(fieldA) as FieldTotA, sum(fieldB) as fieldTotB | eval division=round(FieldTotA/FieldTotB,2) 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 11 Feb 2014 15:44:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Dividingof-result-from-two-Hosts/m-p/145597#M40611</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2014-02-11T15:44:47Z</dc:date>
    </item>
  </channel>
</rss>

