summaryrefslogtreecommitdiffstats
path: root/usr/local/www/status_rrd_graph.php
diff options
context:
space:
mode:
Diffstat (limited to 'usr/local/www/status_rrd_graph.php')
-rwxr-xr-xusr/local/www/status_rrd_graph.php89
1 files changed, 82 insertions, 7 deletions
diff --git a/usr/local/www/status_rrd_graph.php b/usr/local/www/status_rrd_graph.php
index f7b5b25..115d12c 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,62 @@ $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;
+ }
+ // 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();
+ $dates['start'] = $start;
+ $dates['end'] = $end;
+ return $dates;
+}
+
+
?>
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
<?php include("fbegin.inc"); ?>
@@ -249,12 +306,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 +358,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&amp;database={$curdatabase}&amp;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}&amp;end={$end}&amp;database={$curdatabase}&amp;style={$curstyle}&amp;graph={$graph}\" />\n";
echo "<br /><hr><br />\n";
echo "</td></tr>\n";
}
@@ -308,7 +380,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 +410,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";
}
}
?>
OpenPOWER on IntegriCloud