From b0d9466ca1f987775c75cdf68607a0ae19a772ca Mon Sep 17 00:00:00 2001 From: Richard Wall Date: Mon, 4 Oct 2010 23:59:04 +0100 Subject: add caps on the start and end times in rrd query --- jarmon/jarmon.js | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/jarmon/jarmon.js b/jarmon/jarmon.js index 06ec4c8..406c4d1 100644 --- a/jarmon/jarmon.js +++ b/jarmon/jarmon.js @@ -216,14 +216,21 @@ jarmon.RrdQuery.prototype.getData = function(startTimeJs, endTimeJs, dsId, cfNam var flotData = []; var dsIndex = ds.getIdx(); - var startRowTime = startTime - startTime%step; - var endRowTime = endTime - endTime%step; - - //console.log('FRT: ', new Date(startRowTime*1000)); - //console.log('ERT: ', new Date(endRowTime*1000)); - //console.log('LRT: ', new Date(lastRowTime*1000)); - //console.log('DIFF: ', (lastRowTime - startRowTime) / step); - //console.log('ROWS: ', rraRowCount); + var startRowTime = Math.max(firstRowTime, startTime - startTime%step); + var endRowTime = Math.min(lastRowTime, endTime - endTime%step); + // If RRD exists, but hasn't been updated then the start time might end up + // being higher than the end time (which is capped at the last row time of + // the chosen RRA, so cap startTime at endTime...if you see what I mean) + startRowTime = Math.min(startRowTime, endRowTime); + + /* + console.log('FRT: ', new Date(firstRowTime*1000)); + console.log('LRT: ', new Date(lastRowTime*1000)); + console.log('SRT: ', new Date(startRowTime*1000)); + console.log('ERT: ', new Date(endRowTime*1000)); + console.log('DIFF: ', (lastRowTime - startRowTime) / step); + console.log('ROWS: ', rraRowCount); + */ var startRowIndex = rraRowCount - (lastRowTime - startRowTime) / step; var endRowIndex = rraRowCount - (lastRowTime - endRowTime) / step; -- cgit v1.1-4-g5e80