Splunk Search

Stats StatusCode error Rate

dpdwibedy
Explorer

Hi There,

Need help to find the  status code error rate  where  status code is >400.

I have below Query to time chart the error rate  , which works fine...

index=apache_core  userAgent!="nginx/*" source="*access.log*"  requestURI!="/web/app*" NOT (requestURI="/api/xyz/*"  OR requestURI="/api/yyy/*"  AND statusCode=404) earliest=-30m latest=now | timechart span=5m limit=0 eval((count(eval(statusCode>=400)) / count()) * 100) as ErrorRate
 
But , to  create an alert , I don't want the time chart  , just the  error rate  in last 30 mins.
 
the stats count with the eval statement doesn't work.
 
Thanks,
DD

 

Labels (1)
0 Karma
1 Solution

richgalloway
SplunkTrust
SplunkTrust

Add | fields ErrorRate to the end of the query.

---
If this reply helps you, Karma would be appreciated.

View solution in original post

0 Karma

richgalloway
SplunkTrust
SplunkTrust

For an alert, replace timechart with stats and eval.

index=apache_core  userAgent!="nginx/*" source="*access.log*"  requestURI!="/web/app*" NOT (requestURI="/api/xyz/*"  OR requestURI="/api/yyy/*"  AND statusCode=404) earliest=-30m latest=now 
| stats count(eval(statusCode>=400)) as errors, count as total
| eval ErrorRate = errors * 100 / total

 

---
If this reply helps you, Karma would be appreciated.
0 Karma

dpdwibedy
Explorer

@richgalloway  ,

Thanks! for  the reply . It works , but I want only "ErrorRate" to be displayed.

Right now , it displays like this.

errors	total	ErrorRate
19056	679878	2.8028558064829276

 

0 Karma

richgalloway
SplunkTrust
SplunkTrust

Add | fields ErrorRate to the end of the query.

---
If this reply helps you, Karma would be appreciated.
0 Karma

dpdwibedy
Explorer

Thanks @richgalloway . Appreciated.

Regards,

DD

0 Karma
Get Updates on the Splunk Community!

Splunk Mobile: Your Brand-New Home Screen

Meet Your New Mobile Hub  Hello Splunk Community!  Staying connected to your data—no matter where you are—is ...

Introducing Value Insights (Beta): Understand the Business Impact your organization ...

Real progress on your strategic priorities starts with knowing the business outcomes your teams are delivering ...

Enterprise Security (ES) Essentials 8.3 is Now GA — Smarter Detections, Faster ...

As of today, Enterprise Security (ES) Essentials 8.3 is now generally available, helping SOC teams simplify ...