forked from open-telemetry/opentelemetry-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
55 lines (46 loc) · 1.57 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
"use strict";
const { Meter } = require("@opentelemetry/metrics");
const { PrometheusExporter } = require("@opentelemetry/exporter-prometheus");
const meter = new Meter();
const exporter = new PrometheusExporter(
{
startServer: true
},
() => {
console.log("prometheus scrape endpoint: http://localhost:9464/metrics");
}
);
meter.addExporter(exporter);
// Monotonic counters and gauges can only be increased.
const monotonicCounter = meter.createCounter("monotonic_counter", {
monotonic: true,
labelKeys: ["pid"],
description: "Example of a monotonic counter"
});
const monotonicGauge = meter.createGauge("monotonic_gauge", {
monotonic: true,
labelKeys: ["pid"],
description: "Example of a monotonic gauge"
});
// Non-monotonic counters and gauges can be increased or decreased.
const nonMonotonicCounter = meter.createCounter("non_monotonic_counter", {
monotonic: false,
labelKeys: ["pid"],
description: "Example of a non-monotonic counter"
});
const nonMonotonicGauge = meter.createGauge("non_monotonic_gauge", {
monotonic: false,
labelKeys: ["pid"],
description: "Example of a non-monotonic gauge"
});
let currentMonotonicGaugeValue = 0;
setInterval(() => {
const labels = meter.labels({ pid: process.pid });
currentMonotonicGaugeValue += Math.random();
monotonicCounter.bind(labels).add(1);
nonMonotonicCounter.bind(labels).add(Math.random() > 0.5 ? 1 : -1);
monotonicGauge.bind(labels).set(currentMonotonicGaugeValue);
nonMonotonicGauge
.bind(labels)
.set(Math.random() > 0.5 ? Math.random() * 10 : -Math.random() * 10);
}, 1000);