-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathapp.js
43 lines (36 loc) · 896 Bytes
/
app.js
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
const express = require("express")
const http = require("http")
const app = express()
const promClient = require('prom-client');
let server
requestSuccess = new promClient.Counter({
name: "request_success",
help: "Number of successful requests"
})
requestFailed = new promClient.Counter({
name: "request_failed",
help: "Number of failed requests"
})
app.get("/", (req, res) => {
res.json({ message: `${new Date} w00t! It's working`})
requestSuccess.inc(1)
})
app.get("/fail", (req, res) => {
res.json({ message: `${new Date} Oh! It's not working`})
requestFailed.inc(1)
})
app.get("/metrics", async (req, res) => {
const metrics = await promClient.register.metrics()
res.end(metrics)
});
module.exports = {
start(cb) {
server = app.listen(8080, () => {
console.log("HTTP server listening on port 8080")
cb()
})
},
stop (cb) {
server.close(cb)
}
}