<?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 How to combine the stats sum() and top functionality in my search? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-combine-the-stats-sum-and-top-functionality-in-my-search/m-p/244755#M72901</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;I'm trying to do something which looks like a basic need to me, but I'm stuck at finding a simple way to do it.&lt;BR /&gt;
I have data of TCP session statistics with the following fields: Client IP, Server IP, Volume of data exchanged (bytes)&lt;BR /&gt;
For each Client IP, I want to get the list of top 5 servers with which the Client has exchanged the most bytes (including the sum) and remaining servers as Others.&lt;/P&gt;

&lt;P&gt;So if my data set is&lt;BR /&gt;
1.2.3.4;2.3.4.5;7000&lt;BR /&gt;
1.2.3.4;2.3.4.5;7000&lt;BR /&gt;
1.2.3.4;2.3.4.6;5000&lt;BR /&gt;
1.2.3.4;2.3.4.7;4000&lt;BR /&gt;
1.2.3.4;2.3.4.8;3000&lt;BR /&gt;
1.2.3.4;2.3.4.9;2000&lt;BR /&gt;
1.2.3.4;2.3.4.10;1000&lt;BR /&gt;
1.2.3.4;2.3.4.11;500&lt;/P&gt;

&lt;P&gt;I want:&lt;BR /&gt;
1.2.3.4;2.3.4.5;14000&lt;BR /&gt;
1.2.3.4;2.3.4.6;5000&lt;BR /&gt;
1.2.3.4;2.3.4.7;4000&lt;BR /&gt;
1.2.3.4;2.3.4.8;3000&lt;BR /&gt;
1.2.3.4;2.3.4.9;2000&lt;BR /&gt;
1.2.3.4;OTHER;1500&lt;/P&gt;

&lt;P&gt;With stats, I could do &lt;CODE&gt;stats sum(bytes) by Client, Server&lt;/CODE&gt;, but I'll get the whole statistics (my result will not be limited to the top 5 + other)&lt;BR /&gt;
With Top, I would not be able to sum bytes.&lt;/P&gt;

&lt;P&gt;Regards,&lt;/P&gt;</description>
    <pubDate>Tue, 10 May 2016 17:55:04 GMT</pubDate>
    <dc:creator>jebabin</dc:creator>
    <dc:date>2016-05-10T17:55:04Z</dc:date>
    <item>
      <title>How to combine the stats sum() and top functionality in my search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-combine-the-stats-sum-and-top-functionality-in-my-search/m-p/244755#M72901</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;I'm trying to do something which looks like a basic need to me, but I'm stuck at finding a simple way to do it.&lt;BR /&gt;
I have data of TCP session statistics with the following fields: Client IP, Server IP, Volume of data exchanged (bytes)&lt;BR /&gt;
For each Client IP, I want to get the list of top 5 servers with which the Client has exchanged the most bytes (including the sum) and remaining servers as Others.&lt;/P&gt;

&lt;P&gt;So if my data set is&lt;BR /&gt;
1.2.3.4;2.3.4.5;7000&lt;BR /&gt;
1.2.3.4;2.3.4.5;7000&lt;BR /&gt;
1.2.3.4;2.3.4.6;5000&lt;BR /&gt;
1.2.3.4;2.3.4.7;4000&lt;BR /&gt;
1.2.3.4;2.3.4.8;3000&lt;BR /&gt;
1.2.3.4;2.3.4.9;2000&lt;BR /&gt;
1.2.3.4;2.3.4.10;1000&lt;BR /&gt;
1.2.3.4;2.3.4.11;500&lt;/P&gt;

&lt;P&gt;I want:&lt;BR /&gt;
1.2.3.4;2.3.4.5;14000&lt;BR /&gt;
1.2.3.4;2.3.4.6;5000&lt;BR /&gt;
1.2.3.4;2.3.4.7;4000&lt;BR /&gt;
1.2.3.4;2.3.4.8;3000&lt;BR /&gt;
1.2.3.4;2.3.4.9;2000&lt;BR /&gt;
1.2.3.4;OTHER;1500&lt;/P&gt;

&lt;P&gt;With stats, I could do &lt;CODE&gt;stats sum(bytes) by Client, Server&lt;/CODE&gt;, but I'll get the whole statistics (my result will not be limited to the top 5 + other)&lt;BR /&gt;
With Top, I would not be able to sum bytes.&lt;/P&gt;

&lt;P&gt;Regards,&lt;/P&gt;</description>
      <pubDate>Tue, 10 May 2016 17:55:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-combine-the-stats-sum-and-top-functionality-in-my-search/m-p/244755#M72901</guid>
      <dc:creator>jebabin</dc:creator>
      <dc:date>2016-05-10T17:55:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to combine the stats sum() and top functionality in my search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-combine-the-stats-sum-and-top-functionality-in-my-search/m-p/244756#M72902</link>
      <description>&lt;P&gt;Easy peasy&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;yoursearchhere
| stats sum(bytes) as totalBytes by Client, Server
| sort 10 -totalBytes
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;will return a list of the "top 10" Client-Server combinations based on the sum.&lt;/P&gt;

&lt;P&gt;If you want the top 5 plus "other", try this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;yoursearchhere
| stats sum(bytes) as totalBytes by Client, Server
| eventstats sum(totalBytes) as grandTotal
| sort 5 -totalBytes
| appendpipe [ stats sum(totalBytes) as top5 avg(grandTotal) as grandTotal 
     | eval Client="Other" | eval Server="Other" | eval totalBytes = grandTotal - top5  ]
| eval percent = round(totalBytes*100/grandTotal,1)
| fields - top5 grandTotal
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Add the "Other" is clearly a little more tricky.&lt;/P&gt;</description>
      <pubDate>Tue, 10 May 2016 18:12:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-combine-the-stats-sum-and-top-functionality-in-my-search/m-p/244756#M72902</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2016-05-10T18:12:37Z</dc:date>
    </item>
  </channel>
</rss>

