forked from open-telemetry/opentelemetry-js-contrib
-
Notifications
You must be signed in to change notification settings - Fork 1
/
node.js
35 lines (29 loc) · 949 Bytes
/
node.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
'use strict';
const { HostMetrics } = require('@opentelemetry/host-metrics');
// const { PrometheusExporter } = require('@opentelemetry/exporter-prometheus');
const { MeterProvider } = require('@opentelemetry/sdk-metrics-base');
const { CollectorMetricExporter } = require('@opentelemetry/exporter-collector');
const exporter = new CollectorMetricExporter({
headers: {},
serviceName: 'test-host-metrics',
// url: '',
});
// for testing purposes if you don't want to use CollectorMetricExporter
// const exporter = new PrometheusExporter(
// {
// startServer: true,
// },
// () => {
// console.log('prometheus scrape endpoint: http://localhost:9464/metrics');
// },
// );
const meterProvider = new MeterProvider({
exporter,
interval: 2000,
});
const hostMetrics = new HostMetrics({ meterProvider, name: 'example-host-metrics' });
hostMetrics.start();
// keep running
(function wait() {
setTimeout(wait, 1000);
}());