Splunk Search

How do I write a search to calculate the percentage of each status field in my sample data?

SrinivasaC
Path Finder

Working on some client data, sample data format looks like:

Item    status
--------------------------
AAA  success
BBB  fail
CCC     pending
DDD  fail
EEE  success
FFF  success
GGG  pending
HHH  success
III  fail
JJJ  pending
KKK  success

Now I want to calculate the percentage of each status field.
I want the output like below:

status     count    percentage
-----------------------------------
Success    50      50%
fail       40      40%
pending    10      10%

plz help me with search.

Thanks in advance..

0 Karma
1 Solution

javiergn
Super Champion

It should be something like:

yoursearch | top status

View solution in original post

fdi01
Motivator

try like this:

...| stats count   by status| eventstats sum(count) as total| eval percent = round((count/total)*100) . " %"|sort -percent | fields - total

or

...| top status | eval percent=percent."%"

javiergn
Super Champion

It should be something like:

yoursearch | top status

sdaniels
Splunk Employee
Splunk Employee
0 Karma
Get Updates on the Splunk Community!

Detecting Remote Code Executions With the Splunk Threat Research Team

REGISTER NOWRemote code execution (RCE) vulnerabilities pose a significant risk to organizations. If ...

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