Splunk Search

Get percentage of matchin to all events

Simon
Contributor

Hi all

I think this will be easy for you guys but I have no clue at the moment 😉

My search is very simple:

sourcetype=access_combined | regex uri="\.(gif|jpg|jpeg|png)$"

With adding

| stats count(_raw)

I get the number of events matching my regex.
How can I get the percentage of events matching my regex to the total number of events of the base search

sourcetype=access_combined

?

Thanks,
Simon

0 Karma
1 Solution

ziegfried
Influencer
sourcetype=access_combined | eval request_type=if(match(uri, "\.(gif|jpe?g|png)"),"image", "other") | stats count(eval(request_type="image")) as image_requests count as total | eval img_pct=image_requests/total*100

or simplified:

sourcetype=access_combined | stats count(eval(match(uri, "\.(gif|jpe?g|png)"))) as image_requests count as total | eval img_pct=image_requests/total*100

View solution in original post

ziegfried
Influencer
sourcetype=access_combined | eval request_type=if(match(uri, "\.(gif|jpe?g|png)"),"image", "other") | stats count(eval(request_type="image")) as image_requests count as total | eval img_pct=image_requests/total*100

or simplified:

sourcetype=access_combined | stats count(eval(match(uri, "\.(gif|jpe?g|png)"))) as image_requests count as total | eval img_pct=image_requests/total*100

Simon
Contributor

Absolutely what I searched for - thanks a lot!

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