Splunk Search

Count based on extracted field

athorat
Communicator

Hi

I have an event which has something like
/getproxy..... size:1
/getproxy..... size:10
/getproxy..... size:0

Want to calculate the total count when the size!=0 and count when size=0
using a rex in the search to extract size value

| rex "size:(?<Size>\d+)"

Any help appreciated

Tags (1)
0 Karma
1 Solution

fdi01
Motivator

try like :

 ...| rex "size:(?<Size>\d+)"|stats sum(eval(Size!=0)) as "total size!=0" sum(eval(Size=0)) as "total size=0"|...

or
for the number of time size!=0 and number of time size=0 try this:

 ...| rex "size:(?<Size>\d+)"|stats count(eval(Size!=0)) as "number of time size!=0" count(eval(Size=0)) as "number of time size=0"|...

View solution in original post

0 Karma

fdi01
Motivator

try like :

 ...| rex "size:(?<Size>\d+)"|stats sum(eval(Size!=0)) as "total size!=0" sum(eval(Size=0)) as "total size=0"|...

or
for the number of time size!=0 and number of time size=0 try this:

 ...| rex "size:(?<Size>\d+)"|stats count(eval(Size!=0)) as "number of time size!=0" count(eval(Size=0)) as "number of time size=0"|...
0 Karma

sideview
SplunkTrust
SplunkTrust

Of if you're more comfortable leaving eval tasks to the eval command, more or less the same idea would look like:
...| rex "size:(?\d+)"|eval type=if(Size=0,"zero","nonzero") | stats count by type

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