Using Splunk Streamstats to Calculate Alert Volume (2024)

By Josh Neubecker|Published On: November 10th, 2020|

Dynamic thresholding using standard deviation is a common method we used to detect anomalies in Splunk correlation searches. However, one of the pitfalls with this method is the difficulty in tuning these searches. This is where the wonderful streamstats command comes to the rescue.

This Splunk tutorial will cover why tuning standard deviation searches is different from using a static threshold, how to use streamstats, and how we can use streamstats to get immediate feedback on alert volume.

Tuning Using Streamstats

1. Understanding the problem

With a static threshold search that runs over 60 minutes, calculating alert volume over 30 days is as simple as running the count by 60 minutes over 30 days. This is different with a dynamic threshold.

Typically, a standard deviation search will calculate a threshold based on the last 7 to 30 days to compare against the last hour of data. Running the same search to see approximately how many notables would be generated in 30 days will calculate the threshold differently than when it runs as a correlation search.

When running a correlation search, the threshold is based on historical data. Using the same search to calculate the alert volume for the whole 30 days the threshold will be based on historical, current, and future data for any given hour but the last.

This is where we can use streamstats to calculate the threshold based on the last 30 days for any given hour.

Still confusing? Let’s take a look at a few examples.

2. What does streamstats even do?

To understand how we can do this, we need to understand how streamstats works. In my experience, streamstats is the most confusing of the stats commands. I find it’s easier to show than explain. Let’s start with a basic example using data from the makeresults command and work our way up.

Example 1: streamstats without options

Copy to Clipboard

Using Splunk Streamstats to Calculate Alert Volume (1)

The streamstats command will run statistics as events come in. In this case, counting how many times each color appears and generating an incremental count for our testing.

Example 2: streamstats with a window

Copy to Clipboard

Using Splunk Streamstats to Calculate Alert Volume (2)

With a window, streamstats will calculate statistics based on the number of events specified. In this case, streamstats looks at the current event and the previous. This causes the count by color to be 1 for each event because the previous event is always a different color. A common expectation with streamstats is that the window by default would be separate for each color. To do this, see our next example.

Example 3: streamstats with a windows and global=false

Copy to Clipboard

Using Splunk Streamstats to Calculate Alert Volume (3)

When global=false a separate window is kept for each color. This is the behavior we need for testing alert volume.

3. How can we use streamstats to help us?

Let’s take a simplified standard deviation search for finding an anomalous amount of failed logins.

Copy to Clipboard

Running this search over 7 days will count the number of failed authentications by src for each hour. Then it will calculate an upper bound based on the average and standard deviation of the counts for each hour by src. Finally, it will only show events where the failure count for the last hour was above the upper bound.

Removing the time constraint would show anomalies for the entire time frame, but the results will be different then when the search runs every hour. To get a more accurate representation, we need to use streamstats to look at the previous 7 days for each individual hour.

Copy to Clipboard

Changing eventstats to streamstats and specifying a window of 168 (168 hours in a week since our time span is 1 hour) with global=false will calculate the threshold for each event based on the last 7 days of counts. Constraining the time to the past 7 days in the where clause and running the search over 14 days will ensure there’s a full history for each event. To exclude the current event from the threshold simply set current=false if desired.

Bonus Example: Creating an alert volume test for ESCU SMB Traffic Spike

Below shows the original search–taken from Splunk’s Enterprise Security Content Update app:

Copy to Clipboard

  • Change stats to streamstats window=168 (for 7 days of history) and global=false
  • In this search, the calculations are done on (maxtime, “-70m@m”) so set current=false
  • Remove `max(eval(if(_time >= relative_time(maxtime, “-70m@m”), count, null))) as count`. We want to keep the original count from each event
  • Add the time constraint `_time>relative_time(now(), “-7d”)` and run over 14 days

Putting all that together, here is the search:

Copy to Clipboard

Using this, we can change the threshold, filter noise, and immediately see what our changes will do.

Conclusion

Using this method, you can immediately see how many alerts would be generated from a standard deviation search. This allows for instant feedback to tune out sources, users, or failure reasons. Hopefully, this post helped you have a better understanding of how you can apply streamstats when creating and tuning alerts as well as other applications.

Share with your network!

About Hurricane Labs

Hurricane Labs is a dynamic Managed Services Provider that unlocks the potential of Splunk and security for diverse enterprises across the United States. With a dedicated, Splunk-focused team and an emphasis on humanity and collaboration, we provide the skills, resources, and results to help make our customers’ lives easier.

For more information, visitwww.hurricanelabs.comand follow us on Twitter@hurricanelabs.

Using Splunk Streamstats to Calculate Alert Volume (4)

Using Splunk Streamstats to Calculate Alert Volume (2024)

FAQs

What is the use of Streamstats in Splunk? ›

The SPL2 streamstats command adds a cumulative statistical value to each search result as each result is processed. For example, you can calculate the running total for a particular field, or compare a value in a search result with a the cumulative value, such as a running average.

What is the alert limit for Splunk? ›

How many recipients can get an email alert through Splunk? What is the limit? In default it is 100(Number of recipients). maximum we can increase till 10000.

What is the index volume limit for Splunk? ›

" If you go over 500MB/day more than 3 times in a 30 day period, Splunk will continue to index your data, but search will be disabled until you are back down to 3 or fewer times in the 30 day period. "

How do I monitor Splunk alerts? ›

In the CMC navigation bar, select Alerts > Triggered Alerts. The page displays the name of any triggered alert and a timestamp of when it was triggered.

What is StreamStats used for? ›

StreamStats provides estimates of various streamflow statistics for user-selected sites by solving equations that were developed through a process known as regionalization.

What is the difference between stats and StreamStats? ›

Shortly streamstats calculate over sliding window and eventstats over all values. Stats calculate aggregate statistics over the dataset, similar to SQL aggregation. If called without a by clause, one row is produced, which represents the aggregation over the entire incoming result set.

How do you calculate alert limit? ›

Alert Levels Calculation. 3) average + 3 SD. To calculate standard deviation (SD) (population), first calculate the difference between each rate and the average, and we square each value (x- µ)2. Next, to obtain the SD, calculate the average of these values and obtain the square root of that value.

What are the two valid types of alerts in Splunk? ›

There are two alert types, scheduled and real-time.

What is the lifespan of Splunk alerts? ›

By default, each triggered alert record on the Triggered Alerts page expires after 24 hours. You can update the lifespans for triggered alert records on a per-alert basis.

What is indexing volume? ›

A volume index or quantity index is a numerical time series measure designed to help compare how the production of some class of goods and/or services, taken as a whole, differs between time periods or geographical locations. Compare price index.

What is the maximum size of entire index in Splunk? ›

As you say there is a max size of the entire index(and all indexes) in general that can go up to 500 GB.

What is the size limit of Splunk? ›

So you can ingest 500MB per day and don't remove it until you've hit your 20TB storage space limit and it will not generate a licensing warning. Ingesting data is one thing, and that's how Splunk is licensed. And data storage is another thing. You're not limited in any way on your storage size.

What is the difference between report and alert in Splunk? ›

A report can be used in a dashboard. It does have to trigger anything. An alert is based on a scheduled saved search that whenever certain conditions are overcome, generates one or more actions to be executed.

How to investigate an alert in Splunk? ›

You can find your alerts in the Alerts & Detectors section in the left navigation pane of Splunk Observability Cloud. In this example, an alert rule is configured in Splunk Observability Cloud to trigger when the online web application error rate over the last 5 minutes is above 30% across at least 10 requests.

How do I triage alerts in Splunk? ›

Triage incidents using incident review in Splunk Mission Control
  1. Review incidents.
  2. Sort incidents in the incident review table.
  3. Customize the incident review table.
  4. Perform bulk actions on incidents. Edit multiple incidents. ...
  5. Apply filters and save filtered views for incidents. Manage filtered views.
  6. Triage incidents.
Oct 18, 2023

How does Splunk stream work? ›

Stream collects network data and forwards it to Splunk Enterprise or Splunk Cloud. Stream does not analyze logs. If you can use a UF to send logs to Splunk then you don't need Stream.

What are streaming commands in Splunk? ›

A streaming command applies a transformation to each event returned by a search. For example, the rex command is streaming because it extracts and adds fields to events at search time.

What is the use of Eventstats in Splunk? ›

The SPL2 eventstats command generates summary statistics from fields in your events and saves those statistics into a new field. The eventstats command places the generated statistics in new field that is added to the original raw events.

What is the use of Splunk monitoring tool? ›

Splunk's software can be used to examine, monitor, and search for machine-generated big data through a browser-like interface. It makes searching for a particular piece of data quick and easy, and more importantly, does not require a database to store data as it uses indexes for storage.

References

Top Articles
Latest Posts
Article information

Author: Errol Quitzon

Last Updated:

Views: 5557

Rating: 4.9 / 5 (79 voted)

Reviews: 86% of readers found this page helpful

Author information

Name: Errol Quitzon

Birthday: 1993-04-02

Address: 70604 Haley Lane, Port Weldonside, TN 99233-0942

Phone: +9665282866296

Job: Product Retail Agent

Hobby: Computer programming, Horseback riding, Hooping, Dance, Ice skating, Backpacking, Rafting

Introduction: My name is Errol Quitzon, I am a fair, cute, fancy, clean, attractive, sparkling, kind person who loves writing and wants to share my knowledge and understanding with you.