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
Get Updates on the Splunk Community!

What's new in Splunk Cloud Platform 9.1.2312?

Hi Splunky people! We are excited to share the newest updates in Splunk Cloud Platform 9.1.2312! Analysts can ...

What’s New in Splunk Security Essentials 3.8.0?

Splunk Security Essentials (SSE) is an app that can amplify the power of your existing Splunk Cloud Platform, ...

Let’s Get You Certified – Vegas-Style at .conf24

Are you ready to level up your Splunk game? Then, let’s get you certified live at .conf24 – our annual user ...