Splunk Search

Average events per day

womblesplunk
New Member

Hi,

I would like to view the average number of events per day for a certain event code. It looks like I should be able to use:

"EventCode='123' | stats avg(count) by _date"

..but I don't have a data field in my log, only the _time field, which does have the data in it.

Can someone suggest a way to achieve this, perhaps by extracting a unique day field from the _time field somehow?

Many Thanks,

W

Tags (4)
0 Karma

martin_mueller
SplunkTrust
SplunkTrust

This sounds like you're actually just looking for a timechart with a span of one day:

EventCode=123 | timechart span=1d count

See http://docs.splunk.com/Documentation/Splunk/6.0.2/SearchReference/timechart for reference, it's quite versatile.

0 Karma

aholzer
Motivator

Try something like this:

EventCode=123 | eval date=strftime(_time,"%Y-%m-%d") | stats count by date | stats avg(count)

The strftime function allows you to extract time information from an epoch time field based on the time format. In this case it will extract only the year, month and day out of _time.

Stats count by date will get you the count of event for each day.

Stats avg(count) will get you the average of the count across all days.

Hope this helps

0 Karma

linu1988
Champion

Hello ,
if you think the eventcode can come like this or with some prefixed data then this will give you correct count. Average count per day won't be correct statistical data as you have the count by day one, average will be the same as count.

source=x "prefix_1234"|stats count(_raw) as Average_Count by date_mday

Thanks

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!

SOC4Kafka - New Kafka Connector Powered by OpenTelemetry

The new SOC4Kafka connector, built on OpenTelemetry, enables the collection of Kafka messages and forwards ...

Rounding off the Splunk Dashboard Contest

What does a contest-winning Splunk dashboard look like? In this case, it isn't in a browser tab at all. It ...

A Four Part Event Series: AI + Observability: AI Agents, LLMs, Apps, & Infrastructure

AI + Observability: AI Agents, LLMs, Apps, & Infrastructure The rapid evolution of artificial intelligence ...