Skip to main content
This lesson explains the Prometheus Pushgateway: what it is, why it exists, and how to use it correctly. Prometheus uses a pull-based model: it scrapes metrics from instrumented targets. This model breaks for short-lived processes (batch jobs, CI steps, ephemeral scripts) that start, expose metrics, and exit before Prometheus can scrape them. The Pushgateway fills that gap by acting as a temporary store: jobs push metrics to the Pushgateway before they exit, and Prometheus later scrapes the Pushgateway like any other target. Key benefits:
  • Preserves metrics from short-lived jobs that cannot be scraped directly.
  • Integrates seamlessly with Prometheus — the Pushgateway is just another scrape target.
  • Supports push, pushadd (merge), and delete operations, plus client library helpers.
Summary:
  • The Pushgateway stores metrics pushed by short-lived jobs and exposes them via an HTTP endpoint.
  • Prometheus scrapes the Pushgateway using normal scrape_configs; no special Prometheus logic is required.
  • The Pushgateway is intended only for short-lived or push-only workflows, not as a long-term replacement for instrumenting always-on services.
Use the Pushgateway for short-lived or batch jobs that cannot be scraped reliably. For long-running services, prefer direct exposition and pull-based scraping.
For official docs and further reading:

How it works (high-level)

  1. A batch job or short-lived process runs and collects metrics.
  2. Before exiting, the job pushes its metrics to the Pushgateway.
  3. The Pushgateway stores the metrics under a grouping key (labels derived from the request path).
  4. Prometheus scrapes the Pushgateway at its scrape interval and ingests the stored metrics.
Grouping key example:
  • The URL path encodes the grouping key. For example, /metrics/job/batch-job/instance/instance1 creates labels job="batch-job" and instance="instance1" on the stored metrics.

Quick reference: key concepts

Common Pushgateway operations

Note: In documentation and examples below, wrap angle-bracket placeholders in backticks (for MDX) when required, e.g. use `/metrics/job/<job>`.

Example: push a metric using curl (text format)

Explanation:
  • The data sent is in Prometheus text exposition format (my_batch_job_last_run_seconds 42).
  • The request path /metrics/job/batch-job/instance/instance1 creates labels job="batch-job" and instance="instance1".
  • The Pushgateway stores the metric and exposes it for scraping.

Example: Prometheus scrape configuration

  • Prometheus will scrape the Pushgateway endpoint and ingest any metrics that have been pushed there.
  • Treat the Pushgateway just like any other scrape target in Prometheus.

Example: delete metrics for a grouping key

  • Use DELETE to remove stale or no-longer-relevant metrics and avoid cardinality growth.

Push modes and semantics

Choose the appropriate method based on whether you need replace semantics or merge semantics. Instead of raw curl commands, use the official Prometheus client libraries which include helpers to push to the Pushgateway. They handle exposition formatting, escaping, and provide functions analogous to:
  • push / pushgateway.push (replace)
  • pushadd / pushgateway.pushAdd (merge)
  • delete / pushgateway.delete
Supported languages: Go, Java, Python, Ruby, and others. These libraries help avoid mistakes that can lead to incorrect labels or formatting.

Best practices and cautions

  • Do not use the Pushgateway as a general-purpose metrics aggregator for long-running services. It is designed for short-lived jobs that cannot be scraped directly.
  • Carefully design grouping keys (labels) to avoid unintentionally creating high cardinality. Avoid including highly variable labels (e.g., timestamps, unique IDs) in grouping keys.
  • Regularly delete metrics for completed jobs if the data is no longer relevant, or implement lifecycle management to avoid stale series.
  • Remember that metrics in the Pushgateway are treated “as if” they were exposed by the job. Incorrect labels or timestamps can produce misleading results.
Avoid using the Pushgateway as a replacement for instrumenting always-on services. Doing so can produce stale or misleading metrics and cause cardinality explosions if grouping keys are not controlled.

Example workflow summary

  1. Instrument your batch job to collect metrics (using a Prometheus client library if possible).
  2. Before the job exits, push metrics to the Pushgateway using the appropriate method (PUT / POST).
  3. Configure Prometheus to scrape the Pushgateway as a normal target.
  4. Periodically delete or rotate metrics for completed jobs to prevent stale series.

This article explained the purpose of the Prometheus Pushgateway, how to push and delete metrics, example configurations, and recommended practices. Use the Pushgateway for short-lived processes and manage grouping keys and metric lifecycle carefully to avoid stale metrics and high cardinality.

Watch Video