Dashboards & Visualizations

Display results from "yesterday" when calculating standard deviation over the past 30 days

matthew_foos
Path Finder

Splunkers,

Here's the search string I'm using to calculate stdev over the last 30 days:

| tstats count where index=* by host, _time span=1d
| eventstats avg(count) as avg stdev(count) as stdev by host
| eval lowerBound=(avg-stdev*exact(2)), upperBound=(avg+stdev*exact(2))
| eval isOutlier=if(count < lowerBound OR count > upperBound, 1, 0)
| where isOutlier=1

My goal is to have this run as a report at 0600 everyday. I'm looking to display the results only from the previous day.

Any guidance would be fantastic.

Thanks

Tags (1)
0 Karma
1 Solution

elliotproebstel
Champion

This is a super easy fix, because your code is preserving the _time field:

| tstats count where index=* by host, _time span=1d
| eventstats avg(count) as avg stdev(count) as stdev by host
| eval lowerBound=(avg-stdev*exact(2)), upperBound=(avg+stdev*exact(2)) 
| eval isOutlier=if(count < lowerBound OR count > upperBound, 1, 0)
| where isOutlier=1 AND _time>=relative_time(now(), "-1d@d")

View solution in original post

0 Karma

elliotproebstel
Champion

This is a super easy fix, because your code is preserving the _time field:

| tstats count where index=* by host, _time span=1d
| eventstats avg(count) as avg stdev(count) as stdev by host
| eval lowerBound=(avg-stdev*exact(2)), upperBound=(avg+stdev*exact(2)) 
| eval isOutlier=if(count < lowerBound OR count > upperBound, 1, 0)
| where isOutlier=1 AND _time>=relative_time(now(), "-1d@d")
0 Karma

matthew_foos
Path Finder

elliotproebstel,

I'm still getting results for the current day as well as yesterday.

0 Karma

elliotproebstel
Champion

Ah, sure. Sorry. Here's a fix:

| tstats count where index=* by host, _time span=1d
| eventstats avg(count) as avg stdev(count) as stdev by host
| eval lowerBound=(avg-stdev*exact(2)), upperBound=(avg+stdev*exact(2)) 
| eval isOutlier=if(count < lowerBound OR count > upperBound, 1, 0)
| where isOutlier=1 AND _time>=relative_time(now(), "-1d@d") AND _time<relative_time(now(), "@d")
0 Karma

matthew_foos
Path Finder

Nailed it.

0 Karma
Get Updates on the Splunk Community!

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...

New in Observability Cloud - Explicit Bucket Histograms

Splunk introduces native support for histograms as a metric data type within Observability Cloud with Explicit ...