diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3c3629e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules diff --git a/lib/gateway.js b/lib/gateway.js index 435331b..9b2b851 100644 --- a/lib/gateway.js +++ b/lib/gateway.js @@ -184,9 +184,10 @@ Gateway.prototype.reportMetrics = function reportMetrics( ) { samples = samples.splice(0); // discard samples older than the configured cutoff - if (this.maxMetricAgeMs >= 0) { - var now = this.getTimestamp(); - var oldestKeepTs = now - this.maxMetricAgeMs; + const now = this.getTimestamp(); + const oldestKeepTs = this.maxMetricAgeMs >= 0 ? (now - this.maxMetricAgeMs) : 0; + const filterOldMetrics = this.maxMetricAgeMs >= 0; + if (filterOldMetrics) { for (i=0; i 0) { Gateway.trace("discarding %d samples older than %d ms, from %d to %d", @@ -210,10 +211,19 @@ Gateway.prototype.reportMetrics = function reportMetrics( ) { for (i=0; i= oldestKeepTs) { + allValues[id] = this.previousValues[id]; + } + } + const discardedMetrics = Object.keys(this.previousValues).length - Object.keys(allValues).length; + if (discardedMetrics > 0) { + Gateway.trace("discarding %d metrics older than %d ms", discardedMetrics, this.maxMetricAgeMs); + } for (id in map) allValues[id] = map[id]; this.previousValues = allValues;