Splunk Search

how to calculate percent of size

fzfengzhuang
New Member

hello

thanks for all your help

how can I calculate the percent of size base on the data
size<1024 2048<size >1024 size >2048

index=maillog size=*
| stats count(eval(size<1024)) as "<1024" count(eval(size>1024 AND size<2048)) as "1024> & <2028" count(eval(size>2048)) as ">2048"
| transpose column_name="size_range"
| rename "row 1" as count

thanks again

Tags (1)
0 Karma

niketn
Legend

@fzfengzhuang this seems to be a duplicate question of https://answers.splunk.com/answers/641469/how-to-do-a-pie-chart.html
Could you please confirm?

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma

TISKAR
Builder

Hello,

Try this,

index=maillog size=*
| stats count(eval(size<1024)) as "val1" count(eval(size>=1024 AND size<2048)) as "val2" count(eval(size>=2048)) as val3 count as tot
| eval perc1=round(100*val1/tot), perc2=round(100*val2/tot), perc3=round(100*val3/tot)

| transpose column_name="size_range" | rename "row 1" as count

Or This:

 index=maillog size=*
    | stats count(eval(size<1024)) as "val1" count(eval(size>=1024 AND size<2048)) as "val2" count(eval(size>=2048)) as val3 
    | transpose column_name="size_range"
    | rename "row 1" as row1
    | eventstats sum(row1) as total
    | eval row1=round(100*row1/total)
    | transpose column_name="size_range" | rename "row 1" as count
0 Karma

adonio
Ultra Champion

hello there,

please try this search anywhere:

   | makeresults count=1
    | eval size="1025,1000,2000,3000,500,5000,200,4000,2100,3001,800,100,2048"
    | makemv delim="," size
    | mvexpand size
    | stats count as event_count count(eval(size<1024)) as less_than count(eval(size>1024 AND size<2048)) as in_between count(eval(size>2048)) as greater_than
    | eval percent_less = round(less_than/event_count*100, 2), percent_in_between = round(in_between/event_count*100, 2), percent_greater_than = round(greater_than/event_count*100, 2)

see screenshot below:
alt text

note, see how it does not count the value "2048" as it is equal (not greater or lesser than) so you can add that rule as you see fit
hope it helps

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 ...