Skip to content

Commit

Permalink
Merge pull request #145 from NOYB/Status_/_Monitoring_-_Last_Sample_Z…
Browse files Browse the repository at this point in the history
…ero_II
  • Loading branch information
jdillard committed Dec 16, 2016
2 parents 2a6c6af + 5b20ed3 commit 2490ac1
Showing 1 changed file with 21 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@
$rrd_location = "/var/db/rrd/";

//lookup end time based on resolution (ensure resolution interval)
$endLookup = array(
"60" => "-1min",
"300" => "-5min",
"3600" => "-1hour",
"86400" => "-1day"
$resolutionLookup = array(
"60" => "1min",
"300" => "5min",
"3600" => "1hour",
"86400" => "1day"
);

//TODO security/validation checks
Expand Down Expand Up @@ -73,23 +73,30 @@
}

if ($timePeriod === "custom") {
// Determine highest resolution available for requested time period
// Should be possible to determine programmaticly from the RRD header info array (rrd_info).
$rrd_options = array( 'AVERAGE', '-a', '-s', $start, '-e', $start );
$left_rrd_array = rrd_fetch($rrd_location . $left . ".rrd", $rrd_options);
$right_rrd_array = rrd_fetch($rrd_location . $right . ".rrd", $rrd_options);
$resolution = max($left_rrd_array['step'], $right_rrd_array['step']);

// make sure end time isn't later than last updated time entry
if( $end > $last_updated ) { $end = $last_updated; }

/* ensure resolution intreval */
$resolution = 60; //defaults to highest resolution available
$start = floor($start/$resolution) * $resolution;
$end = floor($end/$resolution) * $resolution;

$rrd_options = array( 'AVERAGE', '-r', $resolution, '-s', $start, '-e', $end );
// Minus resolution to prevent last value 0 (zero).
$end -= $resolution;

// make sure start time isn't later than end time
if ($start > $end) { $start = $end; }
} else {

$rrd_options = array( 'AVERAGE', '-r', $resolution, '-s', 'e'.$timePeriod, '-e', $endLookup[$resolution] );

// Use end time reference in 'start' to retain time period length.
$start = 'end' . $timePeriod . '+'.$resolutionLookup[$resolution];
// Use the RRD last updated time as end, minus resolution to prevent last value 0 (zero).
$end = $last_updated . '-'.$resolutionLookup[$resolution];
}

$rrd_options = array( 'AVERAGE', '-a', '-r', $resolution, '-s', $start, '-e', $end );

//Initialze
$left_unit_acronym = $right_unit_acronym = "";

Expand Down

0 comments on commit 2490ac1

Please sign in to comment.