Table of Contents
Prometheus is an amazing tool, but it has limitations. Some of your applications, including batch jobs and ephemeral jobs, may not live long enough for it to find and scrape them.
Since Prometheus cannot scrape all jobs, the company developed Pushgateway as a bridge tool. Because you usually cannot push metrics directly to the Prometheus application, you can sometimes use a Pushgateway to deliver the necessary data.
When you need monitoring solutions, try Metricfire. You’ll learn about the best open source applications around, including Pushgateway for Prometheus. Visit the website today for a free trial and demo.
What is Pushgateway?
Pushgateway is a feature of Prometheus that allows ephemeral and batch jobs to expose their metrics to the application. Often, these types of jobs do not have a long enough lifecycle for software programs to scrape them and pull the vast amount of metrics necessary for effective network monitoring.
Instead, you can push your metrics to a Pushgateway that, in turn, exposes the metrics to Prometheus. Consider Pushgateway the middleman in metrics collection. You can push your short-lived batch and ephemeral jobs onto Pushgateway, using it as a metrics cache that then allows Prometheus to scrape them, even when the monitored subjects no longer exist.
This process differs from Prometheus' pull metrics application. With Pushgateway, your metrics series is continually exposed to Prometheus unless someone manually deletes it using Pushgateway's API. When Prometheus uses pull model metrics, it only has access to those instances that still exist. This application has client libraries for Go, Java, Scala, Python, and Ruby, making it useful for a wide audience.
What Are the Use-Cases of Pushgateway?
Pushgateway is not the answer for all your short lifecycle jobs. Prometheus warns users that Pushgateway only works well in specific circumstances, particularly for service-level batch jobs such as deleting the data of users that have requested to be deleted (the right to be forgotten).
Jobs that delete temporary files are not serviced batch jobs because they are tied to a long-living subject - the machine they run on. Exposing metrics for those jobs is best done by a node exporter or other method.
For the node exporter, use:
tar -xzvf node_exporter-*.*.tar.gz cd node_exporter-*.* # Start 3 example targets in separate terminals: ./node_exporter --web.listen-address 127.0.0.1:8080 ./node_exporter --web.listen-address 127.0.0.1:8081 ./node_exporter --web.listen-address 127.0.0.1:8082
Reminder: the file pattern can be a path ending in j.son, yaml and yml.
Pushgateway Benefits and Challenges
Prometheus offers alternative strategies for when an inbound firewall or NAT prevents you from pulling metrics. For instance, you can move the Prometheus server behind the network barrier. Pushgateway is a valuable tool that is effective in limited situations. You cannot use it for all jobs whose metrics Prometheus cannot scrape. You can perform the following tasks with a Pushgateway:
- Send metrics - Through a program that can perform web requests or by using a client library.
- Scrape metrics - Often by statistically defining a Pushgateway target with scrape-configs.
- Delete metrics - By clicking near the group of metrics in the UI, By the wipe end-point on the admin API, and by making an HTTP request with the verb DELETE.
- Alert on metrics - informing you when someone tries to push inconsistent metrics, the Pushgateway has been pushing metrics in the expected timeframe, and when there is a Pushgateway shutdown.
Although Pushgateway has some consistency issues, exposing all pushed metrics together with its own metrics by using the same /metrics endpoint, it can save your metrics to disk for a defined time period by using the parameters "persistence.file= and --persistence.interval=.
You will need to have some mounted-storage writable by one now to serve the traffic and the other that have persistent storage mounted as read-only. For those using Kubernetes, you can manage this task with a persistent volume claim with the mode ReadWriteOnce. You do have several options for making Pushgateway your metrics cache.
By using the configured --web.telemetry-path (default: /metrics, you will expose the following metrics:
- Pushed metrics
- Metric push-time-seconds and push-failure-time-second
- Metrics provided by Prometheus Go client library
- Specific metrics for Pushgateway such as # HELP pushgateway_build_info A metric with a constant '1' value labeled by version, revision, branch, and goversion from which pushgateway was built, and # TYPE pushgateway_build_info gauge.
Although this application has a very specific purpose, it can be an invaluable tool for a wide range of companies. To get started, just download the latest version of Prometheus and then extract it and run it using tar xvfz prometheus-*.tar.gz cd prometheus-*
How Can MetricFire Help?
MetricFire offers you their expertise with the most advanced open source monitoring tools for your website. Hosted Prometheus monitoring offers durable remote storage and easy team access. At MetricFire, they can help you effectively use the monitoring and metric pushing tools at your disposal, including Prometheus Pushgateway.
Pushing metrics through this application can solve your metrics exposure problem with minimum effort. Their team can also help you with Pushgateway authentication, Prometheus static-configs, job labels and other factors that can make metric exposure challenging. You will also enjoy hosted Graphite monitoring and Grafana dashboards.