opentelemetry-js/packages/opentelemetry-metrics
Mayur Kale 1ef341070c
Code cleanup (#664)
* chore: remove unused MetricProducerManager & MetricProducer

* fix: typos
2020-01-07 09:46:34 -08:00
..
src Code cleanup (#664) 2020-01-07 09:46:34 -08:00
test chore: rename Metric Handle to Bound Instrument (#634) (#638) 2020-01-03 12:14:58 -08:00
.npmignore Create opentelemetry metrics package (#297) 2019-09-20 18:41:22 +02:00
LICENSE Create opentelemetry metrics package (#297) 2019-09-20 18:41:22 +02:00
README.md chore: rename Metric Handle to Bound Instrument (#634) (#638) 2020-01-03 12:14:58 -08:00
package.json chore: 0.3.2 (patch) release proposal (#659) 2020-01-03 12:27:10 -08:00
tsconfig.json Create opentelemetry metrics package (#297) 2019-09-20 18:41:22 +02:00
tslint.json Create opentelemetry metrics package (#297) 2019-09-20 18:41:22 +02:00

README.md

OpenTelemetry Metrics SDK

Gitter chat NPM Published Version dependencies devDependencies Apache License

OpenTelemetry metrics allow a user to collect data and export it to a metrics backend like Prometheus.

Installation

npm install --save @opentelemetry/metrics

Usage

Counter

Choose this kind of metric when the value is a quantity, the sum is of primary interest, and the event count and value distribution are not of primary interest. Counters are defined as Monotonic = true by default, meaning that positive values are expected.

const { Meter } = require('@opentelemetry/metrics');

// Initialize the Meter to capture measurements in various ways.
const meter = new Meter();

const counter = meter.createCounter('metric_name', {
  labelKeys: ["pid"],
  description: "Example of a counter"
});

const labels = meter.labels({ pid: process.pid });

// Create a BoundInstrument associated with specified label values.
const boundCounter = counter.bind(labels);
boundCounter.add(10);

Gauge

Gauge metrics express a pre-calculated value. Generally, this kind of metric should be used when the metric cannot be expressed as a sum or because the measurement interval is arbitrary. Use this kind of metric when the measurement is not a quantity, and the sum and event count are not of interest. Gauges are defined as Monotonic = false by default, meaning that new values are permitted to make positive or negative changes to the gauge. There is no restriction on the sign of the input for gauges.

const { Meter } = require('@opentelemetry/metrics');

// Initialize the Meter to capture measurements in various ways.
const meter = new Meter();

const gauge = meter.createGauge('metric_name', {
  labelKeys: ["pid"],
  description: "Example of a gauge"
});

const labels = meter.labels({ pid: process.pid });

// Create a BoundInstrument associated with specified label values.
const boundGauge = gauge.bind(labels);
boundGauge.set(10); // Set to 10

See examples/prometheus for a short example.

Measure

Work in progress

License

Apache 2.0 - See LICENSE for more information.