From 32bf3b1ac4a690656d4e58b85d6a8dfab8dcfd70 Mon Sep 17 00:00:00 2001 From: emanuele-f Date: Mon, 2 Mar 2020 12:11:08 +0100 Subject: [PATCH] Avoid reporting the last point when the timeseries write has not completed yet Fixes #3478 --- scripts/lua/modules/timeseries/drivers/rrd.lua | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/scripts/lua/modules/timeseries/drivers/rrd.lua b/scripts/lua/modules/timeseries/drivers/rrd.lua index 57b94b84c0..6698fab6a0 100644 --- a/scripts/lua/modules/timeseries/drivers/rrd.lua +++ b/scripts/lua/modules/timeseries/drivers/rrd.lua @@ -586,12 +586,20 @@ function driver:query(schema, tstart, tend, tags, options) return nil end + touchRRD(rrdfile) + + local last_update = ntop.rrd_lastupdate(rrdfile) + if isDebugEnabled() then traceError(TRACE_NORMAL, TRACE_CONSOLE, string.format("RRD_FETCH schema=%s %s -> (%s): last_update=%u", - schema.name, table.tconcat(tags, "=", ","), rrdfile, ntop.rrd_lastupdate(rrdfile))) + schema.name, table.tconcat(tags, "=", ","), rrdfile, last_update)) end - touchRRD(rrdfile) + -- Avoid reporting the last point when the timeseries write has not completed + -- yet. Use 2*step as a bound. + if((tend > last_update) and ((tend - last_update) <= 2*schema.options.step)) then + tend = last_update + end --tprint("rrdtool fetch ".. rrdfile.. " " .. getConsolidationFunction(schema) .. " -s ".. tstart .. " -e " .. tend) local fstart, fstep, fdata, fend, fcount = ntop.rrd_fetch_columns(rrdfile, getConsolidationFunction(schema), tstart, tend)