Splunk Search

Stats by hour

motobeats
Path Finder

I would like to create a table of count metrics based on hour of the day. So average hits at 1AM, 2AM, etc.

stats min by date_hour, avg by date_hour, max by date_hour

I can not figure out why this does not work.

Here is the matrix I am trying to return. Assume 30 days of log data so 30 samples per each date_hour

date_hour count min ...
1 (total for 1AM hour) (min for 1AM hour; count for day with lowest hits at 1AM)
2 (total for 2AM hour) (min for 2AM hour; count for day with lowest hits at 2AM)
3
4
...

Would like to do max and percentiles as well to help understand typical and atypical hits at different times of day.

Tags (2)
0 Karma
1 Solution

motobeats
Path Finder

This gave me what I was looking for:

bucket _time span=1h|stats count by _time date_hour|stats min(count), p25(count), p50(count), p75(count), max(count) by date_hour

View solution in original post

mosaicjwb
New Member

This was my solution to an hourly count issue. I've sanitized it. But I created this for a dashboard which watches inbound firewall traffic by country ($token_value$) per hour. Both Allowed and Dropped traffic.

index=firewall sourcetype=traffic action=* location=$token_value$ earliest=-1d@d latest=@d

| eval date_hour=strftime(_time, "%H")

| stats count as "Hourly Count" by action, location, date_hour

| sort date_hour by ascending

 

 

0 Karma

MTravisVolker
Explorer

For a very similar problem I had I solved it this way:

index="my_Index" host="my:host" sourcetype="my:sourcetype"
| timechart count span=60m

motobeats
Path Finder

This gave me what I was looking for:

bucket _time span=1h|stats count by _time date_hour|stats min(count), p25(count), p50(count), p75(count), max(count) by date_hour

the_wolverine
Champion
  • | timechart span=1h avg(count) ?

Ayn
Legend

What's wrong about this answer?

0 Karma

jwalzerpitt
Influencer

When I run the | timechart span=1h avg(count) query, no stats are being returned and I can't figure out why

0 Karma

somesoni2
Revered Legend

You would need to add some base search something like this (runanywhere query)

index=_internal sourcetype=splunkd | timechart span=1h avg(count)

jwalzerpitt
Influencer

Thx for the reply and info. Added various sourcetypes in different queries and sometimes I see no results for the avg count, yet I see events.

For one particular query I see 373k events, yet nothing is returned in the statistics tab even though the the days are being listed for the following query: index=myindex sourcetype=myindex | timechart span=1d avg(count)

Thx

0 Karma

MTravisVolker
Explorer

What is it averaging? Count. Why? Why not take count without averaging it?

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Where Innovation Takes Flight: The Splunk4Aviation Flight Sim Lands at .conf26

If you hear someone at .conf26 shouting "gear down, GEAR DOWN" across the show floor, you have found us.  The ...

Turn Cisco Telemetry Into Action with Cisco Data Fabric, powered by the Splunk ...

The surge in machine data is already hitting enterprise budgets, and the agentic era will only intensify it. ...

Persistent Queue at TcpOut — One of Splunk's Most Practical Features

Splunk introduced persistent queueing at the tcpout layer as one of the most practical resilience features in ...