Recording Rules
Video Lecture
Description
Time series queries can quickly become quite complicated to remember and type using the Expression Browser in the default Prometheus User Interface.
Example query
1 |
|
Rather than remembering and typing this query every time, we can create a recording rule that will run at a chosen interval and make the data available as a time series.
Recording Rule Example 1
CD into the /usr/local/bin/prometheus folder
1 |
|
Create a new file called prometheus_rules.yml
1 |
|
Add our test expression as a recording rule
1 2 3 4 5 |
|
Save it and we can now verify the syntax is ok.
Prometheus now comes with a tool called Promtool which you can use to check your rules files and other things.
We will check our rules file is ok.
1 |
|
The response should contain SUCCESS otherwise there was a problem with your prometheus_rules.yml file.
Now lets add the prometheus_rules.yml reference to the prometheus.yml rule_files section.
1 2 |
|
and restart the prometheus service.
1 2 |
|
Refresh the Prometheus user interface and check the dropdown
Recording Rule Example 2
Lets do another more complicated example.
Update our prometheus_rules.yml file with,
1 2 3 4 5 6 7 8 |
|
Check it with the promtool
1 |
|
If all is ok, restart the prometheus service.
1 2 |
|
Refresh the Prometheus user interface and check the drop down.