Class: CachedGauge

CachedGauge

A Cached Gauge takes a function that returns a promise that resolves a
value that should be cached and updated on a given interval.

toJSON() will return the currently cached value.


new CachedGauge(valueProducingPromiseCallback, updateIntervalInSeconds [, timeUnitOverride])

Parameters:
Name Type Argument Description
valueProducingPromiseCallback function

A function that returns a promise than when
resolved supplies the value that should be cached in this gauge.

updateIntervalInSeconds number

How often the cached gauge should update it's value.

timeUnitOverride number <optional>

by default this function takes updateIntervalInSeconds and multiplies it by TimeUnits.SECONDS (1000),
You can override it here.

Implements:
Source:
Example
const cpuAverageCachedGauge = new CachedGauge(() => {
    return new Promise(resolve => {
      //Grab first CPU Measure
      const startMeasure = cpuAverage();
      setTimeout(() => {
        //Grab second Measure
        const endMeasure = cpuAverage();
        const percentageCPU = calculateCpuUsagePercent(startMeasure, endMeasure);
        resolve(percentageCPU);
      }, sampleTimeInSeconds);
    });
  }, updateIntervalInSeconds);

Methods


end()

Clears the interval, so that it doesn't keep any processes alive.

Source:

getType()

The type of the Metric Impl. MetricTypes.

Implements:
Source:
Returns:

The type of the Metric Impl.

Type
string

toJSON()

Implements:
Source:
Returns:

Gauges directly return the value which should be a number.

Type
number