docs/sources/datasources/aws-cloudwatch/alerting/index.md
The Amazon CloudWatch data source supports Grafana Alerting. You can create alert rules on CloudWatch metrics and CloudWatch Logs, so Grafana notifies you when a metric crosses a threshold or when a log query returns a value that meets your alert condition.
This is Grafana Alerting evaluated by Grafana, not CloudWatch alarms. To visualize the history of existing CloudWatch alarms instead, refer to Amazon CloudWatch annotations.
Before you create alert rules with CloudWatch data, ensure you have:
Alert rules require queries that return numeric data that Grafana can evaluate against a threshold. CloudWatch supports alerting for the following query types:
| Query type | Use case | Notes |
|---|---|---|
| Metrics | Threshold-based alerts on CloudWatch metrics | Returns time series data; best suited for alerting. |
| Logs | Alert on log patterns, error counts, or thresholds | Use the stats command to aggregate logs into numeric values. |
{{< admonition type="note" >}}
You can't create an alert rule from a metric math expression that references another query, such as queryA * 2. Define the metric directly in the alert query instead.
{{< /admonition >}}
To create an alert rule using CloudWatch data:
CPUUtilization or a Logs query that uses the stats command.For detailed instructions, refer to Create a Grafana-managed alert rule.
This example fires when average EC2 CPU utilization exceeds 80%:
AWS/EC2CPUUtilizationAverageInstanceIdThis example alerts when the number of log entries that contain Exception exceeds a threshold. CloudWatch Logs alerting requires a query that returns numeric data, which you can produce with the stats command:
Create a new alert rule.
Configure the query:
Select CloudWatch Logs as the query mode.
Select the region and log groups to query.
Enter the following query:
filter @message like /Exception/
| stats count(*) as exceptionCount by bin(5m)
Add expressions:
Set evaluation to run every 5 minutes.
Save the rule.
{{< admonition type="note" >}}
If you receive an error such as input data must be a wide series but got ..., make sure your query returns numeric data that can render in a time series panel.
{{< /admonition >}}
For CloudWatch Logs queries, Grafana polls AWS until the query completes or a timeout is reached. During alert evaluation, the timeout defined in the Grafana configuration file takes precedence over the Query Result Timeout setting on the data source. Set the configuration timeout high enough for your log queries to finish.
Follow these recommendations to create reliable alerts with CloudWatch data.
Verify your query returns numeric data before you create an alert:
When a query returns multiple time series, use the Reduce expression to aggregate them into a single value with Last, Mean, Max, Min, or Sum.
Configure how the rule behaves when no data is returned under Configure no data and error handling. Choose No Data, Alerting, or OK based on whether missing data should be treated as a problem.
If your CloudWatch alerts don't work as expected, use the following sections to diagnose common issues.
For more help, refer to Troubleshoot Amazon CloudWatch.