docs/sources/datasources/influxdb/alerting/index.md
You can use Grafana Alerting with InfluxDB to create alerts based on your time-series data. This allows you to monitor metrics, detect anomalies, and receive notifications when specific conditions are met.
For general information about Grafana Alerting, refer to Grafana Alerting.
Before creating alerts with InfluxDB, ensure you have:
InfluxDB alerting supports all three query languages: InfluxQL, SQL, and Flux. Queries must return time-series data for Grafana to evaluate values over time and trigger alerts when thresholds are crossed.
| Query language | Alerting support | Notes |
|---|---|---|
| InfluxQL | Yes | Use aggregation functions with GROUP BY time. |
| Flux | Yes | Use aggregateWindow() for time-based aggregation. |
| SQL | Yes | Use $__timeFilter and $__dateBin macros for time filtering. |
To create an alert rule using InfluxDB:
For detailed instructions, refer to Create a Grafana-managed alert rule.
The following examples show common alerting scenarios with InfluxDB.
Monitor CPU usage and alert when it exceeds a threshold:
cpu measurement with mean("usage_system") as the aggregation.time($__interval)In raw query mode:
SELECT mean("usage_system") FROM "cpu" WHERE $timeFilter GROUP BY time($__interval) fill(null)
Monitor memory usage with a Flux query:
from(bucket: "telegraf")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == "mem")
|> filter(fn: (r) => r["_field"] == "used_percent")
|> aggregateWindow(every: v.windowPeriod, fn: mean)
|> yield(name: "mean")
Set the condition to alert when the mean value exceeds 85.
Monitor disk usage with an SQL query:
SELECT $__dateBin(time), mean(used_percent)
FROM disk
WHERE $__timeFilter(time)
GROUP BY $__dateBin(time)
Set the condition to alert when the mean value exceeds 80.
When using InfluxDB with Grafana Alerting, be aware of the following limitations:
Alert queries can't contain template variables. Grafana evaluates alert rules on the backend without dashboard context, so variables like $hostname or $region aren't resolved.
If your dashboard query uses template variables, create a separate query for alerting with hard-coded values.
Complex queries with many nested functions or large result sets may timeout or fail to evaluate. Simplify queries for alerting by:
Follow these best practices when creating InfluxDB alerts:
If you encounter errors when creating or evaluating alert rules, refer to Troubleshoot InfluxDB data source issues.