Skip to content

Commit ef63973

Browse files
committed
Add Prometheus metrics support: integrate prom-client and expose /metrics endpoint
1 parent 7875547 commit ef63973

File tree

3 files changed

+48
-3
lines changed

3 files changed

+48
-3
lines changed

app.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ const bodyParser = require('body-parser');
55
const mongoose = require("mongoose");
66
const app = express();
77
const cors = require('cors')
8-
8+
const client = require('prom-client');
9+
client.collectDefaultMetrics();
910

1011
app.use(bodyParser.json());
1112
app.use(express.static(path.join(__dirname, '/')));
@@ -83,5 +84,10 @@ app.listen(3000, () => {
8384
console.log("Server successfully running on port - " +3000);
8485
})
8586

87+
app.get('/metrics', async (req, res) => {
88+
res.set('Content-Type', client.register.contentType);
89+
res.end(await client.register.metrics());
90+
});
91+
8692

8793
module.exports = app;

package-lock.json

Lines changed: 39 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"express": "^4.18.2",
1919
"mocha-junit-reporter": "^2.2.1",
2020
"mongoose": "5.13.20",
21-
"nyc": "^15.1.0"
21+
"nyc": "^15.1.0",
22+
"prom-client": "^15.1.3"
2223
},
2324
"devDependencies": {
2425
"chai": "*",

0 commit comments

Comments
 (0)