Pushing metric to prometheus with Pushgateway

kubernetes prometheus Pushgateway

2 min read | by Jordi Prats

Prometheus Pushgateway is a component of the Prometheus monitoring system that allows for the collection of time-series data that cannot be scraped: It allows you to push metrics instead of having to wait for prometheus to scrape them

This can be useful in situations where the generation of metrics are irregular, or where the metric cannot be accessed by Prometheus through the usual scraping mechanism. With the Pushgateway we'll get as a buffer between the metric source and Prometheus.

Installing Prometheus Pushgateway

To install Prometheus Pushgateway in a Kubernetes cluster, we can use helm.

First we'll nee to install the prometheus-community repository:

helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo update

Once we have it, we can install the pushgateway with helm install as follows:

helm install pushgateway prometheus-community/prometheus-pushgateway -n prometheus

Pushing Metrics to Prometheus Pushgateway

To push metrics to Prometheus Pushgateway, you can use the HTTP API that it exposes:

echo "some_metric 42" | curl --data-binary @- http://pushgateway-service:9091/metrics/job/some_job

In this example, we are pushing a metric called some_metric (42) with the job label set to some_job.

Posted on 15/08/2023