- Send an HTTP request directly to the Pushgateway (covered here).
- Use a Prometheus client library to push metrics programmatically (not covered).
curl, grouping behavior, and the different HTTP methods (POST, PUT, DELETE) and their semantics.
HTTP push URL structure
The Pushgateway accepts metric pushes at an endpoint that encodes a grouping key in the URL path. The grouping key is derived from thejob name and any additional label/value pairs encoded as path segments.
Pattern:
http://<pushgateway_address>:<port>/metrics/job/<job_name>/<label1>/<value1>/<label2>/<value2>
Key points:
- Labels encoded in the path are appended to every pushed metric and form part of the grouping key.
- The grouping key determines how metrics are grouped for updates and deletions.
- Always URL-encode label names and values that include special characters (slashes, spaces, etc.).
- Prometheus Pushgateway documentation: https://github.com/prometheus/pushgateway
- Prometheus text exposition format: https://prometheus.io/docs/instrumenting/exposition_formats/
Pushing a single metric with curl
Metric data must be sent in Prometheus’ text exposition format. A common pattern is to pipe the metric text intocurl with --data-binary @-, which reads the request body from stdin and sends a POST by default.
Example: push a simple metric named example_metric with value 4421 under job="db_backup":
echo "example_metric 4421"writes the metric in the text exposition format.curl --data-binary @-sends stdin as the request body (POST by default).- The URL
http://localhost:9091/metrics/job/db_backupsets the grouping keyjob="db_backup".
Grouping behavior and label-based grouping keys
Metrics pushed to the same URL path—i.e., the samejob and identical label/value path components—belong to the same group. Groups enable updating or deleting a set of metrics together.
Example: push two metrics into the same group (job=archive, db=mysql):
job=archive, app=web):
archive job:
POST vs PUT vs DELETE — semantics and examples
The HTTP method you use affects how metrics are updated in the target group.
Note:
curl --data-binary @- sends a POST by default. Use -X PUT or -X DELETE to get PUT or DELETE semantics.
POST example
POST a new value formetric_one (replaces only that metric in the archive/app=web group):
PUT example
Replace the entirearchive/app=web group with only metric_one:
archive/app=web group will contain only:
DELETE example
Delete thearchive/app=web group entirely:
db=mysql) remain.
Recap
- The grouping key is encoded in the path:
jobplus any additional label/value path segments. - Labels in the path are appended to every pushed metric.
- Use POST to update specific metric names within a group (non-destructive for other metrics in the group).
- Use PUT to replace the entire group.
- Use DELETE to remove the entire group.
- URL-encode path segments that include special characters.
When using
curl --data-binary @-, curl sends a POST request by default. Use -X PUT or -X DELETE when you want the explicit PUT or DELETE semantics.Links and References
- Prometheus Pushgateway (GitHub): https://github.com/prometheus/pushgateway
- Prometheus exposition formats: https://prometheus.io/docs/instrumenting/exposition_formats/
- Prometheus client libraries: https://prometheus.io/docs/instrumenting/clientlibs/