Splunk Search

Show percentage of total by buckets

cosullivan66
Explorer

I'm evaluating a variable called lengthofpayload. I want to separate it into 10 buckets: 0-1000, 1000-2000, etc. Each bucket has a number of events in it, and I want to find the percent of the total events found in that time window each bucket holds. For example, if I wanted to find the number of events and how their payload lengths are distributed in the last 24 hours, it'd look like this:

6,000 events found  
lengthofpayload             percentage  
0-1000 16%  
1000-2000                   40%  
2000-3000                   20%

I found this link to something similar, but I don't want a timechart in the end: http://splunk-base.splunk.com/answers/27590/charting-percentage-of-a-total-over-time

This is the code I'm using and I think it's close but it doesn't work. It prints nothing out for the first(percentage) variable.

sourcetype="dbmon:kv" |  
search EVENTTYPE="ScreenSharingEvent" |   
eval lengthofpayload=len(PAYLOAD) |  
bucket lengthofpayload bins=10 |  
eventstats count as total by length of payload |  
stats count first(total) as total by lengthofpayload |  
eval percent=(count/total)*100 |  
chart first(percent) by lengthofpayload  

Thanks in advance for help/suggestions!

Tags (2)
0 Karma
1 Solution

Paolo_Prigione
Builder

You can use | top: it will give you the distribution # and % of results grouped by the value of a field.

sourcetype="dbmon:kv" 
| search EVENTTYPE="ScreenSharingEvent"
| eval lengthofpayload=len(PAYLOAD)
| bucket lengthofpayload bins=10
| top lengthofpayload 

View solution in original post

Paolo_Prigione
Builder

You can use | top: it will give you the distribution # and % of results grouped by the value of a field.

sourcetype="dbmon:kv" 
| search EVENTTYPE="ScreenSharingEvent"
| eval lengthofpayload=len(PAYLOAD)
| bucket lengthofpayload bins=10
| top lengthofpayload 

Paolo_Prigione
Builder

| top showcount=false lengthofpayload

cosullivan66
Explorer

I'd like it to display % without #. Do you know how to delete the # column?

0 Karma

cosullivan66
Explorer

Ah this is so obvious now. Thanks so much!

0 Karma
Get Updates on the Splunk Community!

Observability | Use Synthetic Monitoring for Website Metadata Verification

If you are on Splunk Observability Cloud, you may already have Synthetic Monitoringin your observability ...

More Ways To Control Your Costs With Archived Metrics | Register for Tech Talk

Tuesday, May 14, 2024  |  11AM PT / 2PM ET Register to Attend Join us for this Tech Talk and learn how to ...

.conf24 | Personalize your .conf experience with Learning Paths!

Personalize your .conf24 Experience Learning paths allow you to level up your skill sets and dive deeper ...