Iaroslav Kozlov Русский

Observability Automated alert triage

Automated alert triage

Monitoring of databases: metrics are collected and stored, rules turn them into alerts, Alertmanager groups and routes the alerts, and a triage service gathers what the engineer on call looks for first.

My work

I automated first-pass alert triage based on the data and configuration of Alertmanager and on metrics from PMM or VictoriaMetrics, depending on the database.

How it is built

An example of the stack around my work, not the configuration of a real site: a generalised layout from the documentation of Prometheus, Alertmanager, VictoriaMetrics and Percona PMM 3, with two Alertmanagers. How the triage chooses what to gather and writes its message is not shown.

data control My part

While the first instance is down

the route after the failure unavailable takes over

  • vmalert has sent every alert to both instances, as all of them are listed in -notifier.url: Alertmanager 2 has received them all itself.
  • Silences and the state of notifications are replicated between the instances: the second carries on grouping, inhibiting and notifying the webhook.
  • This holds only while every alert is sent to every instance, as the README asks; a load balancer would send each alert to one of them. 6 78

Components

Press a component to read what it does.

Databases exporters

The database hosts: exporters give their state as metrics, and PMM’s agents collect the statistics of queries.

Metrics store VictoriaMetrics

The store of the series. It answers queries in MetricsQL, a language backwards-compatible with PromQL.

PMM Query Analytics

Percona Monitoring and Management: metrics of the databases and Query Analytics, which keeps the history of completed queries.

vmalert alert rules

Evaluates the alerting rules against the store on a schedule and sends what fires to the Alertmanagers.

Alertmanager instance 1

Groups the alerts, suppresses notifications for some while certain others are firing (its inhibition rules), and routes the rest to receivers by their labels.

Alertmanager instance 2

A second instance of the same cluster: it receives every alert itself, and shares silences and the state of notifications with the first.

Triage webhook

A receiver behind Alertmanager’s webhook: it takes the notification and gathers context for it from Alertmanager and from the metrics of PMM or VictoriaMetrics.

On call a notification

The engineer on duty: reads the message and decides.

  1. Collection

    An exporter should give metrics only when Prometheus asks, and build them afresh each time. PMM’s agents also collect the metrics of queries for its Query Analytics.

    My part Prometheus exporters of my own: the queries, locks and resource use of Greenplum are seen in Grafana.

    In detail

    Metrics should only be pulled from the application when Prometheus scrapes them, and a collector should create new metrics each time rather than update the same ones; a metric that takes more than a minute to get may be cached, which its HELP string should say. The default scrape timeout is 10 seconds. PMM’s Query Analytics keeps the history of completed queries, for MySQL, PostgreSQL and MongoDB, to find the slow ones. 1 23

    Where it breaks Every new value of a label is a new series: the guidance is to keep the cardinality of a metric below ten, and a query or a session as a label would take it far past that.

  2. Rules

    vmalert evaluates the alerting rules against the store, once a minute by default. With a for clause a condition has to hold for that long before the alert fires.

    In detail

    vmalert runs the alerting and recording rules against its datasource and keeps the state of the alerts. The for clause makes an alert wait between the first time an element appears and the moment it is counted as firing; in between it is pending, and without for the first true evaluation fires. keep_firing_for keeps an alert firing for a while after its condition was last met, against flapping and false resolutions. 4 56

    Where it breaks MetricsQL is backwards-compatible with PromQL but differs from it on purpose in places: a query carried over can return other numbers, and a threshold tuned on one side can be wrong on the other.

  3. Two Alertmanagers

    For high availability the rules send every alert to every Alertmanager, not to a balancer in front of them. Each instance receives the alerts on its own, and they share silences and the state of notifications.

    In detail

    All the Alertmanager URLs are listed in vmalert’s -notifier.url to ensure high availability. In a high-availability deployment every Alertmanager instance receives alerts independently, while silences and the state of notifications are replicated between peers: Alertmanager expects all alerts to be sent to all Alertmanagers. 6 7811

    Where it breaks The Alertmanagers must not sit behind a load balancer: every alert is expected to be sent to every one of them; and from version 0.15 the default cluster transport needs both UDP and TCP between its instances (TCP alone with TLS).

  4. Grouping and inhibition

    Alertmanager groups alerts of a similar nature into one notification, suppresses some while certain others are firing, and sends the rest to a receiver by their labels.

    In detail

    Grouping puts alerts of a similar nature into a single notification, which matters most in a large outage, when hundreds or thousands of alerts may fire at once. Inhibition suppresses the notifications for some alerts while certain others are already firing. By default a group waits 30 seconds before its first notification; then every 5 minutes it sends one if alerts have fired or resolved since the last, and if nothing has changed it repeats the last notification after 4 hours. A webhook receiver gets each notification as JSON: its status, firing or resolved, and the alerts with their labels, annotations, start time and a link to what caused them. 7 9

    Where it breaks A webhook is sent resolved notifications too, by default (send_resolved), and with max_alerts above 0 a longer list is cut, with the number of the alerts left out given in truncatedAlerts: a receiver that assumes "firing, and all of them" is wrong.

  5. Triage

    Behind the webhook, a triage service gathers for the alert what the engineer would look for first: what Alertmanager knows, and the metrics from PMM or VictoriaMetrics, depending on the database.

    My part I automated the first-pass triage of alerts from the data and configuration of Alertmanager and the metrics of PMM or VictoriaMetrics, depending on the database.

    In detail

    The Prometheus guidance on alerting asks for alerts that link to the relevant consoles and make it easy to find which component is at fault. The store answers queries in MetricsQL, backwards-compatible with PromQL, so Grafana dashboards on a Prometheus data source should work the same after a switch from Prometheus; PMM’s Query Analytics holds the history of the queries of MySQL, PostgreSQL and MongoDB. 3 510

    Where it breaks What the triage concludes from that context is not shown here: the figure shows what it reads.

  6. The message

    The engineer on call gets a notification with the triage’s context already in it.

    In detail

    The guidance is to keep alerting simple, alert on symptoms, have good consoles to find causes, and avoid pages where there is nothing to do: as few alerts as possible, on symptoms associated with the pain of users rather than every way the pain could be caused. 10

    Where it breaks Monitoring that has stopped pages nobody: the guidance is to have alerts that the monitoring itself, Prometheus and the Alertmanagers, is available and runs correctly.

The whole diagram

Automated alert triage

Every component and step of the figure, drawn at once; the page lists them in text.

data control My part

Next story

Anomaly detection with AI

A service that checks the metrics of databases by catalogs of signals: it confirms a breach of a threshold, finds what has become unusual for a series against its own past and where it is heading, follows each finding as an episode, and reports to a chat, where a language model may add a hypothesis of the cause.

How the detection works Observability