1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-22 19:07:54 +01:00
unleash.unleash/lib/metrics.js

25 lines
587 B
JavaScript
Raw Normal View History

2016-12-04 14:09:37 +01:00
'use strict';
const events = require('./events');
exports.startMonitoring = (enable, eventBus) => {
if (!enable) {
return;
}
const client = require('prom-client');
2016-12-04 14:09:37 +01:00
2017-06-28 10:17:14 +02:00
const requestDuration = new client.Summary(
'http_request_duration_milliseconds',
'App response time',
['path', 'method', 'status'],
{
percentiles: [0.1, 0.5, 0.9, 0.99],
}
);
2016-12-04 14:09:37 +01:00
eventBus.on(events.REQUEST_TIME, ({ path, method, time, statusCode }) => {
requestDuration.labels(path, method, statusCode).observe(time);
});
2016-12-04 14:09:37 +01:00
};