![]() |
VOOZH | about |
Anomaly detection is an algorithmic feature that identifies when a metric is behaving differently than it has in the past, taking into account trends, seasonal day-of-week, and time-of-day patterns. It is suited for metrics with strong trends and recurring patterns that are hard to monitor with threshold-based alerting.
For example, anomaly detection can help you discover when your web traffic is unusually low on a weekday afternoon—even though that same level of traffic is normal later in the evening. Or consider a metric measuring the number of logins to your steadily-growing site. Because the number increases daily, any threshold would be outdated, whereas anomaly detection can alert you if there is an unexpected drop—potentially indicating an issue with the login system.
To create an anomaly monitor in Datadog, use the main navigation: Monitors > New Monitor > Anomaly.
Any metric reporting to Datadog is available for monitors. For more information, see the Metric Monitor page.
Note: The anomalies function uses the past to predict what is expected in the future, so using it on a new metric may yield poor results.
After defining the metric, the anomaly detection monitor provides two preview graphs in the editor:
Trigger an alert if the values have been above or below, above, or below the bounds for the last 15 minutes, 1 hour, etc. or custom to set a value between 15 minutes and 2 weeks. Recover if the values are within the bounds for at least 15 minutes, 1 hour, etc. or custom to set a value between 15 minutes and 2 weeks.
above or below) a metric is considered to be anomalous if it is outside of the gray anomaly band. Optionally, you can specify whether being only above or below the bands is considered anomalous.Note: The range of accepted values for the Recovery Window depends on the Trigger Window and the Alert Threshold to ensure the monitor can’t both satisfy the recovery and the alert condition at the same time. Example:
Threshold: 50%Trigger window: 4h
The range of accepted values for the recovery window is between 121 minutes (4h*(1-0.5) +1 min = 121 minutes) and 4 hours. Setting a recovery window below 121 minutes could lead to a 4 hour timeframe with both 50% of anomalous points and the last 120 minutes with no anomalous points.Another example:
Threshold: 80%Trigger window: 4h
The range of accepted values for the recovery window is between 49 minutes (4h*(1-0.8) +1 min = 49 minutes) and 4 hours.Datadog automatically analyzes your chosen metric and sets several parameters for you. However, the options are available for you to edit under Advanced Options.
basic, agile, or robust).hourly, daily, or weekly) of the cycle for the agile or robust algorithm to analyze the metric.agile or robust anomaly detection with weekly or daily seasonality. For more information, see Anomaly Detection and Time Zones.Required data history for Anomaly Detection algorithm: Machine learning algorithms require at least three time as much historical data time as the chosen seasonality time to compute the baseline. For example:
All of the seasonal algorithms may use up to six weeks of historical data when calculating a metric’s expected normal range of behavior. By using a significant amount of past data, the algorithms avoid giving too much weight to abnormal behavior that might have occurred in the recent past.
The graphs below illustrate how and when these three algorithms behave differently from one another.
In this example, basic successfully identifies anomalies that spike out of the normal range of values, but it does not incorporate the repeating, seasonal pattern into its predicted range of values. By contrast, robust and agile both recognize the seasonal pattern and can detect more nuanced anomalies, for example if the metric was to flat-line near its minimum value. The trend also shows an hourly pattern, so the hourly seasonality works best in this case.
In this example, the metric exhibits a sudden level shift. Agile adjusts more quickly to the level shift than robust. Also, the width of robust’s bounds increases to reflect greater uncertainty after the level shift; the width of agile’s bounds remains unchanged. Basic is clearly a poor fit for this scenario, where the metric exhibits a strong weekly seasonal pattern.
This example shows how the algorithms react to an hour-long anomaly. Robust does not adjust the bounds for the anomaly in this scenario since it reacts more slowly to abrupt changes. The other algorithms start to behave as if the anomaly is the new normal. Agile even identifies the metric’s return to its original level as an anomaly.
The algorithms deal with scale differently. Basic and robust are scale-insensitive, while agile is not. The graphs on the left below show agile and robust mark the level-shift as being anomalous. On the right, 1000 is added to the same metric, and agile no longer calls out the level-shift as being anomalous whereas robust continues do so.
This example shows how each algorithm handles a new metric. Robust and agile does not show any bounds during the first few seasons (weekly). Basic starts showing bounds shortly after the metric first appears.
For detailed instructions on the advanced alert options (auto resolve, evaluation delay, etc.), see the Monitor configuration page. For the metric-specific option full data window, see the Metric monitor page.
For detailed instructions on the Configure notifications and automations section, see the Notifications page.
Customers on an enterprise plan can create anomaly detection monitors using the create-monitor API endpoint. Datadog strongly recommends exporting a monitor’s JSON to build the query for the API. By using the monitor creation page in Datadog, customers benefit from the preview graph and automatic parameter tuning to help avoid a poorly configured monitor.
Anomaly monitors are managed using the same API as other monitors. These fields are unique for anomaly monitors:
queryThe query property in the request body should contain a query string in the following format:
avg(<query_window>):anomalies(<metric_query>, '<algorithm>', <deviations>, direction='<direction>', alert_window='<alert_window>', interval=<interval>, count_default_zero='<count_default_zero>' [, seasonality='<seasonality>']) >= <threshold>
query_windowlast_4h or last_7d. This parameter controls the time range of data shown in notification graphs. The query_window determines how much historical data appears in the visualization but does not affect alert evaluation. Datadog recommends the query_window to be around five times the alert_window to provide additional context. Note: The query_window must be at least as large as the alert_window.metric_querysum:trace.flask.request.hits{service:web-app}.as_count()).algorithmbasic, agile, or robust.deviationsdirectionabove, below, or both.alert_windowlast_5m, last_1h).intervalalert_window duration.count_default_zerotrue for most monitors. Set to false only if submitting a count metric in which the lack of a value should not be interpreted as a zero.seasonalityhourly, daily, or weekly. Exclude this parameter when using the basic algorithm.thresholdalert_window that must be anomalous in order for a critical alert to trigger.Below is an example query for an anomaly detection monitor, which alerts when the average Cassandra node’s CPU is three standard deviations above the ordinary value over the last 5 minutes:
avg(last_1h):anomalies(avg:system.cpu.system{name:cassandra}, 'basic', 3, direction='above', alert_window='last_5m', interval=20, count_default_zero='true') >= 1
This query uses avg in two places:
avg(last_1h) - Aggregates anomaly data points over the query window for notification graphsavg:system.cpu.system{name:cassandra} - Aggregates the CPU metric across Cassandra nodes before anomaly detectionoptionsMost of the properties under options in the request body are the same as for other query alerts, except for thresholds and threshold_windows.
thresholdscritical, critical_recovery, warning, and warning_recovery thresholds. Thresholds are expressed as numbers from 0 to 1, and are interpreted as the fraction of the associated window that is anomalous. For example, a critical threshold value of 0.9 means that a critical alert triggers when at least 90% of the points in the trigger_window (described below) are anomalous. Or, a warning_recovery value of 0 means that the monitor recovers from the warning state only when 0% of the points in the recovery_window are anomalous.critical threshold should match the threshold used in the query.threshold_windowsthreshold_windows property in options. threshold_windows must include both two properties—trigger_window and recovery_window. These windows are expressed as timeframe strings, such as last_10m or last_1h. The trigger_window must match the alert_window from the query. The trigger_window is the time range which is analyzed for anomalies when evaluating whether a monitor should trigger. The recovery_window is the time range that analyzed for anomalies when evaluating whether a triggered monitor should recover.A standard configuration of thresholds and threshold window looks like:
"options": {
...
"thresholds": {
"critical": 1,
"critical_recovery": 0
},
"threshold_windows": {
"trigger_window": "last_30m",
"recovery_window": "last_30m"
}
}
Additional helpful documentation, links, and articles:
| |