Splunk Search

How do you find the percent of each srcip within a stats command?

bobbychanthongp
Explorer

base search | stats values(srcip) as Source count by catdesc

Above is my search. The results now yield each category description (catdesc) and lists each srcip for the catdesc. How do I break down each srcip by percent of the toal number of events? I need my table to be:

catdesc Source Percent Count
Pornography x.x.x.x 25% 200
y.y.y.y 50%

z.z.z.z 25%

Gaming a.a.a.a 50% 100
b.b.b.b 50%

Thanks.

Tags (1)
0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi
see this example

index=wineventlog | head 100
| stats count BY Dominio_account EventCode
| eventstats sum(count) AS total BY Dominio_account
| eval perc=round(count/total*100,2)."%"

In your search

base search 
| stats count AS Count by catdesc srcip
| eventstats sum(count) AS total BY catdesc 
| eval Percent=round(Count/total*100,2)."%"
| rename srcip AS Source
| table catdesc Source Percent Count

Bye.
Giuseppe

bobbychanthongp
Explorer

Thank you. It is exactly what I needed. However the eventstats sum(count) should be eventstats sum(Count).

0 Karma

gcusello
SplunkTrust
SplunkTrust

yes sorry!
If this answer satisfies your need, please accept it.
Bye.
Giuseppe

0 Karma
Get Updates on the Splunk Community!

September Community Champions: A Shoutout to Our Contributors!

As we close the books on another fantastic month, we want to take a moment to celebrate the people who are the ...

Splunk Decoded: Service Maps vs Service Analyzer Tree View vs Flow Maps

It’s Monday morning, and your phone is buzzing with alert escalations – your customer-facing portal is running ...

What’s New in Splunk Observability – September 2025

What's NewWe are excited to announce the latest enhancements to Splunk Observability, designed to help ITOps ...