Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update prometheus exporter readme with usage and links #521

Merged
merged 2 commits into from
Nov 14, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 51 additions & 2 deletions packages/opentelemetry-exporter-prometheus/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,58 @@
[![devDependencies][devDependencies-image]][devDependencies-url]
[![Apache License][license-image]][license-image]

OpenTelemetry Exporter Prometheus provides a metrics endpoint for Prometheus.
The OpenTelemetry Prometheus Metrics Exporter allows the user to send collected [OpenTelemetry Metrics](https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-metrics) to Prometheus.

**Work in progress**
[Prometheus](https://prometheus.io/) is a monitoring system that collects metrics, by scraping exposed endpoints at regular intervals, evaluating rule expressions. It can also trigger alerts if certain conditions are met. For assistance setting up Prometheus, [Click here](https://opencensus.io/codelabs/prometheus/#0) for a guided codelab.

## Installation

```bash
npm install --save @opentelemetry/metrics
npm install --save @opentelemetry/exporter-prometheus
```

## Usage

Create & register the exporter on your application.

```js
const { PrometheusExporter } = require('@opentelemetry/exporter-prometheus');
const { Meter } = require('@opentelemetry/metrics');

// Add your port and startServer to the Prometheus options
const options = {port: 9464, startServer: true};
const exporter = new PrometheusExporter(options);

// Register the exporter
const meter = new Meter();
meter.addExporter(exporter);

// Now, start recording data
const counter = meter.createCounter('metric_name');
counter.add(10, meter.labels({ [key]: 'value' }));

// Record data using Handle: It is recommended to keep a reference to the Handle instead of
// always calling `getHandle()` method for every operations.
const handle = counter.getHandle(meter.labels({ [key]: 'value' }));
handle.add(10);

// .. some other work

// Create and record Gauge
const gauge = meter.createGauge('metric_name1');
gauge.set(10, meter.labels({ [key1]: 'value1' }));
```

## Viewing your metrics

With the above you should now be able to navigate to the Prometheus UI at: http://localhost:9464/metrics

## Useful links
- For more information on OpenTelemetry, visit: <https://opentelemetry.io/>
- To learn more about Prometheus, visit: https://prometheus.io/
- For more about OpenTelemetry JavaScript: <https://github.com/open-telemetry/opentelemetry-js>
- For help or feedback on this project, join us on [gitter][gitter-url]

## License

Expand Down