title: Using Prometheus PushGateway with OpenCensus Java Client
body: <p>I've got a CronJob running that I'd like to integrate OpenCensus into to export to Prometheus. However I currently have to add a 1 minute sleep after my job finishes to make sure that Prometheus has scraped my metrics.</p>
  
  <p>I'd like to use the Prometheus PushGateway to avoid the extra sleep if possible, but I can't figure out how to hook it up to OpenCensus.</p>
  
  <p>Here's the documentation for it that mentions it: <a href="https://github.com/census-instrumentation/opencensus-java/tree/master/exporters/stats/prometheus" rel="nofollow noreferrer">https://github.com/census-instrumentation/opencensus-java/tree/master/exporters/stats/prometheus</a> - it says the following:</p>
  
  <pre class="lang-java prettyprint-override"><code>public class MyMainClass {
    public static void main(String[] args) {
      // Creates a PrometheusStatsCollector and registers it to the default Prometheus registry.
      PrometheusStatsCollector.createAndRegister();
  
      // Uses a simple Prometheus HTTPServer to export metrics. 
      // You can use a Prometheus PushGateway instead, though that's discouraged by Prometheus:
      // https://prometheus.io/docs/practices/pushing/#should-i-be-using-the-pushgateway.
      io.prometheus.client.exporter.HTTPServer server = 
        new HTTPServer(/*host*/ "localhost", /*port*/  9091, /*daemon*/ true);
  
      // Your code here.
      // ...
    }
  }
  </code></pre>
  
  <p>However there's no examples of how I actually would use it with OpenCensus. Has anyone done it before, and how?</p>