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-platformManaging 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/*.yamlGood practice: Putmimirtool rules diffin the pull request CI andmimirtool rules syncin 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_ID3. 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 getGood 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.