diff options
author | smos <seth.mos@dds.nl> | 2010-07-15 17:20:49 +0200 |
---|---|---|
committer | smos <seth.mos@dds.nl> | 2010-07-15 17:21:24 +0200 |
commit | 7d906758d5033a54b77ab61cd0e0a72120eb4f52 (patch) | |
tree | d0d16898ac0a104cd1184eff9d144c87789f300c /usr/local/www/status_rrd_graph.php | |
parent | 6cfa23eb6ee7010f0a320ae1c7692ae1ca377597 (diff) | |
download | pfsense-7d906758d5033a54b77ab61cd0e0a72120eb4f52.zip pfsense-7d906758d5033a54b77ab61cd0e0a72120eb4f52.tar.gz |
Improve the RRD graph display
Diffstat (limited to 'usr/local/www/status_rrd_graph.php')
-rwxr-xr-x | usr/local/www/status_rrd_graph.php | 88 |
1 files changed, 81 insertions, 7 deletions
diff --git a/usr/local/www/status_rrd_graph.php b/usr/local/www/status_rrd_graph.php index f7b5b25..cefbbb2 100755 --- a/usr/local/www/status_rrd_graph.php +++ b/usr/local/www/status_rrd_graph.php @@ -63,6 +63,12 @@ if ($_GET['cat']) { } } +if ($_GET['period']) { + $curperiod = $_GET['period']; +} else { + $curperiod = "current"; +} + if ($_GET['option']) { $curoption = $_GET['option']; } else { @@ -150,11 +156,61 @@ $ui_databases = array_merge($dbheader, $databases); $styles = array('inverse' => 'Inverse', 'absolute' => 'Absolute'); -$periods = array("4h", "16h", "48h", "32d", "6m", "1y", "4y"); +$graphs = array("day", "week", "month", "quarter", "year", "4year"); +$periods = array("current" => "Current Period", "previous" => "Previous Period"); $pgtitle = array("Status","RRD Graphs"); include("head.inc"); +function get_dates($curperiod, $graph) { + $now = time(); + $end = $now; + $curyear = date('Y', $now); + $curmonth = date('m', $now); + $curweek = date('W', $now); + $curweekday = date('w', $now); + $curday = date('d', $now); + + switch($curperiod) { + case "previous": + $offset = -1; + break; + default: + $offset = 0; + } + switch($graph) { + case "day": + $start = mktime(0, 0, 0, $curmonth, ($curday - $offset), $curyear); + $end = mktime(0, 0, 0, $curmonth, (($curday - $offset) + 1), $curyear); + break; + case "week": + $start = mktime(0, 0, 0, $curmonth, (($curday - $curweekday) - $offset), $curyear); + $end = mktime(0, 0, 0, $curmonth, (($curday - $curweekday) + 7), $curyear); + break; + case "month": + $start = mktime(0, 0, 0, ($curmonth - $offset), 0, $curyear); + $end = mktime(0, 0, 0, (($curmonth - $offset) + 1), 0, $curyear); + break; + case "quarter": + $start = mktime(0, 0, 0, (($curmonth -2) - $offset), 0, $curyear); + $end = mktime(0, 0, 0, (($curmonth - $offset) + 1), 0, $curyear); + break; + case "year": + $start = mktime(0, 0, 0, 1, 0, ($curyear - $offset)); + $end = mktime(0, 0, 0, 1, 0, (($curyear - $offset) +1)); + break; + case "4year": + $start = mktime(0, 0, 0, 1, 0, (($curyear - 3) - $offset)); + $end = mktime(0, 0, 0, 1, 0, (($curyear - $offset) +1)); + break; + } + $dates = array(); + $dates['start'] = $start; + $dates['end'] = $end; + return $dates; +} + + ?> <body link="#0000CC" vlink="#0000CC" alink="#0000CC"> <?php include("fbegin.inc"); ?> @@ -249,12 +305,24 @@ include("head.inc"); echo ">" . htmlspecialchars($styled) . "</option>\n"; } ?> + </select> + + <?=gettext("Period:");?> + <select name="period" class="formselect" style="z-index: -10;" onchange="document.form1.submit()"> + <?php + foreach ($periods as $period => $value) { + echo "<option value=\"$period\""; + if ($period == $curperiod) echo " selected"; + echo ">" . htmlspecialchars($value) . "</option>\n"; + } + ?> </select> <?php - foreach($periods as $period => $interval) { + // echo "year $curyear, month $curmonth, week $curweek, day $curday, weekday $curweekday<br>"; + foreach($graphs as $graph) { /* check which databases are valid for our category */ foreach($ui_databases as $curdatabase) { if(! preg_match("/($curcat)/i", $curdatabase)) { @@ -289,10 +357,13 @@ include("head.inc"); } } if(in_array($curdatabase, $databases)) { + $dates = get_dates($curperiod, $graph); + $start = $dates['start']; + $end = $dates['end']; echo "<tr><td colspan=2 class=\"list\">\n"; - echo "<IMG BORDER='0' name='{$interval}-{$curoption}-{$curdatabase}' "; - echo "id='{$interval}-{$curoption}-{$curdatabase}' ALT=\"$prettydb Graph\" "; - echo "SRC=\"status_rrd_graph_img.php?interval=$interval&database={$curdatabase}&style={$curstyle}\" />\n"; + echo "<IMG BORDER='0' name='{$graph}-{$curoption}-{$curdatabase}' "; + echo "id='{$graph}-{$curoption}-{$curdatabase}' ALT=\"$prettydb Graph\" "; + echo "SRC=\"status_rrd_graph_img.php?start={$start}&end={$end}&database={$curdatabase}&style={$curstyle}&graph={$graph}\" />\n"; echo "<br /><hr><br />\n"; echo "</td></tr>\n"; } @@ -308,7 +379,7 @@ include("head.inc"); //alert('updating'); var randomid = Math.floor(Math.random()*11); <?php - foreach($periods as $period => $interval) { + foreach($graphs as $graph) { /* check which databases are valid for our category */ foreach($databases as $curdatabase) { if(! stristr($curdatabase, $curcat)) { @@ -338,9 +409,12 @@ include("head.inc"); continue 2; } } + $dates = get_dates($curperiod, $graph); + $start = $dates['start']; + $end = $dates['end']; /* generate update events utilizing prototype $('') feature */ echo "\n"; - echo "\t\t\$('{$interval}-{$curoption}-{$curdatabase}').src='status_rrd_graph_img.php?interval={$interval}&database={$curdatabase}&style={$curstyle}&tmp=' + randomid;\n"; + echo "\t\t\$('{$graph}-{$curoption}-{$curdatabase}').src='status_rrd_graph_img.php?start={$start}&end={$end}&graph={$graph}&database={$curdatabase}&style={$curstyle}&tmp=' + randomid;\n"; } } ?> |