Using Datadog’s ML‑Backed Metric Anomaly Detection to Replace Static Thresholds
Learn how Datadog’s Metric Anomaly Detection can replace hard‑coded thresholds, with a step‑by‑step guide, an API example, and trade‑offs to consider.
10 Feb 2026, 06:43 UTC

Why Anomaly Detection Beats Hard‑Coded Thresholds
In many teams, the first line of defense against production issues is a simple if value > 100 alert. That approach quickly becomes brittle when traffic patterns shift, seasonality creeps in, or new features change the metric distribution. Datadog’s Metric Anomaly Detection uses machine‑learning to learn a baseline from historical data and surface outliers in real time, so you only get notified when the metric truly behaves oddly.
Getting the Feature Ready
1. Enable the anomaly monitor in the UI
Navigate to Metrics > Anomaly in the Datadog web console. Click New anomaly monitor and choose the metric you want to watch. The wizard will automatically suggest a baseline model that fits the last 30 days of data. You can tune the Sensitivity slider: Low for fewer false positives, High for tighter detection.
2. Define suppression and notification details
Suppression windows prevent duplicate alerts during a single anomaly episode. For example, set a 15‑minute suppression to avoid flooding your Slack channel. Under Notify, pick the same notification channel you use for other alerts, or create a dedicated anomaly‑alerts channel for quick triage.
3. Test with the API
Use the Datadog API to confirm that the monitor is in place and to retrieve recent anomaly data for debugging.
# List all anomaly monitors
curl -X GET \
"https://api.datadoghq.com/api/v1/monitor" \
-H "DD-API-KEY: <YOUR_API_KEY>" \
-H "DD-APPLICATION-KEY: <YOUR_APP_KEY>" \
| jq ".[] | select(.type==\"anomaly\")"
# Get anomalies for a metric over the last day
curl -X GET \
"https://api.datadoghq.com/api/v1/metric//anomalies?start=&end=" \
-H "DD-API-KEY: <YOUR_API_KEY>" \
-H "DD-APPLICATION-KEY: <YOUR_APP_KEY>" \
| jq ".anomalies"
Replace <YOUR_API_KEY> and <YOUR_APP_KEY> with your credentials, <METRIC_NAME> with the metric’s name, and the timestamps with epoch seconds. The response will contain timestamp, value, and anomaly_type fields you can cross‑reference with raw data in the UI.
Concrete Example: Detecting Surges in API Latency
Suppose you expose a service.api.latency.usmsec metric that records request latency in microseconds. Historically, the 95th percentile stays around 200 µs, but a recent code change caused a spike to 800 µs.
- Configure the monitor: In the UI, select
service.api.latency.usmsec, choose a 30‑day baseline, and set sensitivity to Medium. - Set suppression: 10‑minute window to avoid repeated alerts during the spike.
- Notify: Channel
#api‑issues. - Verify: After the spike, check the monitor’s Last 24 hrs tab. You should see a single anomaly point at the spike time.
- Cross‑check via API: Run the snippet above with
service.api.latency.usmsecand the corresponding timestamps. The returned anomaly should match the UI point.
Trade‑Offs and Limitations
- Model Lag: The baseline is built on a rolling window (default 30 days). Recent metric changes may take a few hours to influence the model, so sudden shifts can go unnoticed initially.
- False Positives in Highly Variable Metrics: Metrics with high day‑to‑day variance (e.g., traffic spikes during holidays) can generate many anomalies. Adjust sensitivity or add a
thresholdfilter in the monitor to reduce noise. - Cost of Data Retention: Anomaly detection requires sufficient historical data. If you purge data older than a month, the model will be weaker.
- Complexity vs. Simplicity: For a metric that truly has a fixed threshold (like CPU usage > 90 %), a static alert can still be simpler and more predictable.
Actionable Checklist
- Identify high‑impact metrics that change seasonally or with feature releases.
- Enable anomaly detection with a sensitivity that balances noise and detection.
- Set suppression windows to avoid alert fatigue.
- Use the API to validate anomalies against raw data.
- Periodically review anomaly logs to confirm the model still reflects the metric’s behavior.
By replacing brittle thresholds with ML‑backed anomaly detection, you reduce alert noise, catch real issues faster, and keep your monitoring stack aligned with evolving traffic patterns.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.