diff options
author | Erik Fonnesbeck <efonnes@gmail.com> | 2010-12-31 03:13:45 -0700 |
---|---|---|
committer | Erik Fonnesbeck <efonnes@gmail.com> | 2010-12-31 03:18:41 -0700 |
commit | 97acf64675592e2e623eb22b3d1adcc63c109b2a (patch) | |
tree | fcde6dde6122d3450bbdad9080c08bb092dd8b71 | |
parent | 29640ceef3b1ee281dae21ab41cd2ff5703f43c8 (diff) | |
download | pfsense-97acf64675592e2e623eb22b3d1adcc63c109b2a.zip pfsense-97acf64675592e2e623eb22b3d1adcc63c109b2a.tar.gz |
Add new default option that makes RRD graphs with the old type of behavior for time periods, configurable on settings tab.
-rwxr-xr-x | usr/local/www/status_rrd_graph.php | 170 | ||||
-rwxr-xr-x | usr/local/www/status_rrd_graph_settings.php | 20 |
2 files changed, 114 insertions, 76 deletions
diff --git a/usr/local/www/status_rrd_graph.php b/usr/local/www/status_rrd_graph.php index 5c05ceb..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']) { @@ -200,88 +204,102 @@ $custom_databases = array_merge($dbheader_custom, $databases); $styles = array('inverse' => gettext('Inverse'), 'absolute' => gettext('Absolute')); $graphs = array("8hour", "day", "week", "month", "quarter", "year", "4year"); -$periods = array("current" => gettext("Current Period"), "previous" => gettext("Previous Period")); +$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); - $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; + + 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(); diff --git a/usr/local/www/status_rrd_graph_settings.php b/usr/local/www/status_rrd_graph_settings.php index 6fb943a..7accd25 100755 --- a/usr/local/www/status_rrd_graph_settings.php +++ b/usr/local/www/status_rrd_graph_settings.php @@ -47,6 +47,7 @@ require_once("rrd.inc"); $pconfig['enable'] = isset($config['rrd']['enable']); $pconfig['category'] = $config['rrd']['category']; $pconfig['style'] = $config['rrd']['style']; +$pconfig['period'] = $config['rrd']['period']; $curcat = "settings"; $categories = array('system' => gettext("System"), @@ -56,6 +57,9 @@ $categories = array('system' => gettext("System"), 'queues' => gettext("Queues")); $styles = array('inverse' => gettext("Inverse"), 'absolute' => gettext("Absolute")); +$periods = array("absolute" => gettext("Absolute Timespans"), + "current" => gettext("Current Period"), + "previous" => gettext("Previous Period")); if ($_POST) { @@ -69,6 +73,7 @@ if ($_POST) { $config['rrd']['enable'] = $_POST['enable'] ? true : false; $config['rrd']['category'] = $_POST['category']; $config['rrd']['style'] = $_POST['style']; + $config['rrd']['period'] = $_POST['period']; write_config(); $retval = 0; @@ -189,6 +194,21 @@ include("head.inc"); </td> </tr> <tr> + <td width="22%" valign="top" class="vtable"><?=gettext("Default period");?></td> + <td width="78%" class="vtable"> + <select name="period" class="formselect" style="z-index: -10;" > + <?php + foreach ($periods as $period => $periodd) { + echo "<option value=\"$period\""; + if ($period == $pconfig['period']) echo " selected"; + echo ">" . htmlspecialchars($periodd) . "</option>\n"; + } + ?> + </select> + <b><?=gettext("This selects the default period.");?></b> + </td> + </tr> + <tr> <td width="22%" valign="top"> </td> <td width="78%"> <input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save");?>" onclick="enable_change(true)"> |