new CachedGauge(valueProducingPromiseCallback, updateIntervalInSeconds [, timeUnitOverride])
Parameters:
Name | Type | Argument | Description |
---|---|---|---|
valueProducingPromiseCallback |
function | A function that returns a promise than when |
|
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), |
- 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.
-
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