forked from Colm3na/polkastats-backend-v3
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathprometheus.js
More file actions
52 lines (38 loc) · 1.02 KB
/
prometheus.js
File metadata and controls
52 lines (38 loc) · 1.02 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
46
47
48
49
50
51
52
const {
prometheusPort
} = require('./config/config');
const http = require('http');
const url = require('url');
const client = require('prom-client');
// Create a Registry which registers the metrics
const register = new client.Registry();
register.setDefaultLabels({
app: 'crawler'
})
client.collectDefaultMetrics({
register
})
const server = http.createServer(async (req, res) => {
const route = url.parse(req.url).pathname;
if (route === '/metrics') {
res.setHeader('Content-Type', register.contentType)
res.write(await register.metrics());
res.end();
} else {
res.end('Crawler server');
}
})
function startServer(callback) {
server.listen(prometheusPort, callback);
}
module.exports = {
startServer
}
/*const server = http.createServer(async (req, res) => {
console.log('start server');
if (route === '/metrics') {
// Return all metrics the Prometheus exposition format
res.setHeader('Content-Type', register.contentType)
res.end(register.metrics())
}
})*/