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!

Splunk + ThousandEyes: Correlate frontend, app, and network data to troubleshoot ...

 Are you tired of troubleshooting delays caused by siloed frontend, application, and network data? We've got a ...

Splunk Observability for AI

Don’t miss out on an exciting Tech Talk on Splunk Observability for AI!Discover how Splunk’s agentic AI ...

🔐 Trust at Every Hop: How mTLS in Splunk Enterprise 10.0 Makes Security Simpler

From Idea to Implementation: Why Splunk Built mTLS into Splunk Enterprise 10.0  mTLS wasn’t just a checkbox ...