From a029f1510518dbebef35da8e485b05c0ea51e2da Mon Sep 17 00:00:00 2001 From: wkadmin Date: Tue, 21 Oct 2025 17:13:21 +0000 Subject: [PATCH] Ajouter index.js --- index.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 index.js diff --git a/index.js b/index.js new file mode 100644 index 00000000..565fbf08 --- /dev/null +++ b/index.js @@ -0,0 +1,31 @@ +import express from 'express'; +import client from 'prom-client'; + +const app = express(); +const collectDefaultMetrics = client.collectDefaultMetrics; +collectDefaultMetrics({ prefix: 'thetiptop_' }); + +// Exemple de compteur HTTP +const httpRequestCounter = new client.Counter({ + name: 'thetiptop_http_requests_total', + help: 'Nombre total de requêtes HTTP', + labelNames: ['method', 'route', 'status_code'] +}); + +app.use((req, res, next) => { + res.on('finish', () => { + httpRequestCounter.inc({ + method: req.method, + route: req.route ? req.route.path : req.path, + status_code: res.statusCode + }); + }); + next(); +}); + +app.get('/metrics', async (req, res) => { + res.set('Content-Type', client.register.contentType); + res.end(await client.register.metrics()); +}); + +app.listen(4000, () => console.log('Backend en écoute sur le port 4000'));