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?
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_*
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.
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).
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
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
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?
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_*
Thank you! It works perfectly 😄