-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.ts
executable file
·56 lines (48 loc) · 1.69 KB
/
app.ts
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
#!/usr/bin/env node
// For troubleshooting, set the log level to DiagLogLevel.DEBUG
import { diag, DiagConsoleLogger, DiagLogLevel } from '@opentelemetry/api';
diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.INFO);
import {OTLPMetricExporter} from "@opentelemetry/exporter-metrics-otlp-proto";
import {PeriodicExportingMetricReader, MeterProvider} from "@opentelemetry/sdk-metrics";
import {HostMetrics} from '@opentelemetry/host-metrics';
function main() {
var argv = require('minimist')(process.argv.slice(2));
const dbHost = argv.host || 'localhost'
const db = argv.db || 'public'
const username = argv.username
const password = argv.password
const endpoint = argv.endpoint
const port = argv.port
var url = ''
if (endpoint != '') {
url = endpoint
} else {
url = `https://`
url += `${dbHost}`
if (port) {
url += `:${port}`
}
url += `/v1/otlp/v1/metrics`
}
const auth = Buffer.from(`${username}:${password}`).toString('base64')
const metricReader = new PeriodicExportingMetricReader({
exporter: new OTLPMetricExporter({
url: url,
headers: {
Authorization: `Basic ${auth}`,
"x-greptime-db-name": db,
},
timeoutMillis: 5000,
}),
exportIntervalMillis: 5000,
})
const meterProvider = new MeterProvider();
meterProvider.addMetricReader(metricReader);
const hostMetrics = new HostMetrics({ meterProvider, name: 'quick-start-demo-node' });
hostMetrics.start();
console.log('Sending metrics...')
setInterval(() => {}, 1000);
}
if (require.main === module) {
main();
}