Class PushGateway

java.lang.Object
io.prometheus.client.exporter.PushGateway

public class PushGateway extends Object
Export metrics via the Prometheus Pushgateway.

The Prometheus Pushgateway exists to allow ephemeral and batch jobs to expose their metrics to Prometheus. Since these kinds of jobs may not exist long enough to be scraped, they can instead push their metrics to a Pushgateway. This class allows pushing the contents of a CollectorRegistry to a Pushgateway.

Example usage:

 
   void executeBatchJob() throws Exception {
     CollectorRegistry registry = new CollectorRegistry();
     Gauge duration = Gauge.build()
         .name("my_batch_job_duration_seconds").help("Duration of my batch job in seconds.").register(registry);
     Gauge.Timer durationTimer = duration.startTimer();
     try {
       // Your code here.

       // This is only added to the registry after success,
       // so that a previous success in the Pushgateway isn't overwritten on failure.
       Gauge lastSuccess = Gauge.build()
           .name("my_batch_job_last_success").help("Last time my batch job succeeded, in unixtime.").register(registry);
       lastSuccess.setToCurrentTime();
     } finally {
       durationTimer.setDuration();
       PushGateway pg = new PushGateway("127.0.0.1:9091");
       pg.pushAdd(registry, "my_batch_job");
     }
   }
 
 

See https://github.com/prometheus/pushgateway

  • Field Details

  • Constructor Details

    • PushGateway

      public PushGateway(String address)
      Construct a Pushgateway, with the given address.

      Parameters:
      address - host:port or ip:port of the Pushgateway.
    • PushGateway

      public PushGateway(URL serverBaseURL)
      Construct a Pushgateway, with the given URL.

      Parameters:
      serverBaseURL - the base URL and optional context path of the Pushgateway server.
  • Method Details