OneStopList

Gods and goddesses

Prometheus Best Practices: Metrics, Alerts, and Setup

Updated November 25, 2026

Prometheus best practices center on designing metrics that are easy to query, using labels sparingly but consistently, and setting up alerts that are meaningful and actionable. Below are the core principles, along with the context and details you need to apply them in real-world monitoring setups.

Why Prometheus Works Differently

Prometheus is a pull-based monitoring system that scrapes metrics from HTTP endpoints, storing them as time series in a local TSDB. Unlike traditional monitoring tools that push data, Prometheus periodically fetches samples from targets, which makes it easy to detect when a target is down and to run the scraper from anywhere. It uses a multi-dimensional data model: every metric name can have an arbitrary set of key-value labels, and queries can slice and aggregate across those dimensions using PromQL. This design favors high-cardinality data (like per-request metrics) but punishes misuse, so best practices revolve around keeping label cardinality in check.

Metric Naming and Labeling Conventions

Good metric names are the foundation of a maintainable Prometheus setup. Follow these rules:

  • Use a base unit and a clear suffix. For example, http_requests_total (counter) and http_request_duration_seconds (histogram). Avoid vague names like requests or time.
  • Prefix with the namespace. prometheus_http_requests_total or node_cpu_seconds_total makes it clear which component the metric comes from.
  • Keep label names descriptive and low-cardinality. Labels like job, instance, method, path, status are useful, but values like user_id or request_id can explode cardinality and crash the TSDB.
  • Avoid putting dynamic values in the metric name. Use a label instead. http_errors_total{error="404"} is better than http_errors_404_total.

A common rule of thumb: a metric should have no more than 10–15 unique label combinations per target, and the total number of series per target should stay under 10,000 for typical setups.

Choosing the Right Metric Types

Prometheus offers four metric types, and picking the wrong one leads to incorrect queries and alerts.

  • Counter: A monotonically increasing value that resets to zero on restart. Use for counts of events (requests, errors, tasks completed). Never use a counter for values that can go down, like temperature or queue length.
  • Gauge: A value that can go up and down. Use for current state: CPU temperature, memory usage, number of active connections.
  • Histogram: Samples observations (like request durations) and counts them in configurable buckets. Useful for percentiles (e.g., 95th percentile latency) and for tracking the total sum and count.
  • Summary: Similar to a histogram but computes quantiles on the client side. Use when you need exact quantiles and can’t aggregate across instances easily.

For latency, histograms are generally preferred because they allow aggregation across instances, whereas summaries do not. Use the _sum and _count suffixes for histograms and summaries, and the _bucket suffix for histogram buckets.

PromQL Query Best Practices

PromQL is powerful but easy to misuse. Keep these practices in mind:

  • Use rate() for counters, not delta(). rate(http_requests_total[5m]) gives per-second average, which is robust to restarts and resets. delta() is for gauges.
  • Avoid high-cardinality joins. Joining two metrics on a label with many unique values (like user_id) can create massive series sets and slow down queries.
  • Use recording rules for expensive queries. If you have a query that runs frequently (e.g., for dashboards or alerts), precompute it as a recording rule like job:http_requests:rate5m.
  • Be careful with sum() without labels. Always specify which labels to preserve, e.g., sum by (job) (rate(...)), to avoid accidentally aggregating away important dimensions.

Alerting Best Practices

Alerts should be actionable and not noisy. Follow these guidelines:

  • Alert on symptoms, not causes. For example, alert on “API error rate > 5%” rather than “MySQL connection pool exhausted,” because the latter may be a symptom of a broader issue.
  • Use for to avoid flapping. Set a duration like for: 5m so that a temporary spike doesn’t trigger a page.
  • Include a clear summary and description. The alert message should tell the on-call engineer what is wrong and where to look.
  • Set severity levels. Use labels like severity="page" or severity="ticket" to route alerts to the right channel.
  • Test your alerts. Use promtool to check rule syntax, and consider running a test instance with fake metrics to verify firing conditions.

Common Pitfalls and How to Avoid Them

Many Prometheus users run into the same issues. Here are the most common and their fixes:

  • High cardinality explosion: Adding a label like user_id to a metric can create millions of series. Solution: use labels only for dimensions you need to aggregate over, and consider using a separate logging system for high-cardinality data.
  • Counter resets in alerts: Alerting on http_requests_total > 100 will fire after every restart. Use increase() or rate() instead.
  • Scraping too frequently: Default 15s is fine for most. Scraping every 1s can overload the TSDB and is rarely needed.
  • Storage retention: By default, Prometheus stores data for 15 days. If you need longer, configure --storage.tsdb.retention.time, but be aware of disk usage.
  • Not using recording rules: Complex queries repeated in many dashboards slow down the system. Precompute them.

Frequently Asked Questions

What is the difference between a counter and a gauge?

A counter is a cumulative value that only increases (or resets to zero on restart), used for counts like requests or errors. A gauge is a snapshot value that can go up and down, like current CPU usage or queue length. Use rate() on counters to get a per-second rate, and use gauges directly.

How do I choose between a histogram and a summary?

Use a histogram when you need to aggregate percentiles across multiple instances, because histograms can be summed. Use a summary when you need exact quantiles and don’t need cross-instance aggregation, or when you want to avoid the overhead of bucket calculations on the client. Histograms are more common in practice.

How long should I keep my Prometheus data?

The default retention is 15 days, which is fine for many use cases. If you need longer, you can increase it, but you must ensure your disk can handle the growth. For long-term storage, many users ship data to a remote storage system like Thanos or Cortex, which allow unlimited retention and global queries.

Why is my Prometheus server using so much memory?

High memory usage is often caused by high cardinality (too many unique label combinations) or too many time series. Check the number of series with prometheus_tsdb_head_series and review your metric labels. Also, avoid using sum() without by() in dashboards, as it can cause expensive queries.

Can I use Prometheus for logging?

No, Prometheus is designed for metrics, not logs. For logs, use a dedicated system like Loki (which is part of the Grafana stack) or ELK. Prometheus can scrape log metrics if you export them, but it does not store log content.

What is the best way to alert on a service being down?

Use the up metric, which is 1 when the target is scrapable and 0 when it fails. Alert on up == 0 for more than a few minutes, but be careful to avoid false positives during restarts. Combine with for: 2m to avoid paging on a single failed scrape.

Alternatives and Related Tools

Prometheus is not the only monitoring solution, but it has become a standard in cloud-native environments. Alternatives include:

  • Graphite: Older, push-based, uses a different data model (dot-separated metrics).
  • InfluxDB: A time-series database with its own query language (Flux), often used with Telegraf for collection.
  • VictoriaMetrics: A high-performance, Prometheus-compatible database that can be used as a drop-in replacement for remote storage.
  • Thanos: Not an alternative but a companion that extends Prometheus with long-term storage and global querying.

When choosing, consider whether you need long-term storage, multi-cluster querying, or a simpler setup. Prometheus is excellent for single-cluster monitoring, but for enterprise-scale, you may need to pair it with Thanos or Cortex.

Related

How pages are sourced and corrected: Sources and editorial policy.