Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Aggregator.prototype.update = function (timestamp, name, value, calcDiff) {
this.lastUpdate = Date.now()
if (isNaN(value)) {
return
}
if (this.metrics[name] === undefined) {
this.metrics[name] = new Measured.Histogram()
}
if (!this.lastValues[name]) {
this.lastValues[name] = {value: value, ts: timestamp}
}
if (calcDiff === true) {
var diff = value - this.lastValues[name].value
if (diff < 0) {
// container stop might have caused a reset of metric value.
this.lastValues[name].value = 0
} else {
this.metrics[name].update(diff, timestamp)
this.lastValues[name] = {value: value, ts: timestamp}
}
} else {
this.metrics[name].update(value, timestamp)
getOrCreateHistogram(name, dimensions, publishingIntervalInSeconds) {
validateHistogramOptions(name, dimensions, publishingIntervalInSeconds);
let histogram;
if (this._registry.hasMetric(name, dimensions)) {
histogram = this._registry.getMetric(name, dimensions);
} else {
histogram = new Histogram();
const key = this._registry.putMetric(name, histogram, dimensions);
this._reporters.forEach(reporter => reporter.reportMetricOnInterval(key, publishingIntervalInSeconds));
}
return histogram;
}