Skip to main content
As your application grows to expose multiple endpoints—for example, endpoints for cars (/cars) and boats (/boats)—you may want both a global request count and per-path counts. Incrementing a single global counter for every endpoint tracks total traffic, but it doesn’t tell you how that traffic is distributed across paths. Example endpoints:
If you want per-path totals, one naive solution is creating a distinct Counter for each path and incrementing the appropriate one:
This approach works, but it scales poorly. You end up with one metric name per path, making application-wide aggregations awkward: queries must reference every metric name and you must remember to update instrumentation whenever you add or remove endpoints. This increases maintenance overhead and makes queries error-prone. A better practice is to use labels (also called dimensions). Define a single metric and add a path label at metric creation time. Then, when incrementing, provide the label value.
With this pattern, each distinct path value produces a separate time series under the same metric name http_requests_total. That makes filtering and aggregation simple and reliable.
The image shows a dark-themed command-line interface with a text input area and the label "Labels" at the top. There is a small icon of an eye on the bottom right.
Prometheus will expose each labeled time series. For example:
Listing the metric without selectors returns all label variations:
To compute the total across all paths use PromQL aggregation:
You can also add multiple labels to capture more dimensions (for example, path and HTTP method):
Label order matters: the first label value corresponds to path, the second to method, as declared in the metric. Query examples with multiple labels:
And combining selectors still works:
Use labels to keep metrics organized and queryable, but be mindful of cardinality: labels that can take many unique values (like user IDs, session tokens, or request IDs) cause a large number of time series and can harm performance and storage.
Use labels to keep metrics organized and queryable. However, be cautious about label cardinality: labels with high cardinality (for example, user IDs, session IDs, or other highly unique values) can produce a huge number of time series and cause performance and storage problems. Restrict labels to a small, well-defined set of values.
Links and references

Watch Video