Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
'node.os.cpu.all-cores-avg': (updateIntervalInSeconds, sampleTimeInSeconds) => {
updateIntervalInSeconds = updateIntervalInSeconds || 30;
sampleTimeInSeconds = sampleTimeInSeconds || 5;
return 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);
}
};
getOrCreateCachedGauge(
name,
valueProducingPromiseCallback,
cachedGaugeUpdateIntervalInSeconds,
dimensions,
publishingIntervalInSeconds
) {
validateCachedGaugeOptions(name, valueProducingPromiseCallback, dimensions, publishingIntervalInSeconds);
let cachedGauge;
if (this._registry.hasMetric(name, dimensions)) {
cachedGauge = this._registry.getMetric(name, dimensions);
} else {
cachedGauge = new CachedGauge(valueProducingPromiseCallback, cachedGaugeUpdateIntervalInSeconds);
const key = this._registry.putMetric(name, cachedGauge, dimensions);
this._reporters.forEach(reporter => reporter.reportMetricOnInterval(key, publishingIntervalInSeconds));
}
return cachedGauge;
}