UNPKG

dl

Version:

DreamLab Libs

50 lines (38 loc) 1.01 kB
var AbstractMetric = require('./AbstractMetric.js').AbstractMetric; var GaugeMetric = function () { AbstractMetric.apply(this, arguments); this._min = null; this._max = null; this._sum = 0; this._count = 0; }; GaugeMetric.prototype = Object.create(AbstractMetric.prototype); GaugeMetric.prototype.update = function (value) { if (!this._min || value < this._min) { this._min = value; } if (!this._max || value > this._max) { this._max = value; } this._sum += value; this._count++; return this; }; GaugeMetric.prototype._dumpValue = function (count, min, max, sum) { if (count === 1) { max = sum = min; } return { 'min': min, 'max': max, 'sum': sum, 'count': count } }; GaugeMetric.prototype.dump = function () { return [{ 'key': this._name, 'value': this._dumpValue(this._count, this._min, this._max, this._sum) }]; }; exports.GaugeMetric = GaugeMetric;