Prometheus is easy to start and easy to get wrong. A default install scrapes a few targets and draws nice graphs, then a label explosion or a noisy alert costs you a weekend. This guide covers how to use Prometheus well once real traffic and real on-call depend on it.
Key Takeaways
- Prefer histograms to summaries for latency, because you can aggregate histograms across instances.
- Keep labels bounded. A user ID or request ID as a label creates a new time series per value.
- Apply
rate()to counters first, thensum(), and use a range at least four times your scrape interval.- Alert on what users feel, such as errors and latency, with a
for:duration to filter out blips.- Plan retention early. Prometheus keeps 15 days by default and its local storage isn’t clustered.
Prometheus in one picture
Prometheus is an open-source monitoring system that scrapes metrics over HTTP, stores them as time series and lets you query them with PromQL. The Prometheus server pulls metrics from targets on a schedule. Your applications expose a /metrics endpoint through a client library. Exporters do the same for systems you can’t instrument, such as MySQL or the Linux kernel.
Alertmanager receives alerts from Prometheus. It groups them, silences them and routes them to Slack, PagerDuty or email. Grafana sits on top for dashboards.
The Pushgateway is the one exception to the pull model. Short-lived batch jobs push their final metrics to it, and Prometheus scrapes the gateway. The Prometheus docs recommend it for service-level batch jobs and little else.
Pick the right metric type
Prometheus has four metric types. Pick the type before you write queries against it.
| Type | Use it for | Example |
|---|---|---|
| Counter | Things that only go up, reset on restart | Requests served, errors, bytes sent |
| Gauge | Values that go up and down | Queue depth, memory in use, active connections |
| Histogram | Distributions you need to aggregate | Request latency, response size |
| Summary | Quantiles from a single instance | Client-side latency where you can’t aggregate anyway |
Use histograms for latency in most services. You can sum histogram buckets across pods and compute a fleet-wide p99. You can’t aggregate summary quantiles across instances, as the histograms and summaries guide explains. Choose bucket boundaries around your latency targets, for example 100 ms, 300 ms and 1 s.
Name metrics the Prometheus way
Good names make PromQL readable and dashboards reusable. The naming guide sets the conventions:
- Use snake_case with an application prefix, such as
checkout_requests_total. - Use base units: seconds and bytes, not milliseconds or megabytes.
- Put the unit in the name, such as
_secondsor_bytes. - End counters in
_total. - Put dimensions in labels rather than in the name. Write
http_requests_total{method="POST"}, nothttp_post_requests_total.
A name plus its labels should describe one thing. If you’d sum two series of the same metric and get nonsense, split them into two metrics.
Keep label cardinality under control
Every unique combination of label values creates a new time series. Ten endpoints, five status codes and three methods give you 150 series. Add a user_id label and you get 150 series per user. Memory use and query time grow with the series count. High cardinality can run a Prometheus server out of memory.
Keep labels bounded and low in count. User IDs, email addresses, request IDs and full URLs with query strings belong in logs or traces. The instrumentation guide suggests keeping the cardinality of most metrics below 10.
Check where your series come from with this query:
topk(10, count by (__name__) ({__name__=~".+"}))
Watch prometheus_tsdb_head_series on the Prometheus server itself, and alert when it grows faster than your traffic. If an exporter emits a label you don’t need, drop it at scrape time with metric_relabel_configs, as the example config below shows.
Use rate() on counters, then aggregate
A raw counter goes up forever, so you’ll almost always query its rate. Apply rate() first and sum() second:
sum by (job) (rate(http_requests_total[5m]))
Reversing the order breaks counter-reset handling, because rate() needs the raw series to detect restarts. Use a range of at least four times your scrape interval. With a 15-second scrape, [1m] is the minimum and [5m] gives smoother graphs. Use irate() for fast-moving graphs and rate() for alerts.
For latency, apply rate() to the histogram buckets and keep le in the aggregation:
histogram_quantile(0.99, sum by (le, job) (rate(http_request_duration_seconds_bucket[5m])))
Precompute expensive queries with recording rules
Dashboards that run heavy PromQL on every refresh slow down Prometheus for everyone. Recording rules evaluate a query on a schedule and store the result as a new series. The rules guide recommends names in the form level:metric:operations:
groups:
- name: http
rules:
- record: job:http_requests:rate5m
expr: sum by (job) (rate(http_requests_total[5m]))
- record: job:http_request_duration_seconds:p99_5m
expr: histogram_quantile(0.99, sum by (le, job) (rate(http_request_duration_seconds_bucket[5m])))
Point dashboards and alerts at the recorded series. Queries get cheaper, and every panel uses the same definition.
Alert on symptoms users feel
Page on symptoms, such as error rate and latency against a target. Causes such as high CPU belong on dashboards or in low-priority tickets. The alerting guide makes the same case: keep pages few and actionable.
groups:
- name: checkout-alerts
rules:
- alert: CheckoutHighErrorRate
expr: |
sum(rate(http_requests_total{job="checkout", code=~"5.."}[5m]))
/ sum(rate(http_requests_total{job="checkout"}[5m])) > 0.02
for: 10m
labels:
severity: page
annotations:
summary: "Checkout error rate above 2% for 10 minutes"
The for: 10m clause holds the alert until the condition persists, which filters out short blips. Add a runbook link in the annotations so the person on call knows the first step.
Once you have SLOs, alert on how fast you’re burning the error budget instead of on a fixed threshold. I covered that sequence in Do You Need an SRE Yet? Start With SLOs.
Plan retention and long-term storage
Prometheus keeps 15 days of data by default. Change it with --storage.tsdb.retention.time or cap disk use with --storage.tsdb.retention.size. The storage docs state that local storage isn’t clustered or replicated, so a lost disk means lost history.
For longer retention, or one query view across clusters, send data to a long-term store with remote_write. Thanos and Grafana Mimir are common choices. Keep Prometheus itself lean, with short local retention for fast queries.
A scrape config that scales
Static target lists work for a lab. In Kubernetes, use service discovery so Prometheus follows pods as they come and go:
global:
scrape_interval: 30s
evaluation_interval: 30s
rule_files:
- /etc/prometheus/rules/*.yml
scrape_configs:
- job_name: kubernetes-pods
kubernetes_sd_configs:
- role: pod
relabel_configs:
# Scrape only pods annotated with prometheus.io/scrape: "true"
- source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scrape]
action: keep
regex: "true"
- source_labels: [__meta_kubernetes_namespace]
target_label: namespace
- source_labels: [__meta_kubernetes_pod_name]
target_label: pod
metric_relabel_configs:
# Drop an unbounded label an exporter adds
- action: labeldrop
regex: request_id
alerting:
alertmanagers:
- static_configs:
- targets: ["alertmanager:9093"]
remote_write:
- url: https://mimir.example.com/api/v1/push
The prometheus.io/scrape annotation is a common community convention, not a built-in Prometheus feature. Keep one scrape interval across most jobs. Mixed intervals make rate() ranges and recording rules harder to reason about.
My approach on client platforms
I start by asking which questions the on-call engineer needs answered at 3 a.m., then work back to the metrics. On consulting work for Regeneron I built an observability framework on EKS with the Prometheus stack. For Telenor I ran Prometheus and Grafana with custom exporters for production Kubernetes.
On any Prometheus setup, I check three things first: unbounded labels, dashboards that run raw queries, and alerts on causes rather than symptoms. You can read more about my background in cloud reliability.
Frequently asked questions
What are the most important Prometheus best practices?
Keep label cardinality bounded and use histograms for latency. Apply rate() before sum(), and precompute heavy queries with recording rules. Alert on user-facing symptoms with a for: duration, and plan retention before you need old data.
How do I start using Prometheus?
Run Prometheus and Alertmanager, add Node Exporter for host metrics and instrument one service with a client library. Expose /metrics, add a scrape job and build one dashboard in Grafana. Then add a single alert on that service’s error rate.
How long does Prometheus keep data?
Fifteen days by default. Change it with --storage.tsdb.retention.time or --storage.tsdb.retention.size. For months or years of history, use remote_write to a long-term store such as Thanos or Mimir.
Should I use a histogram or a summary?
Use a histogram in most cases. You can aggregate histograms across instances and compute quantiles with histogram_quantile(). A summary computes quantiles on each instance, and you can’t combine those quantiles across a fleet.






