Splunk Search

Calculate percent

C37996518
Explorer

index=Myindex sourcetype=mine mysearch    | eval Result=if(Apple="1","Bad","Good")
| stats count by Result

 

The search above gives me the correct count of events where Apple="1"

eg

Result                                                 Count

Bad                                                       5 

Good                                                  12392

 

How do I express the stats as a  single value in percentage ie  Bad/Good?

How do I alert  if the percentage  > .02%

Labels (1)
0 Karma
1 Solution

bowesmana
SplunkTrust
SplunkTrust

NB: and on a slight technical note to ITWhispers comments, if you're looking for bad as a % of total rather than of goodNB, then

 

| eval percent=100*Bad/(Bad+Good)

 

View solution in original post

C37996518
Explorer

@C37996518 wrote:

index=Myindex sourcetype=mine mysearch    | eval Result=if(Apple="1","Bad","Good")
| stats count by Result

 

The search above gives me the correct count of events where Apple="1"

eg

Result                                                 Count

Bad                                                       5 

Good                                                  12392

 

How do I express the stats as a  single value in percentage ie  Bad/Good?

How do I alert  if the percentage  > .02%


Thanks to both. Perfect!!

0 Karma

bowesmana
SplunkTrust
SplunkTrust

NB: and on a slight technical note to ITWhispers comments, if you're looking for bad as a % of total rather than of goodNB, then

 

| eval percent=100*Bad/(Bad+Good)

 

ITWhisperer
SplunkTrust
SplunkTrust
index=Myindex sourcetype=mine mysearch
| eval Bad=if(Apple="1",1,0)
| eval Good=if(Apple="1",0,1)
| stats sum(Bad) as Bad sum(Good) as Good
| eval percent=100*Bad/Good
| where percent>0.02

The last line is for the alert so that you only get results when the percentage is greater than 0.02

0 Karma
Get Updates on the Splunk Community!

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer Certification at ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...

Share Your Ideas & Meet the Lantern team at .Conf! Plus All of This Month’s New ...

Splunk Lantern is Splunk’s customer success center that provides advice from Splunk experts on valuable data ...