Splunk Search

Timechart average

schufi01
Path Finder

Hi, 

I am pretty new to splunk and need help with a timechart.

I have a timechart, that shows the count of packagelosses >50 per day. Now I want to add an average line to the chart, that matches to the chosen space of time.

 

 

index= ... |eval Amount=lost_packages |where 2500 > Amount and Amount > 50
|timechart span=24h count(Amount) aligntime=@d

 

 

Can somebody tell me how i can calculate the average of Amount in the chosen space of time and how I can add the average to the timechart?  

Labels (1)
0 Karma
1 Solution

bowesmana
SplunkTrust
SplunkTrust

@schufi01 

To work out the number of days in your search window, this should do the trick

| addinfo
| eval days=round((info_max_time-info_min_time)/86400)
| eval averagePerDay=TotalCount/days
| fields - days info_*

 

View solution in original post

0 Karma

bowesmana
SplunkTrust
SplunkTrust

Add the second aggregation to the timechart command

 

index= ... |eval Amount=lost_packages |where 2500 > Amount and Amount > 50
|timechart span=24h count(Amount) avg(Amount) aligntime=@d

 

You will probably want to put the average on a separate Y axis to the count - so format the timechart as needed.

 

0 Karma

schufi01
Path Finder

I already tried this before. avg(Amount) gives different averages for every single day. My goal is to get one single average for the whole time span. E.g. last month, I had an average of 50 per day (It should just be a straight line).

0 Karma

bowesmana
SplunkTrust
SplunkTrust

@schufi01 

Ah, I misunderstood. Then do this

index= ... 
| eval Amount=lost_packages
| where 2500 > Amount and Amount > 50
| timechart span=24h count(Amount) as Count sum(Amount) as Total aligntime=@d
| eventstats sum(Count) as TotalCount sum(Total) as TotalAmount
| eval Average=TotalAmount/TotalCount
| fields - TotalCount TotalAmount

This just calculates the TotalCount and TotalAmount for the period and calculates the average

 

schufi01
Path Finder

It works now, thank you. However, I would like to change something to get better information. At the Moment I can see how many packages have been lost on average. Is it possible to show the average number of events with Packagelosses >50 in the selected time space? 

For example: 

 

Monday: 3 Losses (with 51,53,55 Packages that have been lost)

Tuesday: 2 Losses(with 61,63,Packages that have been lost)

Wednesday: 4 Losses(with 51,53,55,57 Packages that have been lost)

 

At the moment the average gives me 55.444

Is it possible, that the average gives me the average number of events per day, which would be 3? 

-->(3+2+4)/3

 

Tags (1)
0 Karma

schufi01
Path Finder

I guess the last eval line must be changed.

 

It should be something like |eval Average= TotalCount/Timespan. But how can I get this working?

@bowesmana 

0 Karma

bowesmana
SplunkTrust
SplunkTrust

@schufi01 

To work out the number of days in your search window, this should do the trick

| addinfo
| eval days=round((info_max_time-info_min_time)/86400)
| eval averagePerDay=TotalCount/days
| fields - days info_*

 

0 Karma

schufi01
Path Finder

Thank you! It works perfectly 😄

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!

Catalog Is Now Generally Available on Splunk Cloud Platform

A Unified View of Your Data  Security logs, application events, business data, and historical telemetry often ...

Your Path to AgenticOps: AI Experiences for Every Splunk Practitioner

Your Path to AgenticOps: AI Experiences for Every Splunk Practitioner   Watch on demand us for a demo-driven ...

The Data Connection - October 2026

We all have data. Lots of it. But that’s not the problem – it’s understanding what we should we do with it, ...