Example Activity Counts Metrics
Query
let query_frequency = 15m;
let query_period = 30m;
let threshold = 5;
...
| where TimeGenerated > ago(query_period)
...
| as _Events
| join kind=leftsemi (
_Events
// query_period should be 2 * query_frequency
// if IdColumn is Type, and Type has only 1 possible value (only 1 table is used), activity_counts_metrics will only be useful to check if a threshold has been surpassed
| evaluate activity_counts_metrics(Type, TimeGenerated, ago(query_period), now(), query_frequency, ColumnToSummarizeBy1, ColumnToSummarizeBy2, ColumnToSummarizeBy3)
| summarize
arg_min(PreviousTimeGenerated = TimeGenerated, PreviousCount = ["count"]),
arg_max(CurrentTimeGenerated = TimeGenerated, CurrentCount = ["count"])
by ColumnToSummarizeBy1, ColumnToSummarizeBy2, ColumnToSummarizeBy3
| where CurrentTimeGenerated > ago(query_period)
| extend PreviousCount = iff(PreviousTimeGenerated == CurrentTimeGenerated, 0, PreviousCount)
| where (not(PreviousCount > threshold) and CurrentCount > threshold)
or ((CurrentCount - PreviousCount) > threshold)
) on ColumnToSummarizeBy1, ColumnToSummarizeBy2, ColumnToSummarizeBy3
...Explanation
This query is designed to monitor and identify significant changes in activity over a specified time period. Here's a simplified breakdown:
-
Time Parameters:
query_frequencyis set to 15 minutes, which is the interval at which activity is checked.query_periodis set to 30 minutes, which is the total time window being analyzed.thresholdis set to 5, which is the minimum change in activity count that is considered significant.
-
Data Filtering:
- The query filters events to include only those generated within the last 30 minutes (
query_period).
- The query filters events to include only those generated within the last 30 minutes (
-
Activity Analysis:
- The query uses the
activity_counts_metricsfunction to calculate activity counts over time, grouped by three columns (ColumnToSummarizeBy1,ColumnToSummarizeBy2,ColumnToSummarizeBy3). - It captures the minimum and maximum counts within the time window to identify changes in activity.
- The query uses the
-
Change Detection:
- It checks for two conditions:
- If the previous count was not above the threshold but the current count is.
- If the difference between the current and previous counts exceeds the threshold.
- It checks for two conditions:
-
Result Filtering:
- The query uses a
leftsemijoin to filter the original set of events, keeping only those that meet the significant change criteria based on the conditions above.
- The query uses a
In essence, this query is used to detect and highlight events where there has been a notable increase in activity within a 30-minute window, using a 15-minute frequency for checking changes.
Details

Jose Sebastián Canós
Released: July 3, 2024
Tables
_Events
Keywords
TimeGeneratedTypeColumnToSummarizeBy1ColumnToSummarizeBy2ColumnToSummarizeBy3
Operators
letagoasjoinevaluatesummarizearg_minarg_maxbywhereextendiffnoton