diff options
author | Seth Mos <seth.mos@dds.nl> | 2011-01-18 09:10:36 +0100 |
---|---|---|
committer | Seth Mos <seth.mos@dds.nl> | 2011-01-18 09:10:36 +0100 |
commit | 1f74cd2d101f032472a4968a10b64161652d6c1f (patch) | |
tree | d692513243aaed6003264f0b877b50cbeb69328b /usr/local/www/status_rrd_graph.php | |
parent | c9d174dfc0a29c59ae35f43a470460f36f695b61 (diff) | |
parent | 96e889fc1e938187dd18238d80e3163e1aca3006 (diff) | |
download | pfsense-1f74cd2d101f032472a4968a10b64161652d6c1f.zip pfsense-1f74cd2d101f032472a4968a10b64161652d6c1f.tar.gz |
Merge remote branch 'upstream/master'
Conflicts:
etc/inc/interfaces.inc
etc/inc/system.inc
Diffstat (limited to 'usr/local/www/status_rrd_graph.php')
-rwxr-xr-x | usr/local/www/status_rrd_graph.php | 169 |
1 files changed, 98 insertions, 71 deletions
diff --git a/usr/local/www/status_rrd_graph.php b/usr/local/www/status_rrd_graph.php index 48f5734..28b1b4c 100755 --- a/usr/local/www/status_rrd_graph.php +++ b/usr/local/www/status_rrd_graph.php @@ -66,7 +66,11 @@ if ($_GET['cat']) { if ($_GET['period']) { $curperiod = $_GET['period']; } else { - $curperiod = "current"; + if(! empty($config['rrd']['period'])) { + $curperiod = $config['rrd']['period']; + } else { + $curperiod = "absolute"; + } } if ($_GET['option']) { @@ -128,11 +132,11 @@ $now = time(); if($curcat == "custom") { if (is_numeric($_GET['start'])) { if($start < ($now - (3600 * 24 * 365 * 5))) { - $start = $now - (4 * 3600); + $start = $now - (8 * 3600); } $start = $_GET['start']; } else { - $start = $now - (4 * 3600); + $start = $now - (8 * 3600); } } @@ -144,6 +148,7 @@ if (is_numeric($_GET['end'])) { /* this should never happen */ if($end < $start) { + log_error("start $start is smaller than end $end"); $end = $now; } @@ -198,81 +203,103 @@ $custom_databases = array_merge($dbheader_custom, $databases); $styles = array('inverse' => gettext('Inverse'), 'absolute' => gettext('Absolute')); -$graphs = array("day", "week", "month", "quarter", "year", "4year"); -$periods = array("current" => gettext("Current Period"), "previous" => gettext("Previous Period")); +$graphs = array("8hour", "day", "week", "month", "quarter", "year", "4year"); +$periods = array("absolute" => gettext("Absolute Timespans"), "current" => gettext("Current Period"), "previous" => gettext("Previous Period")); +$graph_length = array( + "8hour" => 28800, + "day" => 86400, + "week" => 604800, + "month" => 2764800, + "quarter" => 8035200, + "year" => 31622400, + "4year" => 126489600); $pgtitle = array(gettext("Status"),gettext("RRD Graphs")); include("head.inc"); function get_dates($curperiod, $graph) { + global $graph_length; $now = time(); $end = $now; - $curyear = date('Y', $now); - $curmonth = date('m', $now); - $curweek = date('W', $now); - $curweekday = date('N', $now) - 1; // We want to start on monday - $curday = date('d', $now); - - switch($curperiod) { - case "previous": - $offset = -1; - break; - default: - $offset = 0; - } - switch($graph) { - case "12hour": - switch($offset) { - case 0; - $houroffset = 0; - break; - default: - $houroffset = ($offset * 12) - 12; - break; - } - $start = mktime((8 + $houroffset), 0, 0, $curmonth, $curday, $curyear); - if(($offset != 0) || (($end - ($start + (12 * 3600)) ) > 0) ) { - $end = mktime((8 + $houroffset) + 12, 0, 0, $curmonth, $curday, $curyear); - } - break; - case "day": - $start = mktime(0, 0, 0, $curmonth, ($curday + $offset), $curyear); - if($offset != 0) - $end = mktime(0, 0, 0, $curmonth, (($curday + $offset) + 1), $curyear); - break; - case "week": - switch($offset) { - case 0; - $weekoffset = 0; - break; - default: - $weekoffset = ($offset * 7) - 7; - break; - } - $start = mktime(0, 0, 0, $curmonth, (($curday - $curweekday) + $weekoffset), $curyear); - if($offset != 0) - $end = mktime(0, 0, 0, $curmonth, (($curday - $curweekday) + $weekoffset + 7), $curyear); - break; - case "month": - $start = mktime(0, 0, 0, ($curmonth + $offset), 0, $curyear); - if($offset != 0) - $end = mktime(0, 0, 0, (($curmonth + $offset) + 1), 0, $curyear); - break; - case "quarter": - $start = mktime(0, 0, 0, (($curmonth - 2) + $offset), 0, $curyear); - if($offset != 0) - $end = mktime(0, 0, 0, (($curmonth + $offset) + 1), 0, $curyear); - break; - case "year": - $start = mktime(0, 0, 0, 1, 0, ($curyear + $offset)); - if($offset != 0) - $end = mktime(0, 0, 0, 1, 0, (($curyear + $offset) +1)); - break; - case "4year": - $start = mktime(0, 0, 0, 1, 0, (($curyear - 3) + $offset)); - if($offset != 0) - $end = mktime(0, 0, 0, 1, 0, (($curyear + $offset) +1)); - break; + + if($curperiod == "absolute") { + $start = $end - $graph_length[$graph]; + } else { + $curyear = date('Y', $now); + $curmonth = date('m', $now); + $curweek = date('W', $now); + $curweekday = date('N', $now) - 1; // We want to start on monday + $curday = date('d', $now); + $curhour = date('G', $now); + + switch($curperiod) { + case "previous": + $offset = -1; + break; + default: + $offset = 0; + } + switch($graph) { + case "8hour": + if($curhour < 24) + $starthour = 16; + if($curhour < 16) + $starthour = 8; + if($curhour < 8) + $starthour = 0; + + switch($offset) { + case 0: + $houroffset = $starthour; + break; + default: + $houroffset = $starthour + ($offset * 8); + break; + } + $start = mktime($houroffset, 0, 0, $curmonth, $curday, $curyear); + if($offset != 0) { + $end = mktime(($houroffset + 8), 0, 0, $curmonth, $curday, $curyear); + } + break; + case "day": + $start = mktime(0, 0, 0, $curmonth, ($curday + $offset), $curyear); + if($offset != 0) + $end = mktime(0, 0, 0, $curmonth, (($curday + $offset) + 1), $curyear); + break; + case "week": + switch($offset) { + case 0: + $weekoffset = 0; + break; + default: + $weekoffset = ($offset * 7) - 7; + break; + } + $start = mktime(0, 0, 0, $curmonth, (($curday - $curweekday) + $weekoffset), $curyear); + if($offset != 0) + $end = mktime(0, 0, 0, $curmonth, (($curday - $curweekday) + $weekoffset + 7), $curyear); + break; + case "month": + $start = mktime(0, 0, 0, ($curmonth + $offset), 0, $curyear); + if($offset != 0) + $end = mktime(0, 0, 0, (($curmonth + $offset) + 1), 0, $curyear); + break; + case "quarter": + $start = mktime(0, 0, 0, (($curmonth - 2) + $offset), 0, $curyear); + if($offset != 0) + $end = mktime(0, 0, 0, (($curmonth + $offset) + 1), 0, $curyear); + break; + case "year": + $start = mktime(0, 0, 0, 1, 0, ($curyear + $offset)); + if($offset != 0) + $end = mktime(0, 0, 0, 1, 0, (($curyear + $offset) +1)); + break; + case "4year": + $start = mktime(0, 0, 0, 1, 0, (($curyear - 3) + $offset)); + if($offset != 0) + $end = mktime(0, 0, 0, 1, 0, (($curyear + $offset) +1)); + break; + } } // echo "start $start ". date('l jS \of F Y h:i:s A', $start) .", end $end ". date('l jS \of F Y h:i:s A', $end) ."<br>"; $dates = array(); |