Time series queries can quickly become quite complicated to remember and type using the Expression Browser in the default Prometheus User Interface.
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
Create a new file called prometheus_rules.yml
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.
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.
and restart the prometheus service.
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
If all is ok, restart the prometheus service.
Refresh the Prometheus user interface and check the drop down.