O'Reilly logo

Prometheus: Up & Running by Brian Brazil

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 17. Recording Rules

The HTTP API is not the only way in which you can access PromQL. You can also use recording rules to have Prometheus evaluate PromQL expressions regularly and ingest their results. This is useful to speed up your dashboards, provide aggregated results for use elsewhere, and to compose range vector functions. Other monitoring systems might call their equivalent feature standing queries or continuous queries. Alerting rules (covered in Chapter 18) are also a variant of recording rules. This chapter will show you how and when to use recording rules.

Using Recording Rules

Recording rules go in separate files from your prometheus.yml, which are known as rule files. As with prometheus.yml, rule files also use the YAML format. You can specify where your rule files are located using the rule_files top-level field in your prometheus.yml. For example, Example 17-1 loads a rule file called rules.yml, in addition to scraping two targets.

Example 17-1. prometheus.yml scraping two targets and loading a rule file
global:
  scrape_interval: 10s
  evaluation_interval: 10s
rule_files:
 - rules.yml
scrape_configs:
 - job_name: prometheus
   static_configs:
    - targets:
      - localhost:9090
 - job_name: node
   static_configs:
    - targets:
      - localhost:9100

Similar to the files field of file_sd_configs, as covered in “File”, rule_files takes a list of paths, and you can use globs in the filename. Unlike file service discovery, rule_files does not use inotify nor does it automatically pick ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required