1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-28 00:06:53 +01:00
unleash.unleash/lib/metrics.js
2020-02-20 08:33:46 +01:00

27 lines
695 B
JavaScript

'use strict';
const events = require('./events');
exports.startMonitoring = (enable, eventBus) => {
if (!enable) {
return;
}
const client = require('prom-client');
const gcStats = require('prometheus-gc-stats');
client.collectDefaultMetrics();
gcStats()();
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],
});
eventBus.on(events.REQUEST_TIME, ({ path, method, time, statusCode }) => {
requestDuration.labels(path, method, statusCode).observe(time);
});
};