-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
45 lines (37 loc) · 1.07 KB
/
index.js
File metadata and controls
45 lines (37 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const express = require("express");
const client = require("prom-client");
const app = express();
const collectDefaultMetrics = client.collectDefaultMetrics;
// Probe every 5th second.
collectDefaultMetrics({ timeout: 5000 });
const counter = new client.Counter({
name: "node_request_operations_total",
help: "The total number of processed requests",
});
const histogram = new client.Histogram({
name: "node_request_duration_seconds",
help: "Histogram of request durations in seconds",
buckets: [0.1, 0.5, 1, 1.5, 2, 2.5, 3],
});
app.get("/", (req, res) => {
counter.inc();
const end = histogram.startTimer();
res.send("Hello World");
end();
});
app.get("/metrics", async (req, res) => {
res.set("Content-Type", client.register.contentType);
try {
const metrics = await client.register.metrics();
res.end(metrics);
} catch (err) {
res.status(500).end(err.message);
}
});
const PORT = process.env.PORT || 3000;
if (require.main === module) {
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});
}
module.exports = app;