RousselTMLEARNING

Observability

Mimir: ruler, Alertmanager and mimirtool

Evaluate recording and alerting rules in Mimir, configure the multi-tenant Alertmanager and automate everything with mimirtool (rules, alertmanager, analyze).

1. The ruler #

Prometheus rules, evaluated on all the data.

Principle #

The ruler evaluates recording and alerting rules in Prometheus format, per tenant, on all of Mimir's data (not only that of one Prometheus). Recording rule results are written back to Mimir; alerts are sent to the Alertmanager.

ruler:
  alertmanager_url: http://localhost:8080/alertmanager   # Alertmanager intégré
  rule_path: /data/ruler
ruler_storage:
  s3: { bucket_name: mimir-ruler }
Good practice: Move rules from the Prometheus servers to the ruler as soon as you aggregate several sources: a sum by (service) rule evaluated in one Prometheus only sees its own targets.

A rule file #

# rules/api.yaml
namespace: api
groups:
  - name: api-slo
    interval: 1m
    rules:
      - record: service:http_requests:rate5m
        expr: sum by (service) (rate(http_requests_total[5m]))
      - alert: ApiHighErrorRate
        expr: |
          sum by (service) (rate(http_requests_total{code=~"5.."}[5m]))
            / sum by (service) (rate(http_requests_total[5m])) > 0.05
        for: 10m
        labels: { severity: critical }
        annotations:
          summary: "{{ $labels.service }} : plus de 5 % d'erreurs" 

2. mimirtool #

Mimir's Swiss army knife.

Installation and configuration #

# Binaire (Linux amd64)
curl -fLo mimirtool https://github.com/grafana/mimir/releases/latest/download/mimirtool-linux-amd64
chmod +x mimirtool

export MIMIR_ADDRESS=http://mimir:8080
export MIMIR_TENANT_ID=team-platform

Managing rules #

# Vérifier la syntaxe et le style
mimirtool rules check rules/*.yaml
mimirtool rules lint rules/*.yaml

# Charger un fichier, lister, comparer, synchroniser (GitOps)
mimirtool rules load rules/api.yaml
mimirtool rules list
mimirtool rules diff rules/*.yaml
mimirtool rules sync rules/*.yaml      # supprime aussi ce qui n'est plus dans Git

# Convertir des règles Prometheus existantes
mimirtool rules prepare -i rules/*.yaml
Good practice: Put mimirtool rules diff in the pull request CI and mimirtool rules sync in the deployment: rules become reviewed, versioned code.

Analyzing metric usage #

mimirtool analyze compares the metrics used by your dashboards and rules with the stored metrics: ideal for removing series nobody reads.

mimirtool analyze grafana --address=http://grafana:3000 --key=$GRAFANA_TOKEN   # metrics-in-grafana.json
mimirtool analyze ruler                                                           # metrics-in-ruler.json
mimirtool analyze prometheus --address=http://mimir:8080/prometheus --id=$MIMIR_TENANT_ID

3. The multi-tenant Alertmanager #

One configuration per tenant.

Configuring and loading #

# mimir.yaml
alertmanager:
  data_dir: /data/alertmanager
  external_url: http://mimir.example.com/alertmanager
  fallback_config_file: /etc/mimir/alertmanager-fallback.yaml
# alertmanager.yaml du tenant team-platform
route:
  receiver: slack
  group_by: [alertname, service]
receivers:
  - name: slack
    slack_configs:
      - api_url: https://hooks.slack.com/services/XXX
        channel: '#alertes-plateforme'
mimirtool alertmanager load alertmanager.yaml
mimirtool alertmanager get
Good to know: Grafana can manage this Alertmanager: add an Alertmanager-type data source pointing to http://mimir:8080/ with the « Mimir » implementation, then manage rules and silences from Grafana Alerting.

Related articles

The LGTM stack (Loki, Grafana, Tempo, Mimir): architecture and setup

Grafana Labs' LGTM stack: Loki for logs, Grafana for visualization, Tempo for traces, Mimir for metrics (and …

Why Grafana Mimir? Architecture and deployment modes

The limits of Prometheus alone, what Mimir brings (long-term storage, high availability, multi-tenancy), its …

Mimir: the write path (distributor, ingesters, replication and HA deduplication)

How Mimir ingests metrics: remote_write, distributor validation and limits, hash ring, ingester replication, …

Keep learning

Support us

♥ SUPPORT US

Support RousselTM Learning

Courses, articles, labs and certificates stay free with no intrusive ads. A voluntary contribution, of any amount you choose, pays for hosting, lab environments and new content.

Contribute with PayPal Any amount · card or PayPal accountLearn more
QR code PayPal
Or scan this QR code with your phone

Thank you, every contribution counts!