Configuring a Recording Rule

Let's create an example recording rule based on the metrics of a demo service that we are going to monitor. First, let's monitor three instances of the demo service and load our rule file (that we will create in the next step) into Prometheus by adding a rule_files configuration directive to the top level of your Prometheus configuration file.

Set your Prometheus configuration file to the following contents:

  scrape_interval: 15s
  evaluation_interval: 15s

  - demo-rules.yml

  - job_name: 'demo'
      - targets:
        - ''
        - ''
        - ''

The demo service exposes a demo_api_request_duration_seconds_count counter metric (derived from a histogram, thus the duration_seconds component in the base name of the metric) split up by the path, method, and status labels.

Based on that metric, we could calculate the total request rate for each path/method combination, aggregated over the entire job and all status codes, like this:

sum without(status, instance) (

Let's create a recording rule that records the result of this expression into a new metric name called path_method:demo_api_request_duration_seconds_count:rate5m.

Save the following recording rule as a file named demo-rules.yml in the same directory as the main Prometheus configuration file:

- name: demo-service-rules
  # Calculate and record the total request rate for each path/method combination.
  - record: path_method:demo_api_request_duration_seconds_count:rate5m
    expr: |
      sum without(status, instance) (

Reload the Prometheus configuration by sending a HUP signal to the Prometheus process:

killall -HUP prometheus

Prometheus should now evaluate the configured recording rule every 15 seconds.