<?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: How do I count each value of a multi-value field and show the top 30 with percentage? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-count-each-value-of-a-multi-value-field-and-show-the/m-p/439745#M125084</link>
    <description>&lt;P&gt;@raykongstar, &lt;BR /&gt;
1. The percentage calculated as  what percentage count  per port is of Total count for that IP ((count/total)*100). Let me know what's your formula for percentage and we can change. &lt;BR /&gt;
2. try&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;   dest_ip="10.66.100.*" | stats count by dest_port,port,protocol,dest_ip|eventstats sum(count) as total by dest_ip
   |eval percentage=round((count/total)*100,2)
   |stats list(*) as * by dest_ip|sort - total |head 30|fields - total
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 21 Oct 2018 02:12:36 GMT</pubDate>
    <dc:creator>renjith_nair</dc:creator>
    <dc:date>2018-10-21T02:12:36Z</dc:date>
    <item>
      <title>How do I count each value of a multi-value field and show the top 30 with percentage?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-count-each-value-of-a-multi-value-field-and-show-the/m-p/439739#M125078</link>
      <description>&lt;P&gt;Dear Community,&lt;/P&gt;

&lt;P&gt;So far, I have gone through the posted QnAs, but haven't yet found a way to make it work with my data context and desired output.&lt;/P&gt;

&lt;P&gt;I'm analyzing ASA firewall logs. I'm trying to make a search for the top 30 inbound ports for a range of IPs.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;FIELDS:
Destination IP = dest_ip 
Destination Port = dest_port
Protocol = protocol
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The closest I could get was as below;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;dest_ip="10.66.100.*" | stats value(dest_port) count by dest_ip
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The above gave me a list of IPs and ports but the total count was seemingly for all ports combined.&lt;/P&gt;

&lt;P&gt;DESIRED OUTPUT:&lt;BR /&gt;
IP # List of Ports # Hits count for each port # Protocol # Percentage of total traffic&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Search results for ports belonging to the same IP address should be grouped together. So IP address followed but multi-value field of ports with corresponding count, protocol and percentage for each.&lt;/STRONG&gt;&lt;/P&gt;

&lt;HR /&gt;

&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;We can also try this on the buttercupgames data so that we all get same output format;&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Fields for buttercupgames:
dest_port = clientip
dest_ip= productId
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Let's use just these two fields above, forget protocol &amp;amp; port.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; Buttercupgames | stats count by productId,clientip | eventstats sum(count) as total by productId
 | eval percentage=round((count/total)*100,2)
     | stats list(*) as * by productId | sort -total | head 30 | fields - total
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I hope you already have buttercupgames data or know how to get it. I'm not allowed to post links yet. It's Splunk's own sample data.&lt;/P&gt;

&lt;P&gt;Regards!&lt;/P&gt;</description>
      <pubDate>Sat, 20 Oct 2018 12:40:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-count-each-value-of-a-multi-value-field-and-show-the/m-p/439739#M125078</guid>
      <dc:creator>raykongstar</dc:creator>
      <dc:date>2018-10-20T12:40:52Z</dc:date>
    </item>
    <item>
      <title>Re: How do I count each value of a multi-value field and show the top 30 with percentage?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-count-each-value-of-a-multi-value-field-and-show-the/m-p/439740#M125079</link>
      <description>&lt;P&gt;@raykongstar,&lt;/P&gt;

&lt;P&gt;Try&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  dest_ip="10.66.100.*" | stats count by dest_port,port,protocol,dest_ip|eventstats sum(count) as _total by dest_ip
  |eval percentage=round((count/_total)*100,2)
  |stats list(*) as * by dest_ip
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;Updated:&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  dest_ip="10.66.100.*" | stats count by dest_port,port,protocol,dest_ip|eventstats sum(count) as _total by dest_ip
  |eval percentage=round((count/_total)*100,2)
  |stats list(*) as * by dest_ip
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 20 Oct 2018 13:16:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-count-each-value-of-a-multi-value-field-and-show-the/m-p/439740#M125079</guid>
      <dc:creator>renjith_nair</dc:creator>
      <dc:date>2018-10-20T13:16:53Z</dc:date>
    </item>
    <item>
      <title>Re: How do I count each value of a multi-value field and show the top 30 with percentage?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-count-each-value-of-a-multi-value-field-and-show-the/m-p/439741#M125080</link>
      <description>&lt;P&gt;@renjith.nair You search was very close but unfortunately had the following issues or maybe I wasn't clear enough.&lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt; The percentage is supposed to calculate only for a certain dest_ip, so should total to 100% for each IP address.&lt;/LI&gt;
&lt;LI&gt;The ports belonging to one IP address should be grouped together, not appear as different search results. ie. See below;&lt;/LI&gt;
&lt;/OL&gt;

&lt;P&gt;10.66.100.1 ..... 6543 ... 345 .... 40%&lt;BR /&gt;
                      ....  443 ..... 453 ..... 50%&lt;BR /&gt;
                      ..... 80   ....... 70 ...... 10%&lt;/P&gt;

&lt;P&gt;10.66.100.4 ..... 6543 ... 345 .... 30%&lt;BR /&gt;
                      ....  443 ..... 453 ..... 50%&lt;BR /&gt;
                      ..... 80   ....... 70 ...... 20%&lt;/P&gt;

&lt;P&gt;10.66.100.8 ..... 6543 ... 345 .... 20%&lt;BR /&gt;
                      ....  443 ..... 453 ..... 20%&lt;BR /&gt;
                      ..... 80   ....... 70 ...... 10%&lt;BR /&gt;
                      ....  443 ..... 453 ..... 30%&lt;BR /&gt;
                      ..... 80   ....... 70 ...... 20%&lt;/P&gt;

&lt;P&gt;Etc etc etc.. I hope that's clearer now.&lt;/P&gt;

&lt;P&gt;Thanks in advance.&lt;/P&gt;</description>
      <pubDate>Sat, 20 Oct 2018 14:53:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-count-each-value-of-a-multi-value-field-and-show-the/m-p/439741#M125080</guid>
      <dc:creator>raykongstar</dc:creator>
      <dc:date>2018-10-20T14:53:21Z</dc:date>
    </item>
    <item>
      <title>Re: How do I count each value of a multi-value field and show the top 30 with percentage?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-count-each-value-of-a-multi-value-field-and-show-the/m-p/439742#M125081</link>
      <description>&lt;P&gt;I see spaces have been removed.. just imagine there next line after IP address is indented.&lt;/P&gt;</description>
      <pubDate>Sat, 20 Oct 2018 14:55:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-count-each-value-of-a-multi-value-field-and-show-the/m-p/439742#M125081</guid>
      <dc:creator>raykongstar</dc:creator>
      <dc:date>2018-10-20T14:55:05Z</dc:date>
    </item>
    <item>
      <title>Re: How do I count each value of a multi-value field and show the top 30 with percentage?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-count-each-value-of-a-multi-value-field-and-show-the/m-p/439743#M125082</link>
      <description>&lt;P&gt;@raykongstar,&lt;BR /&gt;
Try this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; dest_ip="10.66.100.*" | stats count by dest_port,port,protocol,dest_ip|eventstats sum(count) as _total by dest_ip
 |eval percentage=round((count/_total)*100,2)
 |stats list(*) as * by dest_ip
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 20 Oct 2018 15:23:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-count-each-value-of-a-multi-value-field-and-show-the/m-p/439743#M125082</guid>
      <dc:creator>renjith_nair</dc:creator>
      <dc:date>2018-10-20T15:23:58Z</dc:date>
    </item>
    <item>
      <title>Re: How do I count each value of a multi-value field and show the top 30 with percentage?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-count-each-value-of-a-multi-value-field-and-show-the/m-p/439744#M125083</link>
      <description>&lt;P&gt;The updated version of your search gave me exactly what I needed except the formula for percentage is still not right.&lt;/P&gt;

&lt;P&gt;But. So far so good, I need to use this information to help determine what ports to open on the firewall.&lt;/P&gt;

&lt;P&gt;Only the following are missing now;&lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;Percentage not calculated right.&lt;/LI&gt;
&lt;LI&gt;BONUS: Top 30/20/10 values.&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Sat, 20 Oct 2018 16:08:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-count-each-value-of-a-multi-value-field-and-show-the/m-p/439744#M125083</guid>
      <dc:creator>raykongstar</dc:creator>
      <dc:date>2018-10-20T16:08:41Z</dc:date>
    </item>
    <item>
      <title>Re: How do I count each value of a multi-value field and show the top 30 with percentage?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-count-each-value-of-a-multi-value-field-and-show-the/m-p/439745#M125084</link>
      <description>&lt;P&gt;@raykongstar, &lt;BR /&gt;
1. The percentage calculated as  what percentage count  per port is of Total count for that IP ((count/total)*100). Let me know what's your formula for percentage and we can change. &lt;BR /&gt;
2. try&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;   dest_ip="10.66.100.*" | stats count by dest_port,port,protocol,dest_ip|eventstats sum(count) as total by dest_ip
   |eval percentage=round((count/total)*100,2)
   |stats list(*) as * by dest_ip|sort - total |head 30|fields - total
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 21 Oct 2018 02:12:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-count-each-value-of-a-multi-value-field-and-show-the/m-p/439745#M125084</guid>
      <dc:creator>renjith_nair</dc:creator>
      <dc:date>2018-10-21T02:12:36Z</dc:date>
    </item>
    <item>
      <title>Re: How do I count each value of a multi-value field and show the top 30 with percentage?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-count-each-value-of-a-multi-value-field-and-show-the/m-p/439746#M125085</link>
      <description>&lt;P&gt;Thanks Renjith,&lt;/P&gt;

&lt;P&gt;Unfortunately that didn't solve the issue(s).&lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;&lt;P&gt;Percentage = (count/Summation of total counts PER dest_ip)*100,2) . It can be confusing, see my suggestion below about buttercupgames data.&lt;/P&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;P&gt;I still didn't get top 30 and the results weren't sorted.&lt;/P&gt;&lt;/LI&gt;
&lt;/OL&gt;

&lt;P&gt;I had an idea, why dont we all try this in the context of BUTTERGAMES data so that we be on the same page on the output;&lt;/P&gt;

&lt;P&gt;For instance I tried below on buttercupgames but still didn't give expected results;&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Fields for buttercupgames:&lt;/STRONG&gt;&lt;BR /&gt;
dest_port = clientip&lt;BR /&gt;
dest_ip= productId&lt;/P&gt;

&lt;P&gt;Let's use just these two fields above, forget protocol &amp;amp; port.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Buttercupgames | stats count by productId,clientip |eventstats sum(count) as total by productId
|eval percentage=round((count/total)*100,2)
    |stats list(*) as * by productId|sort -total |head 30|fields - total
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I hope you already have buttercupgames data or know how to get it. I'm not allowed to post links yet. It's Splunk's own sample data.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 21:43:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-count-each-value-of-a-multi-value-field-and-show-the/m-p/439746#M125085</guid>
      <dc:creator>raykongstar</dc:creator>
      <dc:date>2020-09-29T21:43:38Z</dc:date>
    </item>
    <item>
      <title>Re: How do I count each value of a multi-value field and show the top 30 with percentage?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-count-each-value-of-a-multi-value-field-and-show-the/m-p/439747#M125086</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/143527"&gt;@raykongstar&lt;/a&gt;, I am using data from internal index to simulate your scenario. &lt;/P&gt;

&lt;P&gt;Here I consider &lt;STRONG&gt;index&lt;/STRONG&gt; in place of your &lt;STRONG&gt;dest_ip&lt;/STRONG&gt; and &lt;STRONG&gt;sourcetype&lt;/STRONG&gt; in place of your &lt;STRONG&gt;port&lt;/STRONG&gt;.&lt;BR /&gt;
Please have a look at the attached image and let me know where you see the issue&lt;/P&gt;

&lt;P&gt;In &lt;STRONG&gt;step1&lt;/STRONG&gt;  - It calculates the count based on the index,sourcetype(dest_ip,dest_port)   and then total is calculated per index(dest_ip). Percentage is calculated as &lt;CODE&gt;(count/total)*100&lt;/CODE&gt;&lt;BR /&gt;
In &lt;STRONG&gt;step2&lt;/STRONG&gt; - It brings everything into a list for the formatting but data remains the same (ignore slight variation of count as its live data)&lt;BR /&gt;
In &lt;STRONG&gt;step3&lt;/STRONG&gt;  - We sort it based on total and take the first value which is index=_internal in this cases since it has the highest total.&lt;BR /&gt;
&lt;IMG src="https://community.splunk.com/storage/temp/256282-results.jpg" alt="alt text" /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 21:39:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-count-each-value-of-a-multi-value-field-and-show-the/m-p/439747#M125086</guid>
      <dc:creator>renjith_nair</dc:creator>
      <dc:date>2020-09-29T21:39:58Z</dc:date>
    </item>
    <item>
      <title>Re: How do I count each value of a multi-value field and show the top 30 with percentage?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-count-each-value-of-a-multi-value-field-and-show-the/m-p/439748#M125087</link>
      <description>&lt;P&gt;Thanks this worked perfectly. I'll play around with the Top/head command ad it's still not giving me the top results I need.. Thanks Again, This is usable for me.&lt;/P&gt;</description>
      <pubDate>Sun, 21 Oct 2018 16:37:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-count-each-value-of-a-multi-value-field-and-show-the/m-p/439748#M125087</guid>
      <dc:creator>raykongstar</dc:creator>
      <dc:date>2018-10-21T16:37:27Z</dc:date>
    </item>
  </channel>
</rss>

