-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain.js
More file actions
82 lines (70 loc) · 1.82 KB
/
Copy pathmain.js
File metadata and controls
82 lines (70 loc) · 1.82 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
const config = require('./config/config');
const probeConfig = require(config.probeConfigFile);
const promClient = require('prom-client');
const express = require('express');
const logger = require('./utils/logger');
const Prober = require('./prober/prober');
const register = new promClient.Registry();
promClient.collectDefaultMetrics({ register });
const app = express();
/**
* Show index page
*/
app.get('/', (req, res) => {
logger.debug('return /');
let probes = '';
Object.keys(probeConfig).forEach(probe => {
probes += `
<li><a href="probe/${probe}">${probe}</a></li>`;
});
res.send(`<html>
<head><title>Postman Exporter</title></head>
<body>
<h1>Postman Exporter</h1>
<p><a href="metrics">Metrics</a></p>
<p><a href="config">Configuration</a></p>
<h2>Probes</h2>
<ul>
${probes}
</ul>
</body>
</html>`);
});
/**
* Run a probe
*/
app.get('/probe/:probe', (req, res) => {
try {
return new Prober(req, res, req.params.probe).run();
}
catch {
logger.info(`requested probe '${req.params.probe}' not found`);
return res.status(404).send('Probe not found');
}
});
/**
* Return Node.js metrics
*/
app.get('/metrics', async (req, res) => {
logger.debug('return /metrics');
res.set('Content-Type', register.contentType);
res.end(await register.metrics());
});
/**
* Return current configuration
*/
app.get('/config', (req, res) => {
logger.debug('return /config');
res.send(config);
});
/**
* Returns status code 200 when the service is running
*/
app.get('/-/ready', (req, res) => {
logger.debug('return /-/ready');
res.send('ready');
});
const server = app.listen(config.serverPort, () => logger.info(`postman exporter running on port ${config.serverPort}`));
server.timeout = config.serverTimeout;
// Export for testing purposes
module.exports = app;