Splunk stats vs eventstats vs streamstats: Examples, Output Tables & Exam Guide
One-sentence rule: Use stats when you only want a summary table; use eventstats when you need to compare each individual event against a group total or average; use streamstats when you need a running total, counter, or sliding window in event order.
At-a-glance comparison
| Feature | stats | eventstats | streamstats |
|---|---|---|---|
| Command type | Transforming (collapses events) | Dataset processing (keeps all events) | Streaming / stateful (keeps all events) |
| Output row count | 1 row per unique BY group | Same number of rows as input events | Same number of rows as input events |
| Raw fields preserved? | No (only BY fields + aggregates remain) | Yes (all original fields stay intact) | Yes (all original fields stay intact) |
| Scope of math | Entire search result set | Entire search result set | Events seen so far (or last N via window=N) |
| Classic use case | Dashboards, top talkers, KPI tables | Outlier detection (bytes > 3 * avg_bytes), % of total | Brute-force login counters, cumulative bandwidth, session numbering |
Seeing all three on the exact same 4 events
Suppose our base search (sorted chronologically with | sort 0 _time) returns these 4 web events:
| _time | host | uri | ms |
|---|---|---|---|
| 10:00:01 | web01 | /login | 100 |
| 10:00:02 | web01 | /checkout | 500 |
| 10:00:03 | web02 | /login | 200 |
| 10:00:04 | web01 | /home | 300 |
1. stats: Collapse into a summary table
index=web | sort 0 _time
| stats count, avg(ms) AS avg_ms BY hoststats discards _time and uri and outputs 2 summary rows (one per host):
| host | count | avg_ms |
|---|---|---|
| web01 | 3 | 300 |
| web02 | 1 | 200 |
2. eventstats: Stamp the overall group average onto every event
index=web | sort 0 _time
| eventstats avg(ms) AS host_avg_ms BY host
| eval is_slow = if(ms > host_avg_ms, "YES", "no")Every web01 row receives the final 3-event average (300), making it trivial to spot that /checkout (500 ms) was slower than web01's own baseline:
| _time | host | uri | ms | host_avg_ms | is_slow |
|---|---|---|---|---|---|
| 10:00:01 | web01 | /login | 100 | 300 | no |
| 10:00:02 | web01 | /checkout | 500 | 300 | YES |
| 10:00:03 | web02 | /login | 200 | 200 | no |
| 10:00:04 | web01 | /home | 300 | 300 | no |
3. streamstats: Calculate a running average / counter as each event arrives
index=web | sort 0 _time
| streamstats count AS req_num, avg(ms) AS running_avg_ms BY hostNotice how web01's running_avg_ms updates step-by-step (100, then (100+500)/2 = 300, then (100+500+300)/3 = 300):
| _time | host | uri | ms | req_num | running_avg_ms |
|---|---|---|---|---|---|
| 10:00:01 | web01 | /login | 100 | 1 | 100 |
| 10:00:02 | web01 | /checkout | 500 | 2 | 300 |
| 10:00:03 | web02 | /login | 200 | 1 | 200 |
| 10:00:04 | web01 | /home | 300 | 3 | 300 |
Practice these commands live → SPLK-1001 SPL Lab: stats · SPLK-1002 Lesson: eventstats · SPLK-1002 Lesson: streamstats
High-value streamstats options tested on SPLK-1002 & SPLK-1004
window=N(Sliding Window): Compute statistics across only the most recentNevents rather than all prior events (e.g.,| streamstats window=5 avg(cpu) AS rolling_cpu).current=false(Compare to Prior Events Only): Exclude the current event from the calculation—ideal for comparing an event to the previous event's timestamp or IP address:index=auth action=success | sort 0 user _time | streamstats current=false last(src_ip) AS prev_ip, last(_time) AS prev_time BY user | where isnotnull(prev_ip) AND src_ip != prev_ipreset_on_change=true(Streak Counter): Reset the running calculation whenever theBYfield changes—perfect for counting consecutive failed logins before a successful login:index=auth user=jdoe | sort 0 _time | streamstats reset_on_change=true count AS consecutive_attempts BY action
Common exam gotchas
- Event ordering trap: Splunk returns events newest-first by default. Running
streamstatswithout| reverseor| sort 0 _timecomputes values backward in time! - Memory & result limits:
eventstatsandstreamstatsprocess events on the search head rather than reducing them on indexers. Always filter withindex=,sourcetype=, and| fieldsfirst, and prefertstatsorstatswhen you do not need individual raw events preserved. - Calculating percentage of total without subsearches: Pair
stats+eventstatsinstead of slowappendpipeor subsearches:index=web | stats count BY status | eventstats sum(count) AS total | eval pct = round((count / total) * 100, 2)
Next steps
- Test yourself on the free SPLK-1002 Power User Practice Exam.
- Review all core SPL syntax in the SPL Cheat Sheet.
- Learn how to scale aggregations across terabytes of data in the Splunk tstats & CIM Guide.
Frequently asked questions
What is the main difference between stats, eventstats, and streamstats in Splunk?
stats is a transforming command that collapses raw events into a summary table (one row per group). eventstats calculates the exact same summary across the whole dataset, but appends the result as a new field onto every original event without removing raw fields. streamstats calculates a running (cumulative or sliding-window) statistic in the exact order events flow through the pipeline.
In what chronological order does streamstats process events?
By default, Splunk returns events in reverse chronological order (newest first). If you want streamstats to calculate a true forward-in-time running total or sequence number, pipe through | reverse or | sort 0 _time before running | streamstats.
Which command is fastest: stats, eventstats, or streamstats?
stats is the fastest because indexers perform map-reduce pre-aggregation before sending small summary rows to the search head. eventstats and streamstats must retain individual events in memory/disk on the search head, so always filter events as early as possible before using them.
Which Splunk certification exams test stats vs eventstats vs streamstats?
stats is heavily tested on SPLK-1001 (Core Certified User). Comparing stats, eventstats, and streamstats (including window=, current=, and reset_on_change) is a signature exam topic on SPLK-1002 (Core Certified Power User), SPLK-1004 (Advanced Power User), and SPLK-5001 (CDA).