Sub topic 3
Metrics, Labels, and Time Series
Assume you are comfortable with Linux commands, YAML, HTTP, and basic server resources. This chapter explains how Prometheus represents measurements. You need this model before writing reliable PromQL queries or building Grafana panels.
The Prometheus data model
A metric is a named measurement, such as CPU time or available memory. Prometheus stores each metric as one or more time series.
A time series is identified by:
- A metric name.
- A set of labels.
- Samples, which are numeric values paired with timestamps.
For example, node_memory_MemAvailable_bytes may have one series for each server. The metric name identifies the measurement. Labels add dimensions that distinguish one series from another.
node_memory_MemAvailable_bytes{instance="server1.example.com:9100",job="node"} 6432155648
node_memory_MemAvailable_bytes{instance="server2.example.com:9100",job="node"} 8123456784These two lines use the same metric name but represent different time series because their instance labels differ. Prometheus adds a new sample to each series whenever it scrapes the exporter.
A label value is text. Prometheus does not automatically understand that instance is a server or that job is an exporter group. You define the meaning through your scrape configuration and naming conventions.
Labels are dimensions
Labels let one metric describe related measurements without creating a separate metric name for every case. A filesystem metric, for example, can use labels for the device, mount point, filesystem type, and server.
| Metric | Useful labels | Meaning |
|---|---|---|
| `node_filesystem_avail_bytes` | `instance`, `mountpoint`, `fstype` | Available space for one filesystem on one server |
The complete label set matters. These are separate series:
node_filesystem_avail_bytes{instance="server1:9100",mountpoint="/",fstype="ext4"} 12000000000
node_filesystem_avail_bytes{instance="server1:9100",mountpoint="/var",fstype="ext4"} 4500000000A label with many possible values creates cardinality, which is the number of distinct series. Labels such as instance, device, and mountpoint usually have bounded values. A label containing request IDs, email addresses, or timestamps can create a new series for every request and consume large amounts of memory and storage.
Time series and selection
A selector chooses series by metric name and label matchers. An exact matcher uses =. A regular-expression matcher uses =~.
node_filesystem_avail_bytes{job="node",mountpoint="/"}This selects root filesystems from the node job. It does not calculate a percentage or combine servers. Those operations belong to later PromQL functions and aggregations.
The data path is:
Exercise
Why are node_filesystem_avail_bytes{mountpoint="/"} and node_filesystem_avail_bytes{mountpoint="/var"} different time series?
Show answer
Their mountpoint label values differ, so each label set identifies a separate series.