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!

See just what you’ve been missing | Observability tracks at Splunk University

Looking to sharpen your observability skills so you can better understand how to collect and analyze data from ...

Weezer at .conf25? Say it ain’t so!

Hello Splunkers, The countdown to .conf25 is on-and we've just turned up the volume! We're thrilled to ...

How SC4S Makes Suricata Logs Ingestion Simple

Network security monitoring has become increasingly critical for organizations of all sizes. Splunk has ...