Adding Prometheus metrics
This commit adds a '/metrics' endpoint in the API that can be exploited by Prometheus. This endpoint returns: - the number of connected sockets - the number of users per room - common NodeJS and system metrics WARNING: this endpoint is public right now and should be protected
This commit is contained in:
parent
bdb01f3103
commit
af6924a27c
6 changed files with 66 additions and 5 deletions
20
back/src/Controller/PrometheusController.ts
Normal file
20
back/src/Controller/PrometheusController.ts
Normal file
|
@ -0,0 +1,20 @@
|
|||
import {Application, Request, Response} from "express";
|
||||
import {IoSocketController} from "_Controller/IoSocketController";
|
||||
const register = require('prom-client').register;
|
||||
const collectDefaultMetrics = require('prom-client').collectDefaultMetrics;
|
||||
|
||||
export class PrometheusController {
|
||||
constructor(private App: Application, private ioSocketController: IoSocketController) {
|
||||
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));
|
||||
}
|
||||
|
||||
private metrics(req: Request, res: Response): void {
|
||||
res.set('Content-Type', register.contentType);
|
||||
res.end(register.metrics());
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue