Recording rules in Promscale

Promscale supports Prometheus recording rules. These rules are used to calculate frequently used or computationally expensive queries before they are required. A recording rule is a PromQL expression that Prometheus evaluates at a predefined frequency to generate a new metric series. The new metric series is stored in Promscale, and you can query it in the same way as any other Prometheus metric. In Promscale, you can set the recording rules similar to Prometheus rules configuration.

Set recording rules

Promscale recording rules are built on top of Prometheus recording rules capabilities. The recording rules are written in a YAML file and specified in the Promscale configuration file. The recording rules are used for computationally expensive expressions and save their result as a new set of time series data. These help in visualization of data over a long period of time.

Setting example recording rules

  1. Create a YAML file that contains the configuration for each record, similar to:

    1. groups:
    2. - name: daily_stats
    3. interval: 1h
    4. rules:
    5. - record: customer:api_requests:rate1day
    6. expr: sum by (customer) (rate(api_requests_total[1d]))
  2. Load the rules YAML file to Promscale by specifying this file in Prometheus configuration format along with global evaluation interval , and rules files configuration:

    1. global:
    2. evaluation_interval: 10s
    3. rule_files:
    4. - "<rules-file>"
  3. Pass this configuration file to Promscale when you start the service, using the -metrics.rules.config flag.

To query the recorded metric with PromQL use metric name as:

  1. customer:api_requests:rate1day

To query the metric with SQL:

  1. SELECT time, jsonb(labels) as metric, value
  2. FROM "customer:api_requests:rate1day"
  3. ORDER BY time ASC

For more information about recording, see Prometheus recording.

For specific information about recording rules, see Prometheus recording rules.