Prometheus recording rule not showing up when querying, with the help of Docker

  docker, docker-compose, export, prometheus, python

I am new to Prometheus and just finished writing a custom exporter in Python that successfully creates query-able metrics that Docker connects to Prometheus. Now I’m trying to create a recording rule with the following file rules.rules (also has a default alert rule a coworker showed me):

- name: Standard rules
  rules:
  - alert: InstanceDown
    expr: up == 0
    for: 5m
    labels:
      severity: critical
    annotations:
      summary: "Instance {{ $labels.instance }} down"
      description: "{{ $labels.instance }} of job {{ $labels.job }} has been down for more than 5 minutes."
- name: Statusmap rules
  rules:
  - record: randCounter_rate_InLastMin
    expr: rate(randCounter[1m])

The rules.rules file is included in a a prometheus.yml file that is added via ADD in a same-directory Dockerfile.

prometheus.yml:

  scrape_interval:     10s
  evaluation_interval: 15s #Evaluates alerting rules at this interval

alerting:
  alertmanagers:
  - static_configs:
    - targets:

rule_files:
  - /etc/prometheus/rules.rules

#hello
scrape_configs:
  - job_name: 'prometheus'
    static_configs:
    - targets: ['localhost:9090']
  - job_name: 'custom-exporter-that-is-mine'
    static_configs:
      - targets: ['python:8000']

Dockerfile:

ADD prometheus.yml /etc/prometheus/
ADD rules.rules /etc/prometheus/

I’ve tried querying randCounter_rate_InLastMin in Prometheus and also identically in Grafana and the new metric that should be precomputed because of the rule is not showing up. Am I thinking about this wrong?

Thanks!

Source: Docker Questions

LEAVE A COMMENT