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.
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.
Here's the documentation for it that mentions it: https://github.com/census-instrumentation/opencensus-java/tree/master/exporters/stats/prometheus - it says the following:
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.
// ...
}
}
However there's no examples of how I actually would use it with OpenCensus. Has anyone done it before, and how?