streamstats
Use the streamstats operator to generate cumulative statistics for each event in your data, streaming up to the current event. In other words, it adds new fields to your current results as it performs the specified statistics at row level, while accumulating the results from all previous events up to the current event in a specified time window.
This operator works with both eventlog and ocsf schemas:
-
For the
eventlogtable, events are ordered based onevent_timeandevent_meta_idparameters. -
For the
ocsftable, events are ordered based onevent_timeandevent_seq_idparameters to ensure proper sequential ordering across OCSF event classes. -
For other tables, if no ordering is available, an internal row number is used to maintain ordering and statistics are calculated based on this.
When used with OCSF fields, streamstats supports nested object fields using dotted notation. Examples include metadata.product.name and actor.user.name.
Caution: streamstats performs expensive aggregation operations. Therefore, we recommend using this command on shorter time periods. Searches running over very large time ranges using streamstats can result in searches timing out.
Syntax
| streamstats <aggregation-list> [by <field-list>] [current=<boolean>] [window=<integer>] [limit=<integer>]
<aggregation-list>
|
Represents a comma-separated list of aggregations to be included in the result. For example: List of supported aggregations:
|
by <field-list>
|
Specifies the list of fields to include in the group-by clause, Similar to the |
current=<boolean>
|
Specifies if the current row must be considered for the calculations. Setting it to Default: |
window=<integer>
|
Specifies the number of events to be used when calculating the statistics. This window size lets you:
Default: Note: When using |
limit=<integer>
|
Specifies the limit of the number of events to be processed. Default: |
Usage
You can use the streamstats operator to make running calculations on your events. For example, you can count the number of events by any field or to get the previous value of the field to make any further calculations.
Examples
Example 1: Eventlog with running statistics
| streamstats count as cnt, sum(bytes_in), next(bytes_in), previous(bytes_in) by app_type
Example 2: Multiple streamstats operations
| streamstats count as cnt, avg(bytes_in) by app_type | streamstats count as cnt_total
Example 3: Windowed streamstats
| streamstats count as cnt, next(bytes_in) by sourcetype window=5 current=false
Example 4: OCSF activity tracking with previous value
Note: For OCSF schema fields, array indexes start at array[1] and not array[0].
ocsf | streamstats previous(activity_name) as pr_activity | fields event_time, activity_name, metadata.product.name, pr_activity | sort event_time
Example 5: Distinct count over a sliding window
| streamstats dc(src) by sourcetype window=10