Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
@opentelemetry/exporter-prometheus
Advanced tools
OpenTelemetry Exporter Prometheus provides a metrics endpoint for Prometheus
@opentelemetry/exporter-prometheus is an npm package that allows you to export OpenTelemetry metrics to Prometheus. It provides a way to expose metrics collected by OpenTelemetry to be scraped by a Prometheus server.
Setup Prometheus Exporter
This code sets up a Prometheus exporter that starts an HTTP server on port 9464 to expose metrics. It creates a meter provider and a counter metric, which is then incremented by 10.
const { PrometheusExporter } = require('@opentelemetry/exporter-prometheus');
const { MeterProvider } = require('@opentelemetry/sdk-metrics-base');
const exporter = new PrometheusExporter({
startServer: true,
}, () => {
console.log('Prometheus scrape endpoint: http://localhost:9464/metrics');
});
const meterProvider = new MeterProvider({
exporter,
interval: 1000,
});
const meter = meterProvider.getMeter('example-meter');
const counter = meter.createCounter('example_counter', {
description: 'An example counter',
});
counter.add(10, { key: 'value' });
Customizing Exporter Options
This code demonstrates how to customize the Prometheus exporter options, such as changing the port and endpoint for the metrics server.
const { PrometheusExporter } = require('@opentelemetry/exporter-prometheus');
const { MeterProvider } = require('@opentelemetry/sdk-metrics-base');
const exporter = new PrometheusExporter({
port: 8080,
endpoint: '/custom-metrics',
startServer: true,
}, () => {
console.log('Prometheus scrape endpoint: http://localhost:8080/custom-metrics');
});
const meterProvider = new MeterProvider({
exporter,
interval: 1000,
});
const meter = meterProvider.getMeter('example-meter');
const counter = meter.createCounter('example_counter', {
description: 'An example counter',
});
counter.add(10, { key: 'value' });
prom-client is a Prometheus client for Node.js that allows you to create and expose metrics to be scraped by a Prometheus server. Unlike @opentelemetry/exporter-prometheus, which integrates with OpenTelemetry, prom-client is a standalone library specifically for Prometheus.
prometheus-api-metrics is a middleware for Express.js that automatically collects and exposes metrics for HTTP requests. It is more focused on web server metrics and does not provide the broader OpenTelemetry integration that @opentelemetry/exporter-prometheus offers.
prometheus-gc-stats is a library that collects garbage collection metrics from Node.js and exposes them to Prometheus. It is specialized for GC metrics, whereas @opentelemetry/exporter-prometheus can handle a wider range of metrics through OpenTelemetry.
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.
npm install --save @opentelemetry/metrics
npm install --save @opentelemetry/exporter-prometheus
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 work
With the above you should now be able to navigate to the Prometheus UI at: http://localhost:9464/metrics
Apache 2.0 - See LICENSE for more information.
FAQs
OpenTelemetry Exporter Prometheus provides a metrics endpoint for Prometheus
The npm package @opentelemetry/exporter-prometheus receives a total of 256,256 weekly downloads. As such, @opentelemetry/exporter-prometheus popularity was classified as popular.
We found that @opentelemetry/exporter-prometheus demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.