Skip to main content
In this lesson, we explain Prometheus Pushgateway and how it helps capture metrics from short-lived, ephemeral batch jobs that exit before Prometheus can scrape them. Batch jobs that run briefly and then terminate are difficult for Prometheus to scrape because the process might have already exited when a scrape occurs. In that case, there is nothing for Prometheus to contact, and the job’s metrics are effectively lost from the Prometheus scraping perspective. The Pushgateway solves this by acting as an intermediary between ephemeral jobs and the Prometheus server. A batch job pushes its metrics to the Pushgateway before it exits. The Pushgateway stores those metrics and exposes them on an HTTP endpoint so Prometheus can scrape them like any other target.
The image illustrates the Push Gateway's role as an intermediary between batch jobs and the Prometheus server, with metrics being scraped at regular intervals.
Prometheus treats the Pushgateway like any other scrape target: it scrapes the Pushgateway’s /metrics endpoint on the configured schedule. Prometheus does not need to know that the metrics were pushed; it only consumes the metrics that the Pushgateway exposes. Typical push flow:
  • The job collects metrics while running.
  • Before exiting, the job pushes those metrics to the Pushgateway.
  • The Pushgateway stores and serves those metrics at /metrics.
  • Prometheus scrapes the Pushgateway at its regular scrape interval.
Why use Pushgateway?
  • Capture metrics from non-long-lived processes (batch jobs, one-off tasks).
  • Decouple metric lifetime from job lifetime so Prometheus can scrape them at its schedule.
  • Add grouping labels to distinguish pushes from multiple instances.
For more background, see the Prometheus documentation: Pushgateway. HTTP endpoints and common actions Example: push a local metrics file to the Pushgateway
Example: include grouping labels in the push URL
Example: remove metrics for a job to avoid stale entries
Best practices and caveats
Use the Pushgateway primarily for short-lived, ephemeral jobs. The Pushgateway stores metrics until they are explicitly deleted or overwritten. If metrics are not removed or updated after a job completes, they can become stale and produce misleading results in Prometheus.
Additional tips:
  • Prefer instrumenting long-lived services directly and let Prometheus scrape them.
  • Use meaningful grouping labels in the URL path to avoid label collisions and to identify metric sources.
  • Automate deletion of Pushgateway entries when jobs are complete, or implement a TTL/cleanup mechanism if appropriate.
  • Monitor the Pushgateway itself as a scrape target to ensure it remains available for Prometheus to collect pushed metrics.

Watch Video