2016-12-04 14:09:37 +01:00
|
|
|
'use strict';
|
|
|
|
|
2016-11-30 23:41:57 +01:00
|
|
|
const events = require('./events');
|
|
|
|
|
|
|
|
exports.startMonitoring = (enable, eventBus) => {
|
|
|
|
if (!enable) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const client = require('prom-client');
|
2017-08-23 11:27:58 +02:00
|
|
|
const gcStats = require('prometheus-gc-stats');
|
2016-12-04 14:09:37 +01:00
|
|
|
|
2017-06-28 14:21:05 +02:00
|
|
|
client.collectDefaultMetrics();
|
2017-08-23 11:27:58 +02:00
|
|
|
gcStats()();
|
2017-06-28 14:21:05 +02:00
|
|
|
|
|
|
|
const requestDuration = new client.Summary({
|
|
|
|
name: 'http_request_duration_milliseconds',
|
|
|
|
help: 'App response time',
|
|
|
|
labelNames: ['path', 'method', 'status'],
|
|
|
|
percentiles: [0.1, 0.5, 0.9, 0.99],
|
|
|
|
});
|
2016-12-01 17:43:08 +01:00
|
|
|
|
2016-12-04 14:09:37 +01:00
|
|
|
eventBus.on(events.REQUEST_TIME, ({ path, method, time, statusCode }) => {
|
2016-12-01 18:10:25 +01:00
|
|
|
requestDuration.labels(path, method, statusCode).observe(time);
|
2016-12-01 17:43:08 +01:00
|
|
|
});
|
2016-12-04 14:09:37 +01:00
|
|
|
};
|