eventstats
Add group aggregates to every event without collapsing the events, so you can compare each event to its group.
Use eventstats to compare each event with an aggregate for its group. nano adds the aggregate columns and keeps your individual events.
Syntax
... | eventstats <agg> [as <name>] [, <agg> ...] [by <field> [, <field> ...]]| Part | Description |
|---|---|
agg | Any stats aggregation. Name each one with as. |
by | Grouping fields. Without by, the aggregate is computed over all events. |
You can start a query with eventstats and no pipe.
How it works
- Every input event is kept, with all its fields. Each event gets one new column per aggregation, holding the value for its group.
- Use it when you need both the event and a group statistic, for example "this response is 20 times its host's average".
Examples
HTTP responses far larger than their host's average:
class_uid=4002 | eventstats avg(http_response.length) as avg_len by http_request.url.hostname | where http_response.length > avg_len * 20 | table time, http_request.url.hostname, http_response.length, avg_lenFailed logons from sources that tried three or more accounts, keeping each attempt:
class_uid=3002 status_id=2 | eventstats dc(user.name) as users_tried by src_endpoint.ip | where users_tried >= 3 | table time, src_endpoint.ip, user.name, users_triedProcesses that ran on only one host in the time range:
class_uid=1007 | eventstats dc(device.hostname) as host_count by process.name | where host_count = 1 | table time, device.hostname, process.name, process.cmd_lineShare of each web host in the total, after a stats:
class_uid=4002 | stats count by http_request.url.hostname | eventstats sum(count) as total | eval pct=round(count*100/total, 2) | sort -pctNotes
- Put
eventstatsafterstatswhen you need a total across the aggregated rows, as in the last example. Astatsplaced aftereventstatskeeps only its ownbyfields and aggregations, so theeventstatscolumns are dropped there. - To collapse events into one row per group, use stats. For values that accumulate in time order, use streamstats.
What's next
- stats: aggregate into one row per group
- streamstats: running aggregates in time order
- where: filter on the added columns