Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Status / Monitoring - Last Sample Zero II #145

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,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 @@ -104,23 +104,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