nano SIEM
Search Commands

streamstats

Supported in:Self-hosted

Running aggregates in time order: cumulative counts, moving averages and previous values per group.

Use streamstats to add running aggregates to your events in time order. You can calculate cumulative counts, moving averages, or previous values within each group.

Syntax

... | streamstats [current=<bool>] [window=<N>] <agg> [as <name>] [, <agg> ...] [by <field> [, <field> ...]]
OptionDefaultDescription
currenttrueInclude the current event in its own aggregate. current=false uses only earlier events.
windowall earlier eventsLimit the aggregate to N events. With current=true, this includes the current event; with current=false, it covers N earlier events.
aggAny stats aggregation, such as count, avg(f), last(f). Name each with as.
byKeep a separate running aggregate per group.

Write current= before window=, and both before the aggregations. You can start a query with streamstats and no pipe.

How it works

  • Events are processed oldest first (time ascending), within each by group.
  • Every event is kept. Each gets one new column per aggregation, holding the value up to that event.
  • current=false with last(f) gives the previous event's value: useful for time-between-events and change detection.

Examples

The fifth and later failed logon for each user, as they happen:

class_uid=3002 status_id=2 | streamstats count as failures by user.name | where failures >= 5 | table time, user.name, src_endpoint.ip, failures

Seconds since the previous logon by the same user:

class_uid=3002 | streamstats current=false last(time) as prev_time by user.name | where epoch(prev_time) > 0 | eval gap_s=epoch(time) - epoch(prev_time) | table time, user.name, src_endpoint.ip, gap_s

A user's logon from a different source IP than their previous logon:

class_uid=3002 status_id=1 | streamstats current=false last(src_endpoint.ip) as prev_ip by user.name | eval changed=if(src_endpoint.ip != prev_ip, 1, 0) | where changed=1 | table time, user.name, prev_ip, src_endpoint.ip

Moving average of response size per host over the previous 10 requests:

class_uid=4002 | streamstats current=false window=10 avg(http_response.length) as moving_avg by http_request.url.hostname | where http_response.length > moving_avg * 10

Running total of bytes sent per source:

class_uid=4001 | streamstats sum(traffic.bytes_out) as running_bytes by src_endpoint.ip

Notes

  • Use epoch(time) for time arithmetic in seconds. With current=false, last(time) is null on the first event in a group. Filter missing previous values with isnotnull(prev_time).
  • In where, a bare word on the right of = or != is a literal value, not a field. To compare two fields, compute the comparison in eval first, as in the source-IP example.
  • To add a whole-group aggregate to each event instead of a running one, use eventstats.

What's next

  • eventstats: whole-group aggregates on each event
  • stats: aggregate into one row per group
  • transaction: group related events into sessions

On this page