Metrics
Cheat sheet · https://pcornel.dk/topic.php?topic=6099
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 topiccurl -s localhost:9090/-/ready— Prometheus readycurl -s 'localhost:9090/api/v1/query?query=up'— scrape targets up/downpromtool 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
| Boundary | Inspect | Healthy interpretation | Do not infer |
|---|---|---|---|
| Intent | Counters | Intended object/scope is explicit and versioned where relevant | Intent is already effective |
| Owning runtime/control plane | Gauges / Histograms | Owner accepts and reports the expected object state | Downstream dependencies are healthy |
| Effective state | Summaries | Independent read-back matches the intended state | Every client sees the same result |
| Consumer outcome | Labels | The original bounded check succeeds in the same time window | Production 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