UNPKG

lisk-framework

Version:

Lisk blockchain application platform

76 lines 1.88 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.defaultMetrics = exports.Metrics = void 0; const prom_client_1 = require("prom-client"); const noopCounter = { inc: (_num) => { }, reset: () => { }, }; const noopGauge = { inc: (_num) => { }, dec: (_num) => { }, set: (_num) => { }, }; const noopHistogram = { observe: (_num) => { }, startTimer: () => () => { }, reset: () => { }, }; class Metrics { constructor(enabled = false) { this._enabled = enabled; this._registry = new prom_client_1.Registry(); } enable() { this._enabled = true; } disable() { this._enabled = false; } enabled() { return this._enabled; } counter(name) { if (!this._enabled) { return noopCounter; } const newCounter = new prom_client_1.Counter({ name, help: name, registers: [this._registry], }); return newCounter; } gauge(name) { if (!this._enabled) { return noopGauge; } const newGauge = new prom_client_1.Gauge({ name, help: name, registers: [this._registry], }); return newGauge; } histogram(name, buckets = []) { if (!this._enabled) { return noopHistogram; } const newHistogram = new prom_client_1.Histogram({ name, help: name, registers: [this._registry], buckets, }); return newHistogram; } async report(inJSON) { if (inJSON) { return this._registry.getMetricsAsJSON(); } return this._registry.metrics(); } } exports.Metrics = Metrics; exports.defaultMetrics = new Metrics(); //# sourceMappingURL=metrics.js.map