Splunk Search

Generate percentage and filter based on it from events with count in them (so I cannot use "top")?

arun_kant_sharm
Path Finder

Hi Experts,
I need to create a alert , if HTTPCode_Target_5XX_Count is greater than 5% of Total count then i need to send alert mail.
My SPL

sourcetype=aws:cloudwatch
| spath path=Average
| spath path=Maximum
| spath path=Minimum 
| spath path=SampleCount 
| spath path=Sum 
| spath path=Unit
| spath path=account_id
| spath path=metric_dimensions 
| spath path=metric_name
| spath path=period
| spath path=timestampe 
| search metric_dimensions="*app/adj-tok-nonprod-web-in-alb/*" AND metric_name=HTTPCode_Target*  | stats sum(SampleCount)  by metric_name |rename sum(SampleCount)  as SampleCount |  addtotals row=f col=t labelfield=metric_name  SampleCount 

Output Format:

metric_name              SampleCount
HTTPCode_Target_2XX_Count       14684
HTTPCode_Target_3XX_Count        9551
HTTPCode_Target_4XX_Count         189
HTTPCode_Target_5XX_Count          44
Total                           24468

Suggest what i need to append in my SPL to get proper result

Tags (3)
0 Karma
1 Solution

woodcock
Esteemed Legend

Like this:

index="YouShouldAlwaySpecifyAnIndex" AND sourcetype="aws:cloudwatch"
| spath path=Average
| spath path=Maximum
| spath path=Minimum 
| spath path=SampleCount 
| spath path=Sum 
| spath path=Unit
| spath path=account_id
| spath path=metric_dimensions 
| spath path=metric_name
| spath path=period
| spath path=timestampe 
| search metric_dimensions="*app/adj-tok-nonprod-web-in-alb/*" AND metric_name=HTTPCode_Target* 
| stats sum(SampleCount) AS SampleCount BY metric_name
| eventstats sum(SampleCount) AS GrandTotal
| eval pct = 100 * (SampleCount / GrandTotal)
| where pct > 5

View solution in original post

0 Karma

woodcock
Esteemed Legend

Like this:

index="YouShouldAlwaySpecifyAnIndex" AND sourcetype="aws:cloudwatch"
| spath path=Average
| spath path=Maximum
| spath path=Minimum 
| spath path=SampleCount 
| spath path=Sum 
| spath path=Unit
| spath path=account_id
| spath path=metric_dimensions 
| spath path=metric_name
| spath path=period
| spath path=timestampe 
| search metric_dimensions="*app/adj-tok-nonprod-web-in-alb/*" AND metric_name=HTTPCode_Target* 
| stats sum(SampleCount) AS SampleCount BY metric_name
| eventstats sum(SampleCount) AS GrandTotal
| eval pct = 100 * (SampleCount / GrandTotal)
| where pct > 5
0 Karma

woodcock
Esteemed Legend

P.S. Your subject stinks. Try harder next time.

0 Karma

woodcock
Esteemed Legend

I fixed it for you.

0 Karma

renjith_nair
Legend

@arun_kant_sharma ,

Try

sourcetype=aws:cloudwatch | spath path=Average
| spath path=Maximum
| spath path=Minimum
| spath path=SampleCount
| spath path=Sum
| spath path=Unit
| spath path=account_id
| spath path=metric_dimensions
| spath path=metric_name
| spath path=period
| spath path=timestampe
| search metric_dimensions="app/adj-tok-nonprod-web-in-alb/" AND metric_name=HTTPCode_Target* 
| stats sum(SampleCount) as total,sum(eval(if(metric_name=="HTTPCode_Target_5XX_Count",SampleCount,0))) as 5xx
| eval perc=round((5xx/total)*100,2)
| where perc > 5
---
What goes around comes around. If it helps, hit it with Karma 🙂
0 Karma
Get Updates on the Splunk Community!

Introducing the Splunk Community Dashboard Challenge!

Welcome to Splunk Community Dashboard Challenge! This is your chance to showcase your skills in creating ...

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