diff --git a/lib/commands/includes/collectMetrics.lua b/lib/commands/includes/collectMetrics.lua index a2a4a0c..cccba14 100644 --- a/lib/commands/includes/collectMetrics.lua +++ b/lib/commands/includes/collectMetrics.lua @@ -19,7 +19,7 @@ local function collectMetrics(metaKey, dataPointsList, maxDataPoints, timestamp) return end - local N = math.min(math.floor((timestamp - prevTS) / 60000), tonumber(maxDataPoints)) + local N = math.min(math.floor(timestamp / 60000) - math.floor(prevTS / 60000), tonumber(maxDataPoints)) if N > 0 then local delta = count - rcall("HGET", metaKey, "prevCount") diff --git a/test/test_metrics.js b/test/test_metrics.js index 5a8aaff..fb063ee 100644 --- a/test/test_metrics.js +++ b/test/test_metrics.js @@ -34,6 +34,8 @@ describe('metrics', () => { ONE_MINUTE, ONE_MINUTE, ONE_MINUTE * 3, + ONE_SECOND * 70, + ONE_SECOND * 50, ONE_HOUR, ONE_MINUTE ]; @@ -100,6 +102,8 @@ describe('metrics', () => { '0', '0', '1', + '1', + '1', '0', '0', '1',