<?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 streamstats sum() by  not functioning as expected in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/streamstats-sum-by-not-functioning-as-expected/m-p/85315#M21788</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I have the following search, which is attempting to add up the number of dropped and processed syslog messages in each event, based on the field syslog_dest_host:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype="syslog-stats" | streamstats window=1 sum(syslog_dropped) as Dest_Syslog_Dropped, sum(syslog_processed) as Dest_Syslog_Processed by syslog_dest_host | table _time, host, syslog_dest_host, syslog_dropped, Dest_Syslog_Dropped, syslog_processed, Dest_Syslog_Processed
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;When this is run, however, I see that the sum is being taken over all values of syslog_dest_host in the event, rather than one sum per syslog_dest_host, eg:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;host    syslog_dest_host    syslog_dropped    Dest_Syslog_Dropped    ...
host1   dest1               1                 12
        dest2               1
        dest2               3
        dest1               4
        dest1               2
        dest2               1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;However, what I would like to see is:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;host    syslog_dest_host    syslog_dropped    Dest_Syslog_Dropped    ...
host1   dest1               1                 7
        dest2               1                 5
        dest2               3
        dest1               4
        dest1               2
        dest2               1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Is what I want even possible?&lt;/P&gt;

&lt;P&gt;If not, is there a way to filter within the event, such that only the instances of syslog_dest_host and syslog_dropped are returned when syslog_dest_host=host1?  I tried adding this to the search string "sourcetype=syslog-stats syslog_dest_host=host1", but because host1 appears somewhere in the event, the entire event is returned.&lt;/P&gt;

&lt;P&gt;Rgds,&lt;BR /&gt;
Brett.&lt;/P&gt;</description>
    <pubDate>Mon, 28 Sep 2020 14:15:36 GMT</pubDate>
    <dc:creator>brettw10</dc:creator>
    <dc:date>2020-09-28T14:15:36Z</dc:date>
    <item>
      <title>streamstats sum() by  not functioning as expected</title>
      <link>https://community.splunk.com/t5/Splunk-Search/streamstats-sum-by-not-functioning-as-expected/m-p/85315#M21788</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I have the following search, which is attempting to add up the number of dropped and processed syslog messages in each event, based on the field syslog_dest_host:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype="syslog-stats" | streamstats window=1 sum(syslog_dropped) as Dest_Syslog_Dropped, sum(syslog_processed) as Dest_Syslog_Processed by syslog_dest_host | table _time, host, syslog_dest_host, syslog_dropped, Dest_Syslog_Dropped, syslog_processed, Dest_Syslog_Processed
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;When this is run, however, I see that the sum is being taken over all values of syslog_dest_host in the event, rather than one sum per syslog_dest_host, eg:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;host    syslog_dest_host    syslog_dropped    Dest_Syslog_Dropped    ...
host1   dest1               1                 12
        dest2               1
        dest2               3
        dest1               4
        dest1               2
        dest2               1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;However, what I would like to see is:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;host    syslog_dest_host    syslog_dropped    Dest_Syslog_Dropped    ...
host1   dest1               1                 7
        dest2               1                 5
        dest2               3
        dest1               4
        dest1               2
        dest2               1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Is what I want even possible?&lt;/P&gt;

&lt;P&gt;If not, is there a way to filter within the event, such that only the instances of syslog_dest_host and syslog_dropped are returned when syslog_dest_host=host1?  I tried adding this to the search string "sourcetype=syslog-stats syslog_dest_host=host1", but because host1 appears somewhere in the event, the entire event is returned.&lt;/P&gt;

&lt;P&gt;Rgds,&lt;BR /&gt;
Brett.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 14:15:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/streamstats-sum-by-not-functioning-as-expected/m-p/85315#M21788</guid>
      <dc:creator>brettw10</dc:creator>
      <dc:date>2020-09-28T14:15:36Z</dc:date>
    </item>
    <item>
      <title>Re: streamstats sum() by  not functioning as expected</title>
      <link>https://community.splunk.com/t5/Splunk-Search/streamstats-sum-by-not-functioning-as-expected/m-p/85316#M21789</link>
      <description>&lt;P&gt;Hello bro,&lt;BR /&gt;
try the below search.    &lt;/P&gt;

&lt;P&gt;sourcetype="syslog-stats" | streamstats window=1 global=false sum(syslog_dropped) as Dest_Syslog_Dropped, sum(syslog_processed) as Dest_Syslog_Processed by syslog_dest_host | table _time, host, syslog_dest_host, syslog_dropped, Dest_Syslog_Dropped, syslog_processed, Dest_Syslog_Processed&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 14:15:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/streamstats-sum-by-not-functioning-as-expected/m-p/85316#M21789</guid>
      <dc:creator>eashwar</dc:creator>
      <dc:date>2020-09-28T14:15:56Z</dc:date>
    </item>
    <item>
      <title>Re: streamstats sum() by  not functioning as expected</title>
      <link>https://community.splunk.com/t5/Splunk-Search/streamstats-sum-by-not-functioning-as-expected/m-p/85317#M21790</link>
      <description>&lt;P&gt;I would get out of multivalue-land for this, even if you go back into multivalue fields at the end. &lt;/P&gt;

&lt;P&gt;For example:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype="syslog-stats" | mvexpand syslog_dest_host | streamstats window=1 sum(syslog_dropped) as Dest_Syslog_Dropped, sum(syslog_processed) as Dest_Syslog_Processed by syslog_dest_host | table _time, host, syslog_dest_host, syslog_dropped, Dest_Syslog_Dropped, syslog_processed, Dest_Syslog_Processed
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If you need to fold it back up the way it was at the end,  then do this: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype="syslog-stats" | streamstats count as rowId | mvexpand syslog_dest_host | streamstats window=1 sum(syslog_dropped) as Dest_Syslog_Dropped, sum(syslog_processed) as Dest_Syslog_Processed by syslog_dest_host | table _time, host, syslog_dest_host, syslog_dropped, Dest_Syslog_Dropped, syslog_processed, Dest_Syslog_Processed | stats values(*) as * by rowId
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 07 May 2015 00:27:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/streamstats-sum-by-not-functioning-as-expected/m-p/85317#M21790</guid>
      <dc:creator>sideview</dc:creator>
      <dc:date>2015-05-07T00:27:07Z</dc:date>
    </item>
  </channel>
</rss>

