Package Exports
- @opentelemetry/exporter-prometheus
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@opentelemetry/exporter-prometheus) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
OpenTelemetry Prometheus Metric Exporter
The OpenTelemetry Prometheus Metrics Exporter allows the user to send collected OpenTelemetry Metrics to Prometheus.
Prometheus 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 for a guided codelab.
Installation
npm install --save @opentelemetry/metrics
npm install --save @opentelemetry/exporter-prometheusUsage
Create & register the exporter on your application.
const { PrometheusExporter } = require('@opentelemetry/exporter-prometheus');
const { MeterProvider } = 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 MeterProvider({
exporter,
interval: 1000,
}).getMeter('example-prometheus');
// Now, start recording data
const counter = meter.createCounter('metric_name', {
description: 'Example of a counter'
});
counter.add(10, { pid: process.pid });
// Record data using Instrument: It is recommended to keep a reference to the Bound Instrument instead of
// always calling `bind()` method for every operations.
const boundCounter = counter.bind({ pid: process.pid });
boundCounter.add(10);
// .. some other workViewing 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 in GitHub Discussions
License
Apache 2.0 - See LICENSE for more information.