Data model & metric types

This content was generated with the assistance of AI and should be verified against the official documentation before being relied on in production.

Every value Prometheus stores is a time series: a stream of (timestamp, float64 value) samples identified by a metric name plus a set of labels. This page covers that identification model, where the job and instance labels come from, the four metric types client libraries expose (Counter, Gauge, Histogram, Summary), the _bucket/_sum/_count suffixes a Histogram produces in scraped output, and the newer native histogram representation. How an application actually emits these types is covered in Instrumenting Applications; querying them is covered starting with PromQL: Basics & Selectors.

The examples on this page use the running example of this section: a small Python service called orders-api, instrumented with the official client library (the full source is in Instrumenting Applications) and scraped every five seconds by a Prometheus server in Docker (set up in Getting Started). All output shown was captured from that live setup; absolute numbers vary from run to run, but the shapes are what a real server produces.

Time series: metric name + labels

A time series is uniquely identified by its metric name together with an unordered set of key-value label pairs, conventionally written as:

metric_name{label1="value1", label2="value2", ...}

For example, http_requests_total{method="POST", handler="/messages", status="200"} and http_requests_total{method="POST", handler="/messages", status="500"} are two distinct time series — same metric name, different label value on status. Internally Prometheus treats the metric name itself as just another label, __name__, so a metric name is really the special case of one particular label matching. Metric names should describe what is being measured in general (http_requests_total), and labels should carry the dimensions that vary (method, handler, status) — never encode a dimension into the name itself (http_requests_post_total is an anti-pattern). See Data model for the full naming and labeling conventions, including the reserved __-prefixed label namespace and the metric-name/label character restrictions.

Every distinct combination of label values is a separate series stored and indexed independently, so an unbounded label value (a raw user ID, a full URL with a query string, a timestamp) multiplies storage and query cost unboundedly — this is the cardinality concern that comes up repeatedly across this section, in particular in Security & Production Operations.

From an exposition line to a stored series

Prometheus does not store the text it scrapes. For every sample line in a /metrics response it builds a label set, merges in the target labels it knows from the scrape configuration, and appends one (timestamp, value) pair to the series with that exact identity. The timestamp is the scrape time, not something the application reports.

flowchart LR A["Exposition line
http_requests_total{handler=/orders, status=500} 105"] --> B["Add target labels
job, instance, env"] B --> C["Series identity
__name__ + all labels"] C --> D["Append sample
(scrape time, 105.0)"] D --> E[("TSDB: one series
per distinct label set")]

A scrape of the running service shows the effect directly. The application exposes only its own labels (handler, method, status); the server adds job, instance and the static env label from the scrape config:

curl -s 'http://localhost:9090/api/v1/series' --data-urlencode 'match[]=http_requests_total'
{"status":"success","data":[
  {"__name__":"http_requests_total","env":"lab","handler":"/orders","instance":"host.docker.internal:28101","job":"orders-api","method":"GET","status":"500"},
  {"__name__":"http_requests_total","env":"lab","handler":"/health","instance":"host.docker.internal:28101","job":"orders-api","method":"GET","status":"200"},
  {"__name__":"http_requests_total","env":"lab","handler":"/orders","instance":"host.docker.internal:28101","job":"orders-api","method":"GET","status":"200"}
]}

Three label combinations were observed so far (/health never failed), so three series exist. A fourth (/health with status="500") appears the first time that combination is incremented — series are created lazily by the client library, which is why a Counter with a never-seen label value is simply absent rather than zero.

Counting series: the cost of a label

The cost of a metric is the number of series it creates, which is the product of the cardinalities of its labels. Counting series per metric name is itself a PromQL query:

count by (__name__) ({job="orders-api"})

For the orders-api target this returned, among others:

Metric name Series Why

http_requests_total

3

handler x status combinations seen so far (one method).

http_request_duration_seconds_bucket

14

2 handlers x 7 buckets (six le bounds plus +Inf).

http_request_duration_seconds_count, _sum

2 each

One per handler.

orders_in_progress

1

A Gauge with no labels.

order_payload_bytes_count, _sum

1 each

A Summary with no labels.

Adding a customer_id label to http_requests_total for 10,000 customers would multiply those three series by up to 10,000 — and the histogram’s 14 series by the same factor. That is the arithmetic behind the advice to keep label values to small, closed sets.

The server also records how many samples each scrape returned in the synthetic scrape_samples_scraped series (41 for this target at the time of the query), which is the quickest way to spot a target that suddenly exposes far more series than before.

Jobs and instances

A job is the set of targets configured under one scrape_configs entry — typically all the replicas of one service. An instance is one specific target within that job, normally <host>:<port>. Prometheus adds job and instance as labels automatically on every sample it scrapes, so they need no instrumentation from the application:

scrape_configs:
  - job_name: "orders-api"
    static_configs:
      - targets: ["10.0.1.11:9100", "10.0.1.12:9100"]

Scraping this config attaches job="orders-api" to every metric pulled from both targets, and instance="10.0.1.11:9100" or instance="10.0.1.12:9100" depending on which replica answered. That is enough to select one replica’s series (up{instance="10.0.1.11:9100"}) or aggregate across the whole job (sum(rate(http_requests_total{job="orders-api"}[5m]))). Both labels can be renamed or replaced before ingestion (for instance, deriving a friendlier instance from a service-discovery label) — that mechanism belongs to Service Discovery & Relabeling. See Jobs & instances for the full scrape-target model, including the synthetic up metric Prometheus generates for every target.

The synthetic up series

Besides the series a target exposes, Prometheus writes a handful of series of its own for every scrape: up (1 if the scrape succeeded, 0 otherwise), scrape_duration_seconds, scrape_samples_scraped and scrape_samples_post_metric_relabeling. They carry the target’s job and instance labels and are written even when the scrape fails, which is why up == 0 is a reliable down detector:

up
up{instance="localhost:9090", job="prometheus"}                                1
up{env="lab", instance="host.docker.internal:28101", job="orders-api"}         1

The four core metric types

Client libraries expose four metric types. The type only matters at instrumentation time (which library call to use) and, for Histogram/Summary, at scrape time (which series it expands into) — on the wire, every type is still just plain samples: the type is metadata that shapes how PromQL functions like rate() and histogram_quantile() are meant to be used against it. See Metric types for the authoritative definitions.

Counter

A Counter is a cumulative value that only ever increases (or resets to zero on process restart). It is for counting things: requests served, errors raised, tasks completed. Never use a Counter for a value that can decrease — use a Gauge instead. Because a Counter only goes up, it is almost always queried through rate() or increase() rather than read directly:

rate(http_requests_total{job="orders-api", status="500"}[5m])

By convention a Counter’s name ends in _total, and its underlying sample name in the exposition format carries that suffix.

A Counter lives in the process, so it restarts from zero whenever the process does. While restarting the orders-api service during the lab, the raw samples of one series looked like this (scrape interval 5 s, the 15 s gap is the time the service was down):

http_requests_total{handler="/orders",status="200"}
  1794317525  970
  1794317530  1019
  1794317535  1065      <- last sample before the restart
  1794317550  47        <- counter restarted from zero
  1794317555  99
  1794317560  150

rate() and increase() treat a drop as a reset and continue from the new value, so the chart of the rate shows no dip and no negative spike. resets(http_requests_total{handler="/orders",status="200"}[10m]) returned 1 for this series, which is how an alert can count restarts. Increments that happen between the last scrape and the crash are lost, one reason rate() is an estimate rather than an exact count.

Gauge

A Gauge is a value that can go up or down: current memory usage, number of items in a queue, temperature, the number of concurrently in-flight requests. A Gauge is read directly, or aggregated with functions like avg(), min(), max() — not rate(), which is meaningless once a value can decrease:

queue_size{job="orders-api"}

In the running example orders_in_progress goes up when a request starts and down when it finishes. Because a scrape sees only the value at that instant, a Gauge that changes faster than the scrape interval hides its peaks: max_over_time(orders_in_progress[1m]) over the scraped samples is the largest value that was observed, not necessarily the largest that occurred. Use a Counter or Histogram when the peak matters. avg_over_time(orders_in_progress[1m]) returned 2.33 during the lab run, a fair summary of concurrency under the load generator.

Histogram

A Histogram samples observations (request durations, response sizes) and counts them into configurable cumulative buckets, while also tracking their sum and total count. A single Histogram metric expands, at scrape time, into several underlying series:

curl -s http://localhost:28101/metrics | grep 'http_request_duration_seconds.*handler="/orders"'
http_request_duration_seconds_bucket{handler="/orders",le="0.05"} 4.0
http_request_duration_seconds_bucket{handler="/orders",le="0.1"} 7.0
http_request_duration_seconds_bucket{handler="/orders",le="0.25"} 8.0
http_request_duration_seconds_bucket{handler="/orders",le="0.5"} 11.0
http_request_duration_seconds_bucket{handler="/orders",le="1.0"} 15.0
http_request_duration_seconds_bucket{handler="/orders",le="2.5"} 15.0
http_request_duration_seconds_bucket{handler="/orders",le="+Inf"} 15.0
http_request_duration_seconds_count{handler="/orders"} 15.0
http_request_duration_seconds_sum{handler="/orders"} 3.802187955999998

Each _bucket series is cumulative: le="0.25" (less-than-or-equal) counts every observation that also falls into le="0.1" (8 of the 15 requests above took at most 0.25 s, 7 of them at most 0.1 s), and the final le="+Inf" bucket always equals _count. _sum is the running total of all observed values and _count the running total of observations — both are themselves Counters, which is what lets histogram_quantile() and rate() work on a Histogram across time windows. Because buckets are fixed at instrumentation time, a Histogram is cheap to scrape and aggregate across instances, but its quantile estimate is only as accurate as the bucket boundaries chosen. Bucket design and quantile queries are covered in PromQL: Functions.

Summary

A Summary also samples observations and tracks a sum and count, but instead of (or in addition to) buckets it can calculate configurable quantiles (for example, the 0.5 and 0.99 quantile of request latency) directly on the client side, over a sliding time window:

# a Summary with quantiles, as exposed by the Go and Java clients
http_request_duration_seconds{quantile="0.5"} 0.042
http_request_duration_seconds{quantile="0.9"} 0.183
http_request_duration_seconds{quantile="0.99"} 0.512
http_request_duration_seconds_sum 1863.31
http_request_duration_seconds_count 34011

Not every client library implements the quantile part. The Python client’s Summary only tracks the count and sum, so the order_payload_bytes Summary of the running example exposes just two series:

order_payload_bytes_count 15.0
order_payload_bytes_sum 21575.0

That is still useful: rate(order_payload_bytes_sum[5m]) / rate(order_payload_bytes_count[5m]) is the average payload size over the window, and the same count/sum pair exists on every Histogram.

A client-side quantile cannot be aggregated across instances (the 99th percentile of several machines' 99th percentiles is not the fleet’s 99th percentile), while a Histogram’s buckets can be summed across instances and then have histogram_quantile() applied once, server-side. That trade-off is why most instrumentation guidance defaults to Histogram and reserves Summary for cases where only a single process’s exact quantile matters.

Choosing a metric type

flowchart TD Q["What does the value do?"] --> U{"Only increases,
resets on restart?"} U -- yes --> C["Counter
query with rate or increase"] U -- no --> D{"Individual
observations?"} D -- no --> G["Gauge
read directly, avg, max"] D -- yes --> A{"Need percentiles
across instances?"} A -- yes --> H["Histogram
histogram_quantile"] A -- no --> S["Summary
sum and count, optional quantiles"]

Native histograms

Native histograms are a newer, denser wire representation for histogram data: instead of a fixed, manually chosen set of _bucket{le=...} series, a native histogram stores a single series carrying a sparse, exponentially-scaled set of buckets at much higher resolution, computed automatically by the client library. This removes the need to pick bucket boundaries up front, shrinks both scrape payload size and stored series count (one series instead of one-per-bucket), and yields materially more accurate quantiles. Ingesting native histograms is opt-in on the server: in the Prometheus 3.5 server used for this page the capability is switched on with --enable-feature=native-histograms (listed by prometheus --help), and newer releases refine this into per-scrape-job controls, so check the configuration reference for the version you run. A client library must also expose them, and not every library does yet (the Python client used in the running example does not), so classic Histograms remain the default choice. Native histograms remain an evolving specification — see Native histograms for the exposition format, the exponential bucketing scheme, and current client/server support status. Native histograms are also the representation OpenTelemetry’s exponential histogram metric maps onto most directly, which matters when a service is instrumented through the OpenTelemetry SDK rather than a native Prometheus client library, a topic picked up in Instrumenting Applications.

Continue with Instrumenting Applications, or back up to Architecture & Ecosystem for how scraping, storage and these types fit into the overall system.