Skip to content
SPL // Splunk

Using the eventstats Command

KGI Avatar
 

Written by: Carlos Diez | Last Updated:

 
December 19, 2025
 
Search Command Of The Week: eventstats
 
 

Originally Published:

 
December 19, 2025

Introduction to Splunk SPL & the eventstats Command

Splunk Search Processing Language (SPL) is the foundation for searching, transforming, and analyzing machine data. Through SPL, raw events are shaped into structured insights that can support operations, security, and business decisions. 

Among the many transforming commands, eventstats holds a unique position. It is often selected when summary statistics must be calculated without collapsing individual events. 

Practically, eventstats is used when context matters. For example, a user may need to compare each event to an overall average or total. In those situations, per-event visibility must be preserved. Therefore, eventstats become essential when enrichment is preferred over aggregation. Instead of reducing results, it augments them. 

Understanding the eventstats Command

The eventstats command calculates statistics across a dataset and appends them to each event.As a result, original events remain intact.In contrast, stats reduces events into summary rows.That distinction is central to understanding proper usage.

It is important to note that eventstats runs through each event. This can greatly increase search time if not done correctly.

Additionally, eventstats support grouping with by clauses. This allows contextual metrics to be attached at different levels. Because results are enriched rather than replaced, downstream commands remain flexible. Filters, visualizations, and evaluations can still be applied per event. 

Benefits of the eventstats Command

The value of eventstats becomes clear in repeated workflows. 

  • Preserves event granularity 
    Individual events are retained, which supports detailed analysis and filtering. 
  • Adds contextual metrics 
    Totals, averages, or counts can be compared directly against each event. 
  • Improves analytic flexibility 
    Since events remain intact, additional SPL can be layered afterward. 

Basic Syntax

The syntax of eventstats closely mirrors that of stats. However, the output behavior is different. A basic structure is shown below: 

				
					... | eventstats <aggregation>(<field>) AS <new_field> [BY <grouping_field>]
				
			

Here, an aggregation function is applied. Then, the calculated value is written back into each event. Optionally, grouping can be applied. This enables scoped calculations rather than global ones. 

Usage Examples & Practical Applications

The following examples demonstrate practical use cases. Where possible, the Splunk Common Information Model (CIM) is used. 

Example #1: Compare Each Network Event to the Average Bytes Transferred

This use case helps identify unusually large network transfers. Each event is compared to an overall average. 

				
					| tstats sum(All_Traffic.bytes) AS bytes  
  FROM datamodel=Network_Traffic  
  BY _time, src, dest 
| eventstats avg(bytes) AS avg_bytes 
| eval bytes_vs_avg = bytes - avg_bytes
				
			

As shown, the average is attached to every event. Therefore, deviations can be calculated directly. 

Example #2: Add Total Authentication Attempts per User

This example supports user behavior analysis. Each authentication event is enriched with a per-user total. 

				
					| tstats count AS auth_count  
  FROM datamodel=Authentication  
  BY _time, user, action 
| eventstats sum(auth_count) AS total_user_auth BY user
				
			

Because events remain visible, failures and successes can be examined together. This is useful during investigations. 

Example #3: Identify Systems Contributing Most to Endpoint Activity

This scenario focuses on endpoint telemetry. Each event is tagged with the host’s overall activity count.

				
					| tstats count AS event_count  
  FROM datamodel=Endpoint  
  BY _time, host, signature 
| eventstats sum(event_count) AS total_host_events BY host
				
			

As a result, noisy systems can be identified quickly. Thresholds can then be applied downstream. 

Conclusion

The eventstats command plays a critical role in contextual analysis. It enriches events while preserving analytical flexibilityBy understanding when and how to use it, searches become more expressive. Comparisons, baselines, and relative metrics become easier to implement. 

Key takeaways include: 

  • eventstats enriches events without reducing them 
  • Contextual metrics can be added at global or grouped levels 
  • Complex comparisons are simplified within a single search 

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