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!

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer at Splunk .conf24 ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...

Share Your Ideas & Meet the Lantern team at .Conf! Plus All of This Month’s New ...

Splunk Lantern is Splunk’s customer success center that provides advice from Splunk experts on valuable data ...