You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
OpenTelemetry metrics allow a user to collect data and export it to a metrics backend like [Prometheus](https://prometheus.io/).
9
+
10
+
## Installation
11
+
12
+
```bash
13
+
npm install --save @opentelemetry/metrics
14
+
```
15
+
16
+
## Usage
17
+
18
+
### Counter
19
+
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.
20
+
21
+
```js
22
+
const { Meter } =require('@opentelemetry/metrics');
23
+
24
+
// Initialize the Meter to capture measurements in various ways.
25
+
constmeter=newMeter();
26
+
27
+
constcounter=meter.createCounter('metric_name', {
28
+
labelKeys: ["pid"],
29
+
description:"Example of a counter"
30
+
});
31
+
32
+
constlabels=meter.labels({ pid:process.pid });
33
+
34
+
// Create a Handle associated with specified label values.
35
+
consthandle=counter.getHandle(labels);
36
+
handle.add(10);
37
+
```
38
+
39
+
### Gauge
40
+
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.
41
+
42
+
```js
43
+
const { Meter } =require('@opentelemetry/metrics');
44
+
45
+
// Initialize the Meter to capture measurements in various ways.
46
+
constmeter=newMeter();
47
+
48
+
constgauge=meter.createGauge('metric_name', {
49
+
labelKeys: ["pid"],
50
+
description:"Example of a gauge"
51
+
});
52
+
53
+
constlabels=meter.labels({ pid:process.pid });
54
+
55
+
// Create a Handle associated with specified label values.
56
+
consthandle=gauge.getHandle(labels);
57
+
handle.set(10); // Set to 10
58
+
```
59
+
60
+
See [examples/prometheus](https://github.com/open-telemetry/opentelemetry-js/tree/master/examples/prometheus) for a short example.
61
+
62
+
### Measure
63
+
***Work in progress***
64
+
65
+
## Useful links
66
+
- For more information on OpenTelemetry, visit: <https://opentelemetry.io/>
67
+
- For more about OpenTelemetry JavaScript: <https://github.com/open-telemetry/opentelemetry-js>
68
+
- For help or feedback on this project, join us on [gitter][gitter-url]
8
69
9
70
## License
10
71
@@ -18,3 +79,5 @@ Apache 2.0 - See [LICENSE][license-url] for more information.
0 commit comments