Skip to content

Commit

Permalink
(status > monitoring) fix resolution interval - adapted from NOYB in #…
Browse files Browse the repository at this point in the history
  • Loading branch information
jdillard committed Jun 7, 2016
1 parent 0a3154c commit 0ff2dfc
Showing 1 changed file with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@

$rrd_location = "/var/db/rrd/";

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

//TODO security/validation checks
$left = $_POST['left'];
$right = $_POST['right'];
Expand All @@ -75,6 +83,7 @@
$right_pieces = explode("-", $right);

if ($timePeriod === "custom") {

//dates validation
if($end < $start) {
die ('{ "error" : "The start date must come before the end date." }');
Expand All @@ -85,9 +94,13 @@
$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 );

} else {
$rrd_options = array( 'AVERAGE', '-r', $resolution, '-s', $timePeriod );

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

}

//Initialze
Expand Down Expand Up @@ -266,12 +279,8 @@

$data = array();

$dataKeys = array_keys($data_list);
$lastDataKey = array_pop($dataKeys);
foreach ($data_list as $time => $value) {
if($time != $lastDataKey) {
$data[] = array($time*1000, $value*$multiplier);
}
}

$obj[$ds_key_left_adjusted]['values'] = $data;
Expand Down Expand Up @@ -497,12 +506,8 @@

$data = array();

$dataKeys = array_keys($data_list);
$lastDataKey = array_pop($dataKeys);
foreach ($data_list as $time => $value) {
if($time != $lastDataKey) {
$data[] = array($time*1000, $value*$multiplier);
}
}

$obj[$ds_key_right_adjusted]['values'] = $data;
Expand Down

0 comments on commit 0ff2dfc

Please sign in to comment.