How do I line up Alertmanager alert groups with Prometheus metrics on one timeline?
Tares puts Alertmanager alerts and Prometheus metrics on one timeline when both sources carry the same entity key, such as a service label. Alertmanager pushes each alert to Tares as its own event, and Tares polls the Prometheus metrics you pick. In Explore, you pick the entity and see what fired next to how the metric got there, on one clock.
How it works
Tares correlates sources by a shared entity key, so the work is making both sources resolve to the same key value.
- Alertmanager is a push source. You point a webhook receiver at the source’s ingest URL. Alertmanager has already grouped and deduped the alerts. Tares fans the
alertsarray out into one event per alert. Theevent_typeis the alert name, the text is its summary, and the alert labels become Tares labels plus astatusoffiringorresolved. The full alert, including itsfingerprint, stays in the payload. See the Alertmanager connector. - Prometheus is a poll source. You pick metrics by name or by label, with no PromQL to write. Each series becomes a metric event on every poll tick, and the numeric value is stored as a number-typed
valuelabel. See the Prometheus connector. - The key is what joins them. For Alertmanager, Tares derives the key from a label in this order:
namespace,service,job,instance. You can declare aprimarylabel instead, or setkey_labelto name the alert label to key on. For Prometheus, the primary label in your config is the key, for exampleserviceread frommetric.service.
When both sources produce the same value, for example api-server, their events merge into one timeline for that entity. This is the same per-service correlation the AI SRE guide builds on.
Set it up
- Start Tares and open the console at
http://127.0.0.1:8787.
tares up- Add the metrics. Go to Sources → Add source → Prometheus, enter the
url, click Discover, and tick the metrics you want. Tares proposes the entity key and labels from a sample. The generated config looks like this. Note the primaryservicelabel and the number-typedvalue:
- name: metrics
connector: prometheus
poll: 10s
config:
url: http://localhost:9090
queries:
- promql: '{__name__=~"(pg_stat_database_xact_commit|pg_up)"}' # generated from your picks
by_name: true
labels:
- { name: service, field: metric.service, primary: true }
- { name: value, field: value, type: number } # the metric value, aggregate it in triggers- Add the alerts. Go to Sources → Add source → Alertmanager alerts, name it and click Create. The source page shows a receiver block with the ingest URL already filled in. Add it to your
alertmanager.ymland reload Alertmanager. Keepsend_resolved: trueso resolved alerts land on the timeline too:
receivers:
- name: tares
webhook_configs:
- url: http://localhost:8787/ingest/<ingest_key>
send_resolved: true
route:
receiver: tares-
If your instance runs with auth on, the Alertmanager receiver sends a Bearer Authorization header holding an ingest-scoped API key. Without auth, you need no header.
-
Make the keys match. If your alerts carry a
servicelabel, the Alertmanager source already keys on it, becauseservicecomes beforejobandinstancein the derivation order. Ifnamespaceis also present, it wins, so setkey_labelon the Alertmanager source to the label your metrics use. Check that the metric label feeding your primary label holds the same value as the alert label. -
Send a test alert and check Recent events on the Alertmanager source:
curl -X POST http://localhost:8787/ingest/<ingest_key> \
-H 'Content-Type: application/json' \
-d '{"alerts":[{"status":"firing","labels":{"alertname":"PostgresDown","severity":"critical","namespace":"prod"},"annotations":{"summary":"Postgres is down"},"startsAt":"2024-01-01T00:00:00Z"}]}'- Open Fields on each source to see the labels. Then open Explore, pick the entity both sources are keyed on, and read the alert events and metric events on one clock.
What you get
- One timeline per entity where a
firingalert sits next to the metric series that led up to it, and theresolvedevent sits next to the recovery. - Alertmanager’s own grouping, silencing and resolved handling, delivered in real time, with the full alert kept in the payload.
- Only the metrics you picked, ingested as typed events. Triggers can then aggregate the
valuelabel withmax,avgorsum, filtered to one metric byevent_type. - One correlated read for a person in Explore or for an agent. You can wake an agent from a trigger and hand it the same merged timeline.
When something else fits
- If you do not run Alertmanager and only need the alerts your Prometheus rules fire, the
prometheus_alertsconnector polls them directly. Choose Alertmanager when you want its grouping, silencing and real-time delivery. - If you need a computed metric such as a p99 rather than a raw series, a
queriesrow can hold a single PromQL expression with an explicitevent_typeandfield.