Skip to content
SPL // Splunk

Using the streamstats Command

KGI Avatar
 

Written by: Robert Caldwell | Last Updated:

 
December 23, 2025
 
Search Command Of The Week: streamstats
 
 

Originally Published:

 
December 23, 2025

Splunk Processing Language (SPL) is the foundation of Splunk’s data exploration capabilities. This powerful query language enables security analysts, system administrators, and data scientists to search, analyze, and visualize machine data at scale. 

The streamstats command is particularly valuable in SPL. Unlike traditional statistical functions, it calculates aggregations as data flows through the pipeline. This streaming approach means your results include running totals, moving averages, and cumulative calculations without requiring intermediate sorting steps. 

Practical applications for streamstats abound in real-world scenarios. Consider a system administrator monitoring memory usage trends across servers throughout a shift. The command enables them to calculate running averages of resource consumption. In cybersecurity, analysts use it to detect anomalies by computing cumulative failed login attempts. Furthermore, it proves essential when tracking performance metrics that depend on historical context within a data stream. 

Understanding the streamstats Command

The streamstats command operates on data in the order of events are processed. Rather than waiting to see all events, it evaluates each incoming event and produces intermediate results. This distinction from the stats command is fundamental to understanding when to use each tool. 

Consider how traditional statistics work. The stats command typically requires sorting and grouping all data before calculations begin. In contrast, streamstats processes events sequentially. Consequently, your pipeline maintains better performance on large datasets.  

Additionally, the command excels at detecting patterns that unfold over time. 

Streaming aggregations are particularly useful for monitoring scenarios. For example, you might track cumulative alerts throughout the day. Similarly, you could calculate running success rates for authentication attempts. Because the command maintains state across events, it naturally captures temporal patterns that batch processing misses. 

Why streamstats Matter for Your Daily Splunk Work

1. Running Totals & Cumulative Metrics 

Track running counts, sums, and percentages as data flows through your pipeline. This lets you maintain cumulative values across your event stream without losing individual event details. This eliminates the need to wait until your dataset is complete or rerun your search to get updates. 

2. Time-Series Analysis & Trend Detection

Real-time aggregations enable you to identify trends as they emerge. The command calculates moving averages, running totals, and cumulative metrics effortlessly. As a result, detecting anomalies becomes more intuitive. Additionally, security teams can spot unusual patterns before they escalate. 

3. Per-Field Performance Monitoring

Maintain separate calculations for different entities within your dataset in real time. You can track performance metrics per server, user, application, etc. without collapsing your data. This granular approach preserves context while providing observability on various levels. 

Basic Syntax for streamstats

The fundamental syntax structure is straightforward and consistent across use cases. Here is the core format: 

				
					... | streamstats [options] <function>(<field>) [AS new_field] [BY <fields>] 
				
			

Key components of this syntax include several important elements. The <function> represents your aggregation operation such as sumavgcount, or max. The first <field> indicates which data attribute you’re calculating on. Options modify behavior and include parameters like currentwindow, and allnum. The AS field will place your result in a new field with a new name you choose. The BY parameter splits calculations across specified fields. 

Usage Examples & Practical Applications

Example #1: Tracking Cumulative Failed Login Attempts

Use Case Description: Security teams need to detect brute-force attack patterns. This example calculates the cumulative count of failed authentication attempts per source IP address. When these values spike unexpectedly, automated alerts can trigger incident response procedures. 

				
					sourcetype=auth action=failure 
| streamstats count as failed_attempt_count by src_ip 
| where failed_attempt_count > 10 
| stats list(dest_user) as targeted_users, max(failed_attempt_count)  
  as max_attempts by src_ip 
				
			

This search queries your authentication data and filters for failed login events. Subsequently, the streamstats command counts failures per source IP in real time. Then, it identifies IPs with excessive failed attempts. Finally, it aggregates results showing targeted users and attempt counts. 

Example #2: Monitoring Moving Averages of Response Times

Use Case Description: Application performance teams monitor web server responsiveness continuously. This example calculates a rolling five-event average of HTTP response times. Sudden increases in latency indicate potential performance degradation requiring investigation. 

				
					index=web sourcetype=access_combined status=200 
| streamstats window=5 avg(response_time) as moving_avg_response  
  by host 
| stats avg(moving_avg_response) as overall_avg, max(response_time)  
  as peak_response by host 
				
			

Initially, the search filters for successful HTTP transactions across your web infrastructure. Then, streamstats calculate a five-event moving average of response times per host. Consequently, anomalous slowdowns become visually apparent. Finally, results summarize overall averages and peak response times by server. 

Example #3: Detecting Unusual Data Transmission Patterns

Use Case Description: Network security analysts monitor for data exfiltration attempts. This example tracks cumulative data transmission volume per user session. Abnormal transmission volumes compared to baseline behavior signal potential security incidents. 

				
					index=security sourcetype=network action=transmit 
| streamstats sum(bytes_out) as cumulative_bytes_transmitted,  
  count as event_count by user_id, session_id 
| where cumulative_bytes_transmitted > 1000000000 
| table user_id, session_id, cumulative_bytes_transmitted, event_count 
				
			

This search identifies network transmission events in your security logs. Subsequently, streamstats aggregates total bytes transmitted per user and session. Moreover, it counts related events within each session context. Then, results are filtered to show only suspicious transmission volumes exceeding one gigabyte thresholds. 

Conclusion

The streamstats command represents a powerful addition to your Splunk toolkit. It enables real-time aggregations that illuminate patterns within your data streams. Whether you’re tracking security metrics, monitoring performance baselines, or detecting anomalies, this command delivers results efficiently. 

As you’ve explored throughout this post, streamstats excels in specific scenarios where traditional batch aggregation falls short. Here are the key takeaways from our discussion: 

  • Streaming aggregations process events sequentiallyeliminating the need for full dataset buffering and dramatically improving performance on large data volumes 
  • Time-series analysis becomes intuitive through running totals, moving averages, and cumulative metrics that naturally capture temporal patterns and trends 
  • Complex calculations simplify significantly with streamstats, making your queries more readable, maintainable, and easier for colleagues to understand and modify 

To access more Splunk searches, check out Atlas Search Library, which is part of the Atlas Platform. Specifically, Atlas Search Library offers a curated list of optimized searches. These searches empower Splunk users without requiring SPL knowledge. Furthermore, you can create, customize, and maintain your own search library. By doing so, you ensure your users get the most from using Splunk.

Helpful? Don't forget to share this post!
LinkedIn
Reddit
Email
Facebook