Create a rules file
To use rules in Amazon Managed Service for Prometheus, you create a rules file that defines the rules. An
Amazon Managed Service for Prometheus rules file is a YAML text file that has the same format as a rules file in
standalone Prometheus. For more information, see Defining Recording rules
The following is a basic example of a rules file:
groups: - name: cpu_metrics rules: - record: avg_cpu_usage expr: avg(rate(node_cpu_seconds_total[5m])) by (instance) - alert: HighAverageCPU expr: avg_cpu_usage > 0.8 for: 10m keep_firing_for: 20m labels: severity: critical annotations: summary: "Average CPU usage across cluster is too high"
This simple example creates a new metric using a recording rule, called
avg_cpu_usage
and then uses that in an alert. The following describes some of the properties
used. For more information about alerting rules and other properties you can include,
see Alerting rules
-
record: avg_cpu_usage
– This recording rule creates a new metric calledavg_cpu_usage
. -
expr: avg(rate(node_cpu_seconds_total[5m])) by (instance)
– This expression for the recording rule calculates the average rate of CPU usage over the last 5 minutes for each node, grouping by theinstance
label. -
alert: HighAverageCPU
– This alert rule creates a new alert calledHighAverageCPU
-
expr: avg_cpu_usage > 0.8
– This expression tells the alert to look for samples where the average CPU usage goes over 80%. -
for: 10m
– The alert will fire when the expression is met for 10 minutes. In this case, the samples are an average over 5 minutes, so the alert will fire when it receives at least 2 samples that are over the threshold. -
keep_firing_for: 20m
– This alert will continue to fire until the samples are below the threshold for at least 20 minutes. This can be useful to avoid the alert going up and down repeatedly in succession.
For more alerting rule examples, see Alerting rule
examples
Note
You can create a rules definition file locally and then upload it to Amazon Managed Service for Prometheus, or you can create, edit and upload the definition directly within the Amazon Managed Service for Prometheus console. Either way, the same formatting rules apply. To learn more about uploading and editing your file, see Upload a rules configuration file to Amazon Managed Service for Prometheus.