1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
const { MetricTypes } = require('./Metric');
/**
* Values that can be read instantly
* @implements {Metric}
* @example
* var Measured = require('measured')
* var gauge = new Measured.Gauge(function() {
* return process.memoryUsage().rss;
* });
*/
class Gauge {
/**
* @param {function} readFn A function that returns the numeric value for this gauge.
*/
constructor(readFn) {
this._readFn = readFn;
}
/**
* @return {number} Gauges directly return the value from the callback which should be a number.
*/
toJSON() {
return this._readFn();
}
/**
* The type of the Metric Impl. {@link MetricTypes}.
* @return {string} The type of the Metric Impl.
*/
getType() {
return MetricTypes.GAUGE;
}
}
module.exports = Gauge;