Prometheus is the starting point of almost any observability stack: the pull model, PromQL and a huge ecosystem of exporters. But the "default" Prometheus has boundaries that are better known before an incident, not after. Below: the internals, a working config and the main cardinality traps, on live examples.

How it works

  • Pull model. The server itself scrapes targets over /metrics; targets come from service discovery or static config. "Target down" is also a signal: up == 0 is the first rule of any new pool.
  • Exporters. node_exporter, kube-state-metrics, blackbox_exporter and hundreds of others; your own exporter is a client library and fifty lines of code.
  • Data model. Everything is a time series of "name + label set"; labels give you slices by any dimension, but their cardinality is also the main source of incidents (see below).
  • PromQL. Instant and range queries, rate()/irate(), by/without aggregations, joins on labels via on().

A working minimum of configuration

global:
  scrape_interval: 30s        # once in 15 seconds - rarely needed
  evaluation_interval: 30s

scrape_configs:
  - job_name: node
    static_configs:
      - targets: ['node-1:9100', 'node-2:9100']
  - job_name: blackbox-probes
    metrics_path: /probe
    params:
      module: [http_2xx]
    static_configs:
      - targets:
          - https://app.example.com/health
    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - target_label: instance
        replacement: blackbox
  - job_name: kubernetes-pods
    kubernetes_sd_configs:
      - role: pod
    relabel_configs:
      - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scrape]
        action: keep
        regex: "true"

The principle is already visible here: the labels you will search by (instance, env, region) are attached at collection time — later, in queries, you cannot conjure up what was never there.

PromQL: four queries that cover an on-call shift

# 1. is the target alive
up == 0

# 2. error ratio per service over 5 minutes
sum by (service) (rate(http_requests_total{code=~"5.."}[5m]))
  / sum by (service) (rate(http_requests_total[5m]))

# 3. p99 latency per service
histogram_quantile(0.99,
  sum by (le, service) (rate(http_request_duration_seconds_bucket[5m])))

# 4. forecast: will the disk run out?
predict_linear(node_filesystem_avail_bytes{mountpoint="/"}[6h], 24 * 3600) < 0

rate() is not decoration but a necessity: a counter without rate is a number from which no engineering meaning can be extracted.

Cardinality: the main source of incidents

One label with a request ID in its value — and the TSDB drifts into nirvana: hundreds of thousands of series on every scrape, memory gone overnight. The rule is simple:

# the number of active series - Prometheus's main graph about itself
prometheus_tsdb_head_series

# top by memory usage
topk(10, prometheus_tsdb_head_series)
PracticeWhat it does
Scrape limitsample_limit on the job: a target with a sudden cardinality spike gets dropped instead of killing the server
The "not a label set" labelanything resembling an ID, an email, a path is not a label — it's a log field
Series monitoringprometheus_tsdb_head_series with an alert on sharp growth

Set sample_limit from day one: it's cheaper than a night-time OOM of a server that collects "everything".

Where the default Prometheus reaches its limits

  • The local TSDB is a single node: memory, disk, and a default retention of 15 days.
  • Long-term storage and "all labels at once" queries hurt: at scale people add Thanos, VictoriaMetrics or Cortex; for simple cases federation is enough.
  • It is a tool about metrics: logs and traces live in neighboring systems, each with its own storage price.

Together with Grafana, Prometheus is the default source: dashboard variables (label_values()) are built straight from its API, and recording rules let you precompute "heavy" expressions so the dashboard opens instantly instead of recomputing five-minute windows every time.

Prometheus is simple while labels are few. The first rule of scaling is not "add a server" but "check that you're not collecting garbage".

Recording rules: queries that get computed in advance

A dashboard that recomputes rate() over 500 series on every open is a slow dashboard. Recording rules move the computation into a background pass:

groups:
  - name: http-aggregates
    interval: 30s
    rules:
      - record: service:http_error_ratio:rate5m
        expr: |
          sum by (service) (rate(http_requests_total{code=~"5.."}[5m]))
            / sum by (service) (rate(http_requests_total[5m]))
      - record: service:http_request_duration:p99
        expr: |
          histogram_quantile(0.99,
            sum by (le, service) (rate(http_request_duration_seconds_bucket[5m])))

The dashboard and alerts now read ready-made series like service:http_error_ratio:rate5m — opening is instant, and TSDB load is predictable. The level:metric:operations naming convention makes the rules self-documenting.

Federation and remote_write: two ways to aggregate

ApproachHow it worksWhen to use
Federationthe upper Prometheus scrapes /federate of the lower onesmerging 3–5 installations of pre-filtered series
remote_writelower instances push everything (or per relabel rules) into central storagescale, Thanos/VictoriaMetrics at the center, long retention

Federation is fine while series are few; on "everything" it dies first. Remote_write is the de facto standard for platforms — it is also the reason the Prometheus pool from the neighboring article doesn't carry the history on its back.

Capacity planning before, not after

  • Series per installation is the main limit: ~5–10M active series on a node with 32–64 GB of RAM is the practical ceiling of standalone mode.
  • Count series, not "services": 200 services × 3000 series = 600k; add kube-state-metrics and node jobs — the figure doubles. Turning "how many series do we have" into a number is half the planning.
  • Alerts on Prometheus itself (prometheus_tsdb_head_series growth, scrape timeouts) — set up before you need them.