-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
36 lines (30 loc) · 916 Bytes
/
index.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
import * as dotenv from 'dotenv'
import express from 'express';
import { collectDefaultMetrics, register } from 'prom-client';
dotenv.config()
collectDefaultMetrics({
labels: { nodename: process.env.NODE_NAME },
});
const app = express();
app.get('/', (req, res) => {
res.set('Content-Type', 'text/html');
res.send([
'<html>',
'<head><title>NodeJS Prom Exporter</title></head>',
'<body>',
'<h1>NodeJS Prom Exporter</h1>',
'<p><a href="/metrics">Metrics</a></p>',
'</body>',
'</html>'
].join('\n'));
})
app.get('/metrics', async (_req, res) => {
try {
res.set('Content-Type', register.contentType);
res.end(await register.metrics());
} catch (err) {
res.status(500).end(err);
}
});
app.listen(process.env.APP_PORT || 4001, '0.0.0.0');
console.log('App running on port ' + process.env.APP_PORT || 4001);