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 | What is broken 80% of the time by February?

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

Unlock Faster Time-to-Value on Edge and Ingest Processor with New SPL2 Pipeline ...

Hello Splunk Community,   We're thrilled to share an exciting update that will help you manage your data more ...

Splunk MCP & Agentic AI: Machine Data Without Limits

Discover how the Splunk Model Context Protocol (MCP) Server can revolutionize the way your organization uses ...