What a metric point actually is
A metric point is a four-part tuple — (metric_name, label_set, timestamp, value) — and the (metric_name, label_set) pair identifies a series that emits one value per scrape forever.
Scene 01
What a metric point actually is
- Watch
- Try it
- Predict
- Capture
Three running services emit one value every 15 seconds. Watch the dots stream into each lane — the float above each dot is the value at that timestamp. Notice that the three lanes share the same metric name but differ in their label set.
Highlighted lines are the ones running in the diagram right now.
struct Point:metric_name: str # e.g. 'http_requests_total'labels: dict[str, str] # e.g. {method: GET, status: 200}ts: int # unix seconds, on a fixed cadencevalue: float64 # the sample reading# (metric_name, labels) names the SERIES.# (ts, value) is the per-sample payload.
def seriesIdentity(p: Point) -> SeriesKey:# ts and value are NOT part of the identity.# any change to metric_name or labels => different series.return (p.metric_name, frozenset(p.labels.items()))
def ingest(p: Point):key = seriesIdentity(p)series = index.get(key)if series is None:# brand-new identity => brand-new stream, starts nowseries = Series(key)index.put(key, series)series.append(p.ts, p.value)
Where this sits in Build a Prometheus-style time-series database
Scene 01 of 12. A point is (metric, label_set, ts, value). The first two parts are the series identity — change one label and you've named a different stream.
Up next. If every scrape is one of these four-part tuples, the obvious move is to drop them in a SQL row — let's see why that obvious move is catastrophic.
All 12 scenes in Build a Prometheus-style time-series database · Every curriculum