Skip to content
Branch: master
Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

OpenCensus Prometheus Stats Exporter

The OpenCensus Prometheus Stats Exporter is a stats exporter that exports data to Prometheus. Prometheus is an open-source systems monitoring and alerting toolkit originally built at SoundCloud.



To use this exporter, you need to install, configure and start Prometheus first. Follow the instructions here.

Hello "Prometheus Stats"

Add the dependencies to your project

For Maven add to your pom.xml:


For Gradle add to your dependencies:

compile 'io.opencensus:opencensus-api:0.19.2'
compile 'io.opencensus:opencensus-exporter-stats-prometheus:0.19.2'
runtime 'io.opencensus:opencensus-impl:0.19.2'

Register the exporter

public class MyMainClass {
  public static void main(String[] args) {
    // Creates a PrometheusStatsCollector and registers it to the default Prometheus registry.
    // Uses a simple Prometheus HTTPServer to export metrics. 
    // You can use a Prometheus PushGateway instead, though that's discouraged by Prometheus:
    io.prometheus.client.exporter.HTTPServer server = 
      new HTTPServer(/*host*/ "localhost", /*port*/  9091, /*daemon*/ true);
    // Your code here.
    // ...

In this example, you should be able to see all the OpenCensus Prometheus metrics by visiting localhost:9091/metrics. Every time when you visit localhost:9091/metrics, the metrics will be collected from OpenCensus library and refreshed.


After collecting stats from OpenCensus, there are multiple options for exporting them. See Exporting via HTTP, Exporting to a Pushgateway and Bridges.

Java Versions

Java 7 or above is required for using this exporter.


You can’t perform that action at this time.