- 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), anddeleteoperations, plus client library helpers.
- 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.
How it works (high-level)
- A batch job or short-lived process runs and collects metrics.
- Before exiting, the job pushes its metrics to the Pushgateway.
- The Pushgateway stores the metrics under a grouping key (labels derived from the request path).
- Prometheus scrapes the Pushgateway at its scrape interval and ingests the stored metrics.
- The URL path encodes the grouping key. For example,
/metrics/job/batch-job/instance/instance1creates labelsjob="batch-job"andinstance="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)
- The data sent is in Prometheus text exposition format (
my_batch_job_last_run_seconds 42). - The request path
/metrics/job/batch-job/instance/instance1creates labelsjob="batch-job"andinstance="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
DELETEto 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.
Client libraries (recommended)
Instead of rawcurl 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
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
- Instrument your batch job to collect metrics (using a Prometheus client library if possible).
- Before the job exits, push metrics to the Pushgateway using the appropriate method (
PUT/POST). - Configure Prometheus to scrape the Pushgateway as a normal target.
- 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.