Splunk Search

Categorize range of status values and calculate count

Viveklearner
Engager

We have range of statua from 200 to 600. Want to search logs and create a output in below sample for range as 200 to 400 as success, 401 to 500 as exception, 501 to 500 as failure:

Sucess - 100

Exceptio - 44

Failure - 3

I am able to get above format data but getting duplicate rows for each category e.g.

Success - 10

Success - 40

Sucess - 50

Exception - 20

Exception - 24

Failure - 1

Failure -2

Query 

Ns=abc app_name= xyz

| stats count by status
| eval status=if(status>=200 and status<400,"Success",status)
| eval status=if(status>=400 and status<500,"Exception",status)
| eval status=if(status>=500,"Failure",status)

Kindly help.

Labels (1)
0 Karma
1 Solution

gcusello
SplunkTrust
SplunkTrust

Hi @Viveklearner ,

please see my approach and adapt it to your data

<your_search>
| eval Status=case(status>=200 AND status<400,"Success",status>=400 AND status<500,"Exception",status>=500,"Failure",status)
| stats count BY Status

Ciao.

Giuseppe

View solution in original post

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @Viveklearner ,

please see my approach and adapt it to your data

<your_search>
| eval Status=case(status>=200 AND status<400,"Success",status>=400 AND status<500,"Exception",status>=500,"Failure",status)
| stats count BY Status

Ciao.

Giuseppe

0 Karma

Viveklearner
Engager

It worked.. thanks a lot

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @Viveklearner ,

good for you, see next time!

Ciao and happy splunking

Giuseppe

P.S.: Karma Points are appreciated 😉

0 Karma
Get Updates on the Splunk Community!

Index This | Why did the turkey cross the road?

November 2025 Edition  Hayyy Splunk Education Enthusiasts and the Eternally Curious!   We’re back with this ...

Enter the Agentic Era with Splunk AI Assistant for SPL 1.4

  &#x1f680; Your data just got a serious AI upgrade — are you ready? Say hello to the Agentic Era with the ...

Feel the Splunk Love: Real Stories from Real Customers

Hello Splunk Community,    What’s the best part of hearing how our customers use Splunk? Easy: the positive ...