-
Notifications
You must be signed in to change notification settings - Fork 68
/
advanced-example.js
61 lines (53 loc) · 1.52 KB
/
advanced-example.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
'use strict';
const express = require('express');
const app = express();
const promClient = require('prom-client');
// replace this with require('.') when running from library code
const promBundle = require('express-prom-bundle');
const bundle = promBundle({
buckets: [0.1, 0.4, 0.7],
includeMethod: true,
includePath: true,
customLabels: {year: null},
transformLabels: labels => Object.assign(labels, {year: new Date().getFullYear()}),
metricsPath: '/prometheus',
promClient: {
collectDefaultMetrics: {
}
},
urlValueParser: {
minHexLength: 5,
extraMasks: [
"^[0-9]+\\.[0-9]+\\.[0-9]+$", // replace dot-separated dates with #val, (regex as string)
/^[0-9]+\-[0-9]+\-[0-9]+$/ // replace dash-separated dates with #val (actual regex)
]
},
normalizePath: [
['^/foo', '/example'] // replace /foo with /example
]
});
app.use(bundle);
// native prom-client metric (no prefix)
const c1 = new promClient.Counter({name: 'c1', help: 'c1 help'});
c1.inc(10);
app.get('/foo/:id', (req, res) => {
setTimeout(() => {
res.send('foo response\n');
}, 500);
});
app.delete('/foo/:id', (req, res) => {
setTimeout(() => {
res.send('foo deleted\n');
}, 300);
});
app.get('/bar', (req, res) => res.send('bar response\n'));
app.listen(3000, () => console.info( // eslint-disable-line
`listening on 3000
test in shell console:
curl localhost:3000/foo/1234
curl localhost:3000/foo/09.08.2018
curl -X DELETE localhost:3000/foo/5432
curl localhost:3000/bar
curl localhost:3000/prometheus
`
));