diff --git a/src/metrics.ts b/src/metrics.ts index f11513b89d1c9678aafe4c717536e4c8013ada49..775dc8d7cff97219b711f6cfa7418dbf11110643 100644 --- a/src/metrics.ts +++ b/src/metrics.ts @@ -15,7 +15,7 @@ limitations under the License. */ /* eslint-disable max-classes-per-file, @typescript-eslint/no-empty-function */ -import { Gauge, Counter, Histogram, default as promClient } from "prom-client"; +import { Gauge, Counter, Histogram, collectDefaultMetrics, register } from "prom-client"; import { Log } from "./log"; import { Appservice, IMetricContext, @@ -69,15 +69,16 @@ export class PrometheusBridgeMetrics implements IBridgeMetrics { private httpServer: http.Server; public init(as: Appservice, config: DiscordBridgeConfigMetrics) { - promClient.collectDefaultMetrics(); + collectDefaultMetrics(); // TODO: Bind this for every user. this.httpServer = http.createServer((req, res) => { if (req.method !== "GET" || req.url !== "/metrics") { res.writeHead(404, "Not found"); res.end(); + return; } - res.writeHead(200, "OK", {"Content-Type": promClient.register.contentType}); - res.write(promClient.register.metrics()); + res.writeHead(200, "OK", {"Content-Type": register.contentType}); + res.write(register.metrics()); res.end(); }); this.matrixCallCounter = new Counter({ @@ -85,41 +86,41 @@ export class PrometheusBridgeMetrics implements IBridgeMetrics { labelNames: ["method", "result"], name: "matrix_api_calls", }); - promClient.register.registerMetric(this.matrixCallCounter); + register.registerMetric(this.matrixCallCounter); this.remoteCallCounter = new Counter({ help: "Count of remote API calls made", labelNames: ["method"], name: "remote_api_calls", }); - promClient.register.registerMetric(this.remoteCallCounter); + register.registerMetric(this.remoteCallCounter); this.storeCallCounter = new Counter({ help: "Count of store function calls made", labelNames: ["method", "cached"], name: "store_calls", }); - promClient.register.registerMetric(this.storeCallCounter); + register.registerMetric(this.storeCallCounter); this.presenceGauge = new Gauge({ help: "Count of users in the presence queue", name: "active_presence_users", }); - promClient.register.registerMetric(this.presenceGauge); + register.registerMetric(this.presenceGauge); this.matrixRequest = new Histogram({ help: "Histogram of processing durations of received Matrix messages", labelNames: ["outcome"], name: "matrix_request_seconds", }); - promClient.register.registerMetric(this.matrixRequest); + register.registerMetric(this.matrixRequest); this.remoteRequest = new Histogram({ help: "Histogram of processing durations of received remote messages", labelNames: ["outcome"], name: "remote_request_seconds", }); - promClient.register.registerMetric(this.remoteRequest); + register.registerMetric(this.remoteRequest); this.requestsInFlight = new Map(); setInterval(() => {