Splunk Search

Count for multiple timeframes in a single query

ipicbc
Explorer

I am looking for a table where each row has the count of a value, in this case errors for each host. I need 2 value columns, 1 for no. errors in the last day, the other for errors in the last hour. Maybe a 3rd with errors in the last 10 minutes. Is there a way that I can have a single query which delivers the output from multiple count statements in a way that I can use them to populate a table?

Thanks

Tags (2)
0 Karma
1 Solution

woodcock
Esteemed Legend

Like this:

... | eval age = now() - _time | stats count(eval(age<86400)) AS errors_last_24_hours count(eval(age<3600)) AS errors_last_hour count(eval(age<600)) AS errors_last_10_minutes BY host

View solution in original post

0 Karma

woodcock
Esteemed Legend

Like this:

... | eval age = now() - _time | stats count(eval(age<86400)) AS errors_last_24_hours count(eval(age<3600)) AS errors_last_hour count(eval(age<600)) AS errors_last_10_minutes BY host
0 Karma

Sab
New Member

How to search for today's timeframe from the below,

eval age = now() - _time | stats count(eval(age<86400)) AS errors_last_24_hours count(eval(age<3600)) AS errors_last_hour count(eval(age<600)) AS errors_last_10_minutes BY host

Tags (1)
0 Karma

ipicbc
Explorer

This is a thing of beauty, for which I am extremely grateful and from which I have learned a lot!!!

Many thanks

0 Karma

rjthibod
Champion

Try this. You will need to add your base search to it, and you will need to change fields if your base search returns more events than only the error ones you are interested in.

You could do this with eventstats, but that is probably more efficient since you are going over the data set multiple times.

<BASE_SEARCH> earliest=-1d 
| eval marker = if(_time >= relative_time(now(), "-10min"), "ten", if(_time >= relative_time(now(), "-1h"), "hour", "day")) 
| chart count over host by marker 
| fillnull value=0 day hour ten 
| eval day = day + ten + hour 
| eval hour = hour + ten
| table host day hour ten
0 Karma
Get Updates on the Splunk Community!

.conf25 Community Recap

Hello Splunkers, And just like that, .conf25 is in the books! What an incredible few days — full of learning, ...

Splunk App Developers | .conf25 Recap & What’s Next

If you stopped by the Builder Bar at .conf25 this year, thank you! The retro tech beer garden vibes were ...

Congratulations to the 2025-2026 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...