- push — replaces all metrics for a given job (HTTP PUT).
- pushadd — merges the pushed metrics with any existing metrics for the same job, overriding any metrics with identical names while leaving other metrics intact (HTTP POST).
- delete — removes all metrics for a given job/group (HTTP DELETE).
registry argument (a CollectorRegistry instance) that contains the metrics you want to push. They also accept a job name and an optional grouping_key to distinguish different groups within the same job.
Summary of Pushgateway client functions
CollectorRegistry and registry usage
- Use
CollectorRegistryto create an isolated registry that contains only the metrics you intend to push. - Register metrics with the registry either by passing
registry=...when creating them, or by registering collectors explicitly.
CollectorRegistry, defines a Gauge, sets its value, and merges it into the Pushgateway’s existing metrics for job batch.
push_to_gateway to replace all metrics for a job. This will overwrite any metrics previously stored for the specified job.
delete_from_gateway. You can delete all metrics for a job or target a specific grouping using a grouping key.
- Use the
grouping_keyparameter to distinguish different subsets of metrics within the same job (for example, one job per instance). - Pass a dict of label names to values, for example:
grouping_key={'instance': 'worker-1'}. - The
grouping_keyargument is supported bypush_to_gateway,pushadd_to_gateway, anddelete_from_gateway.
The Pushgateway is intended for short-lived batch jobs or ephemeral processes that cannot be scraped directly by Prometheus. For long-running services, prefer exposing metrics via an HTTP endpoint and letting Prometheus scrape them directly.
- Prometheus Pushgateway: https://github.com/prometheus/pushgateway
- Prometheus Python client: https://github.com/prometheus/client_python
- Prometheus documentation: https://prometheus.io/docs/