Splunk Search

How to achieve overlay graf with daily total, average per day for a week and standard deviation?

fatsug
Contributor

I'm trying to use tstats to calculate the daily total number of events for an index per day for one week. Then calculate an averade per day for the entire week, as well as upper and lower bounds +/- 1 standard deviation.

Feels like I can get each individual thing to work, either the bar chart with the daily count, OR the statistics. Though I want them all in a single figure.

This is my base search:

 

| tstats count as daily_events where index="index" earliest=-7d latest=-1d by _time span=1d 
# | timechart span=1d sum(daily_events) as daily_events

 

Which seems to work just fine by itself, with or without a following "timechart"

 

Now I figure I'd do something like this:

 

| stats sum(daily_events) as total_events stdev(daily_events) as std_dev 
| eval avg_events=round(total_events/7, 0)
| eval upper = total_events + std_dev 
| eval lower = total_events - std_dev

 

 Which by itself seems to work, though I now loose the results from the base search.

So how can I combine these things (can I combine?) into something close to what I want to achieve? I'm attaching a crude scetch for clarity.

It feels like I somehow need to add three columns just replicating the upper, lower and av_events values for every "daily_events" entry, or something. I just can figure it out. Any feedback is mych appreciated.

Labels (4)
0 Karma
1 Solution

yuanliu
SplunkTrust
SplunkTrust

You must be looking for eventstats (in lieu of stats)

| tstats count as daily_events where index="index" earliest=-7d latest=-1d by _time span=1d
| eventstats sum(daily_events) as total_events stdev(daily_events) as std_dev
| eval avg_events=round(total_events/7, 0)
| eval upper = total_events + std_dev 
| eval lower = total_events - std_dev

 

View solution in original post

Tags (1)

yuanliu
SplunkTrust
SplunkTrust

You must be looking for eventstats (in lieu of stats)

| tstats count as daily_events where index="index" earliest=-7d latest=-1d by _time span=1d
| eventstats sum(daily_events) as total_events stdev(daily_events) as std_dev
| eval avg_events=round(total_events/7, 0)
| eval upper = total_events + std_dev 
| eval lower = total_events - std_dev

 

Tags (1)

fatsug
Contributor

I was just about to post myself but glad you beat me to the punch, totally forgot about aventstats!

Thank you

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 Certification at ...

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 ...