Home | History | Annotate | only in /external/opencensus-java/exporters/stats/prometheus
Up to higher level directory
NameDateSize
build.gradle22-Oct-2020527
README.md22-Oct-20202.6K
src/22-Oct-2020

README.md

      1 # OpenCensus Prometheus Stats Exporter
      2 
      3 The *OpenCensus Prometheus Stats Exporter* is a stats exporter that exports data to 
      4 Prometheus. [Prometheus](https://prometheus.io/) is an open-source systems monitoring and alerting 
      5 toolkit originally built at [SoundCloud](https://soundcloud.com/).
      6 
      7 ## Quickstart
      8 
      9 ### Prerequisites
     10 
     11 To use this exporter, you need to install, configure and start Prometheus first. Follow the 
     12 instructions [here](https://prometheus.io/docs/introduction/first_steps/).
     13 
     14 ### Hello "Prometheus Stats"
     15 
     16 #### Add the dependencies to your project
     17 
     18 For Maven add to your `pom.xml`:
     19 ```xml
     20 <dependencies>
     21   <dependency>
     22     <groupId>io.opencensus</groupId>
     23     <artifactId>opencensus-api</artifactId>
     24     <version>0.16.1</version>
     25   </dependency>
     26   <dependency>
     27     <groupId>io.opencensus</groupId>
     28     <artifactId>opencensus-exporter-stats-prometheus</artifactId>
     29     <version>0.16.1</version>
     30   </dependency>
     31   <dependency>
     32     <groupId>io.opencensus</groupId>
     33     <artifactId>opencensus-impl</artifactId>
     34     <version>0.16.1</version>
     35     <scope>runtime</scope>
     36   </dependency>
     37 </dependencies>
     38 ```
     39 
     40 For Gradle add to your dependencies:
     41 ```groovy
     42 compile 'io.opencensus:opencensus-api:0.16.1'
     43 compile 'io.opencensus:opencensus-exporter-stats-prometheus:0.16.1'
     44 runtime 'io.opencensus:opencensus-impl:0.16.1'
     45 ```
     46 
     47 #### Register the exporter
     48  
     49 ```java
     50 public class MyMainClass {
     51   public static void main(String[] args) {
     52     // Creates a PrometheusStatsCollector and registers it to the default Prometheus registry.
     53     PrometheusStatsCollector.createAndRegister();
     54     
     55     // Uses a simple Prometheus HTTPServer to export metrics. 
     56     // You can use a Prometheus PushGateway instead, though that's discouraged by Prometheus:
     57     // https://prometheus.io/docs/practices/pushing/#should-i-be-using-the-pushgateway.
     58     io.prometheus.client.exporter.HTTPServer server = 
     59       new HTTPServer(/*host*/ "localhost", /*port*/  9091, /*daemon*/ true);
     60     
     61     // Your code here.
     62     // ...
     63   }
     64 }
     65 ```
     66 
     67 In this example, you should be able to see all the OpenCensus Prometheus metrics by visiting 
     68 localhost:9091/metrics. Every time when you visit localhost:9091/metrics, the metrics will be 
     69 collected from OpenCensus library and refreshed.
     70 
     71 #### Exporting
     72 
     73 After collecting stats from OpenCensus, there are multiple options for exporting them. 
     74 See [Exporting via HTTP](https://github.com/prometheus/client_java#http), [Exporting to a Pushgateway](https://github.com/prometheus/client_java#exporting-to-a-pushgateway)
     75 and [Bridges](https://github.com/prometheus/client_java#bridges).
     76 
     77 #### Java Versions
     78 
     79 Java 7 or above is required for using this exporter.
     80 
     81 ## FAQ
     82