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!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...