Splunk Search

How to split a time period into hourly intervals?

jtest372
Explorer

 

 

 

index="dummy" url="https://www.dummy.com" status="200 OK"
| stats count by id
| where count > 10

 

 


If I apply this above query for 1 day, I would get this result, for example

 

 

id    count
ABC    50
XYZ    60

 

 

This would mean ABC called `https://www.dummy.com` 50 times in 1 day, and XYZ called that 60 times.

Now I want to check this for 1 day but with every two hours interval

Suppose, ABC called that request 25 times at 12:00 AM, and then calls it 25 times at 3:AM,
and XYZ called all the 60 requests between 12 AM and 2 AM

I want the output to look like this (time format doesn't matter)

 

 

id    count   time
XYZ    60   12:00 AM
ABC    25   12:00 AM
ABC    25   2:00 AM

 

 

Also, If I modify the query like this,  count > 30, instead of count > 10, then it should only show the XYZ field, since ABC has 25 counts for both of them.

 How do I modify my query? 


Labels (3)
Tags (1)
0 Karma
1 Solution

SanjayReddy
SplunkTrust
SplunkTrust

Hi @jtest372 

Updated Answer

How about this ?

| bin  span=2h  _time
| stats count by id _time


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

View solution in original post

SanjayReddy
SplunkTrust
SplunkTrust

Hi @jtest372 

can you please try this

| timehcart span=2h count by id

 

 

jtest372
Explorer

Thanks, Sanjay!

I tried this, but it gives me all ids as column headers like this

                        ABC       DEF       XYZ

12:00 AM               25         60         23

2:00 AM                25          0         12

4:00 AM                0          15         20

 

0 Karma

SanjayReddy
SplunkTrust
SplunkTrust

Hi @jtest372 

Updated Answer

How about this ?

| bin  span=2h  _time
| stats count by id _time


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

jtest372
Explorer

Thanks! This looks almost close, but 

bin _time span=1h is invalid

If I remove this line, it gives me the format I want but the span is not working.

0 Karma

SanjayReddy
SplunkTrust
SplunkTrust

Hi @jtest372 

may be time is not present in your data 

can you please replace _time with field which contains  contains time value

| bin <field which contains time > span=1h 

jtest372
Explorer

| bin span=2h _time
| stats count by id _time

this worked for me! I just had to place _time at the end

0 Karma

jtest372
Explorer

Placing _time at the end worked, you can edit your comment, I can accept it as the solution then! Thanks

 

0 Karma

SanjayReddy
SplunkTrust
SplunkTrust

Done Updated the Answer 

Thanks for the feedback

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