Skip to content
This repository was archived by the owner on Oct 3, 2023. It is now read-only.

Commit bf85a7b

Browse files
authored
exporter/prometheus/README: should be a Stats exporter, not Tracing. (#204)
1 parent 5fe3b38 commit bf85a7b

2 files changed

Lines changed: 46 additions & 21 deletions

File tree

Lines changed: 44 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# OpenCensus Prometheus Exporter for Node.js
2-
[![Gitter chat][gitter-image]][gitter-url]
2+
[![Gitter chat][gitter-image]][gitter-url] ![Node Version][node-img] [![NPM Published Version][npm-img]][npm-url]
33

44
The OpenCensus Prometheus Exporter allows the user to send collected stats with [OpenCensus Node.js](https://github.com/census-instrumentation/opencensus-node) to Prometheus.
55

@@ -9,43 +9,60 @@ This package is still at an early stage of development, and is subject to change
99

1010
Install OpenCensus Prometheus Exporter with:
1111
```bash
12-
npm install @opencensus/nodejs
12+
npm install @opencensus/core
1313
npm install @opencensus/exporter-prometheus
1414
```
1515

1616
## Usage
1717

18-
Instance the exporter on your application. For javascript:
18+
Instance the exporter on your application.
1919

20+
For javascript:
2021
```javascript
21-
var tracing = require('@opencensus/nodejs');
22-
var prometheus = require('@opencensus/exporter-prometheus');
22+
const { Stats } = require('@opencensus/core');
23+
const { PrometheusStatsExporter } = require('@opencensus/exporter-prometheus');
24+
25+
// Add your port and startServer to the Prometheus options
26+
const exporter = new PrometheusStatsExporter({
27+
port: 9464,
28+
startServer: false
29+
});
30+
```
2331

24-
var exporter = new prometheus.PrometheusTraceExporter();
32+
Now, register the exporter.
2533

26-
tracing.registerExporter(exporter).start();
27-
```
34+
```javascript
35+
// Our Stats manager
36+
const stats = new Stats();
2837

29-
Similarly for Typescript:
38+
// Pass the created exporter to Stats
39+
stats.registerExporter(exporter);
3040

41+
// Run the server
42+
exporter.startServer(function callback() {
43+
// Callback
44+
});
45+
```
46+
47+
Similarly for Typescript (Since the source is written in TypeScript):
3148
```typescript
32-
import * as tracing from '@opencensus/nodejs';
33-
import { PrometheusTraceExporter } from '@opencensus/exporter-prometheus';
49+
import { PrometheusStatsExporter } from '@opencensus/exporter-prometheus';
50+
import { Stats } from '@opencensus/core';
3451

35-
const exporter = new PrometheusTraceExporter();
36-
```
52+
// Add your port and startServer to the Prometheus options
53+
const options = {port: 9464, startServer: false};
54+
const exporter = new PrometheusStatsExporter(options);
3755

38-
Now, register the exporter and start tracing.
56+
// Our Stats manager
57+
const stats = new Stats();
3958

40-
```javascript
41-
tracing.start({'exporter': exporter});
59+
// Pass the created exporter to Stats
60+
stats.registerExporter(exporter);
4261
```
4362

44-
or
63+
Viewing your metrics:
4564

46-
```javascript
47-
tracing.registerExporter(exporter).start();
48-
```
65+
With the above you should now be able to navigate to the Prometheus UI at: <http://localhost:9464/metrics>
4966

5067
## Useful links
5168
- To learn more about Prometheus, visit: <https://prometheus.io/>
@@ -55,3 +72,10 @@ tracing.registerExporter(exporter).start();
5572

5673
[gitter-image]: https://badges.gitter.im/census-instrumentation/lobby.svg
5774
[gitter-url]: https://gitter.im/census-instrumentation/lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge
75+
[npm-url]: https://www.npmjs.com/package/@opencensus/exporter-prometheus
76+
[npm-img]: https://badge.fury.io/js/%40opencensus%2Fexporter-prometheus.svg
77+
[node-img]: https://img.shields.io/node/v/@opencensus/exporter-prometheus.svg
78+
79+
## LICENSE
80+
81+
Apache License 2.0

packages/opencensus-exporter-prometheus/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"keywords": [
1919
"opencensus",
2020
"nodejs",
21-
"tracing",
21+
"metrics",
22+
"stats",
2223
"profiling"
2324
],
2425
"author": "Google Inc.",

0 commit comments

Comments
 (0)