UNPKG

pandora-metrics

Version:
24 lines 890 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const MetricSet_1 = require("../common/MetricSet"); class CachedMetricSet extends MetricSet_1.MetricSet { constructor(dataTTL) { super(); this.dataTTL = dataTTL || CachedMetricSet.DEFAULT_DATA_TTL; } /** * Do not collect data if our cached copy of data is valid. * The purpose is to minimize the cost to collect system metric. */ async refreshIfNecessary() { let current = Date.now(); if (!this.lastCollectTime || current - this.lastCollectTime > this.dataTTL * 1000) { await this.getValueInternal(); // update the last collect time stamp this.lastCollectTime = current; } } } CachedMetricSet.DEFAULT_DATA_TTL = 60; exports.CachedMetricSet = CachedMetricSet; //# sourceMappingURL=CachedMetricSet.js.map