2020-09-29 09:45:47 +02:00
|
|
|
import {App} from "../Server/sifrr.server";
|
2020-06-09 11:49:23 +02:00
|
|
|
import {IoSocketController} from "_Controller/IoSocketController";
|
2020-09-29 09:45:47 +02:00
|
|
|
import {HttpRequest, HttpResponse} from "uWebSockets.js";
|
2020-06-09 11:49:23 +02:00
|
|
|
const register = require('prom-client').register;
|
|
|
|
const collectDefaultMetrics = require('prom-client').collectDefaultMetrics;
|
|
|
|
|
|
|
|
export class PrometheusController {
|
2020-09-29 09:45:47 +02:00
|
|
|
constructor(private App: App, private ioSocketController: IoSocketController) {
|
2020-06-09 11:49:23 +02:00
|
|
|
collectDefaultMetrics({
|
|
|
|
timeout: 10000,
|
|
|
|
gcDurationBuckets: [0.001, 0.01, 0.1, 1, 2, 5], // These are the default buckets.
|
|
|
|
});
|
|
|
|
|
|
|
|
this.App.get("/metrics", this.metrics.bind(this));
|
|
|
|
}
|
|
|
|
|
2020-09-29 09:45:47 +02:00
|
|
|
private metrics(res: HttpResponse, req: HttpRequest): void {
|
|
|
|
res.writeHeader('Content-Type', register.contentType);
|
2020-06-09 11:49:23 +02:00
|
|
|
res.end(register.metrics());
|
|
|
|
}
|
|
|
|
}
|