Pcornel
Observability

Metrics

Cheat sheet · https://pcornel.dk/topic.php?topic=6099

Back to the Topic

Answer

Metrics are numeric time series identified by a name and labels, sampled or aggregated over time — cheap to store and ideal for trends, dashboards and alerts.

Remember

Pick the right type (counter, gauge, histogram). Apply rate() to counters. Keep label cardinality bounded — never put user IDs or URLs with IDs into labels.

First checks

  • count by (__name__)({__name__=~"http_.*"}) — first check for this topic
  • curl -s localhost:9090/-/ready — Prometheus ready
  • curl -s 'localhost:9090/api/v1/query?query=up' — scrape targets up/down
  • promtool check config prometheus.yml — config valid

Verify in this order

code/exporter exposes metric → scraped/pushed → TSDB → query → dashboard/alert

Where it usually breaks

Typical mistakes are taking a raw counter as a rate, averaging ratios incorrectly, resetting counters across restarts, using unbounded labels, aggregating away instance errors and interpreting missing data as zero without checking scrape state.

Metrics verification boundary matrix

BoundaryInspectHealthy interpretationDo not infer
IntentCountersIntended object/scope is explicit and versioned where relevantIntent is already effective
Owning runtime/control planeGauges / HistogramsOwner accepts and reports the expected object stateDownstream dependencies are healthy
Effective stateSummariesIndependent read-back matches the intended stateEvery client sees the same result
Consumer outcomeLabelsThe original bounded check succeeds in the same time windowProduction correctness outside this scope

Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=6099

Confirmation

Confirm action

Continue?