-
Notifications
You must be signed in to change notification settings - Fork 0
/
metrics.js
36 lines (30 loc) · 1.09 KB
/
metrics.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
import { MeterProvider } from "@opentelemetry/sdk-metrics";
import { PrometheusExporter } from "@opentelemetry/exporter-prometheus";
// Define a configuration object to organize configuration values
const config = {
port: 9464,
meterName: "hub-uploads",
histogramConfig: {
name: "hub_uploads_upload_time_milliseconds",
description: "Time in milliseconds for a file upload",
unit: "ms",
boundaries: [100, 200, 400, 800, 1600],
labelKeys: ["status"],
},
};
// Export a Metrics object to encapsulate initialization and the exporter
const Metrics = {
exporter: new PrometheusExporter({ port: config.port }),
initialize() {
const meterProvider = new MeterProvider();
meterProvider.addMetricReader(this.exporter);
const meter = meterProvider.getMeter(config.meterName);
const FileUploadTime = meter.createHistogram(config.histogramConfig.name, {
description: config.histogramConfig.description,
unit: config.histogramConfig.unit,
boundaries: config.histogramConfig.boundaries,
});
return { meter, FileUploadTime };
},
};
export default Metrics;