Lots of pretty things!

git-svn-id: http://www.observium.org/svn/observer/trunk@99 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
Adam Amstrong
2007-06-06 09:23:41 +00:00
parent ad4160c2ea
commit b8e3ba656a
14 changed files with 154 additions and 48 deletions

View File

@@ -7,6 +7,8 @@ include("windows.php");
include("procurve.php");
include("snom.php");
include("graphing.php");
include("print-functions.php");
function formatStorage($size) {
$sizes = Array('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB');

View File

@@ -1,6 +1,54 @@
<?php
function temp_graph ($device, $graph, $from, $to, $width, $height, $title, $vertical) {
function temp_graph ($temp, $graph, $from, $to, $width, $height, $title, $vertical) {
global $rrdtool, $installdir, $mono_font;
$optsa = array( "--start", $from, "--end", $to, "--width", $width, "--height", $height, "--vertical-label", $vertical, "--alt-autoscale-max",
"-l 0",
"-E",
"-b 1024",
"--title", $title);
$hostname = gethostbyid($device);
$imgfile = "graphs/" . "$graph";
$iter = "1";
$sql = mysql_query("SELECT * FROM temperature where temp_id = '$temp'");
$optsa[] = "COMMENT: Cur Max";
while($temperature = mysql_fetch_array($sql)) {
$hostname = mysql_result(mysql_query("SELECT hostname FROM devices WHERE device_id = '" . $temperature['temp_host'] . "'"),0);
if($iter=="1") {$colour="CC0000";} elseif($iter=="2") {$colour="008C00";} elseif($iter=="3") {$colour="4096EE";
} elseif($iter=="4") {$colour="73880A";} elseif($iter=="5") {$colour="D01F3C";} elseif($iter=="6") {$colour="36393D";
} elseif($iter=="7") {$colour="FF0084"; unset($iter); }
$temperature['temp_descr_fixed'] = str_pad($temperature['temp_descr'], 28);
$temperature['temp_descr_fixed'] = substr($temperature['temp_descr_fixed'],0,28);
$temprrd = addslashes("rrd/$hostname-temp-" . str_replace("/", "_", str_replace(" ", "_",$temperature['temp_descr'])) . ".rrd");
$temprrd = str_replace(")", "_", $temprrd);
$temprrd = str_replace("(", "_", $temprrd);
$optsa[] = "DEF:temp" . $temperature[temp_id] . "=$temprrd:temp:AVERAGE";
$optsa[] = "LINE1:temp" . $temperature[temp_id] . "#" . $colour . ":" . $temperature[temp_descr_fixed];
$optsa[] = "GPRINT:temp" . $temperature[temp_id] . ":LAST:%3.0lf<EFBFBD>C";
$optsa[] = "GPRINT:temp" . $temperature[temp_id] . ":MAX:%3.0lf<EFBFBD>C\l";
$iter++;
}
if($width <= "300") {$optsb = array("--font", "LEGEND:7:$mono_font",
"--font", "AXIS:6:$mono_font",
"--font-render-mode", "normal");}
$opts = array_merge($optsa, $optsb);
$ret = rrd_graph("$imgfile", $opts, count($opts));
if( !is_array($ret) ) {
$err = rrd_error();
echo "rrd_graph() ERROR: $err\n";
return FALSE;
} else {
return $imgfile;
}
}
function temp_graph_dev ($device, $graph, $from, $to, $width, $height, $title, $vertical) {
global $rrdtool, $installdir, $mono_font;
$optsa = array( "--start", $from, "--end", $to, "--width", $width, "--height", $height, "--vertical-label", $vertical, "--alt-autoscale-max",
"-l 0",
@@ -20,7 +68,13 @@ function temp_graph ($device, $graph, $from, $to, $width, $height, $title, $vert
$temperature['temp_descr_fixed'] = str_pad($temperature['temp_descr'], 28);
$temperature['temp_descr_fixed'] = substr($temperature['temp_descr_fixed'],0,28);
$optsa[] = "DEF:temp" . $temperature[temp_id] . "=rrd/" . $hostname . "-temp-" . str_replace(" ", "_", $temperature['temp_descr']) . ".rrd:temp:AVERAGE";
$temprrd = addslashes("rrd/$hostname-temp-" . str_replace("/", "_", str_replace(" ", "_",$temperature['temp_descr'])) . ".rrd");
$temprrd = str_replace(")", "_", $temprrd);
$temprrd = str_replace("(", "_", $temprrd);
$optsa[] = "DEF:temp" . $temperature[temp_id] . "=$temprrd:temp:AVERAGE";
$optsa[] = "LINE1:temp" . $temperature[temp_id] . "#" . $colour . ":" . $temperature[temp_descr_fixed];
$optsa[] = "GPRINT:temp" . $temperature[temp_id] . ":LAST:%3.0lf<EFBFBD>C";
$optsa[] = "GPRINT:temp" . $temperature[temp_id] . ":MAX:%3.0lf<EFBFBD>C\l";

View File

@@ -8,10 +8,11 @@ while($temperature = mysql_fetch_array($temp_data)) {
echo($temp_cmd);
$temp = `$temp_cmd`;
$temprrd = addslashes("rrd/" . $device['hostname'] . "-temp-" . str_replace("/", "_", str_replace(" ", "_",$temperature['temp_descr'])) . ".rrd");
$temprrd = str_replace(")", "_", $temprrd);
$temprrd = str_replace("(", "_", $temprrd);
$temprrd = "rrd/" . $device[hostname] . "-temp-" . str_replace(" ", "_",$temperature['temp_descr']) . ".rrd";
if (!is_file($temprrd)) {
`rrdtool create $temprrd \
--step 300 \
@@ -24,9 +25,13 @@ while($temperature = mysql_fetch_array($temp_data)) {
$temp = str_replace("\"", "", $temp);
if($temperature['temp_tenths']) { $temp = $temp / 10; }
echo("$temprrd, N:$temp");
echo("$temprrd N:$temp");
`rrdtool update $temprrd N:$temp`;
$updatecmd = "rrdtool update $temprrd N:$temp";
echo($updatecmd . "\n");
`$updatecmd`;
mysql_query("UPDATE temperature SET temp_current = '$temp' WHERE temp_id = '$temperature[temp_id]'");

View File

@@ -508,7 +508,53 @@ function apachehitsgraphUnix ($rrd, $graph, $from, $to, $width, $height, $title,
}
}
function unixfsgraph ($device, $graph, $from, $to, $width, $height, $title, $vertical) {
function unixfsgraph ($id, $graph, $from, $to, $width, $height, $title, $vertical) {
global $rrdtool, $installdir, $mono_font;
$optsa = array( "--start", $from, "--end", $to, "--width", $width, "--height", $height, "--vertical-label", $vertical, "--alt-autoscale-max",
"-l 0",
"-E",
"-b 1024",
"--title", $title);
$imgfile = "graphs/" . "$graph";
$iter = "1";
$sql = mysql_query("SELECT * FROM storage where storage_id = '$id'");
$optsa[] = "COMMENT: Size Used %age\l";
while($fs = mysql_fetch_array($sql)) {
$hostname = gethostbyid($fs['host_id']);
if($iter=="1") {$colour="CC0000";} elseif($iter=="2") {$colour="008C00";} elseif($iter=="3") {$colour="4096EE";
} elseif($iter=="4") {$colour="73880A";} elseif($iter=="5") {$colour="D01F3C";} elseif($iter=="6") {$colour="36393D";
} elseif($iter=="7") {$colour="FF0084"; $iter = "0"; }
$descr = str_pad($fs[hrStorageDescr], 16);
$descr = substr($descr,0,16);
$text = str_replace("/", "_", $fs['hrStorageDescr']);
$optsa[] = "DEF:$fs[storage_id]=rrd/$hostname-storage-$text.rrd:used:AVERAGE";
$optsa[] = "DEF:$fs[storage_id]s=rrd/$hostname-storage-$text.rrd:size:AVERAGE";
$optsa[] = "DEF:$fs[storage_id]p=rrd/$hostname-storage-$text.rrd:perc:AVERAGE";
$optsa[] = "LINE1.25:$fs[storage_id]p#" . $colour . ":$descr";
$optsa[] = "GPRINT:$fs[storage_id]s:LAST:%6.2lf%SB";
$optsa[] = "GPRINT:$fs[storage_id]:LAST:%6.2lf%SB";
$optsa[] = "GPRINT:$fs[storage_id]p:LAST:%3.0lf%%\l";
$iter++;
}
if($width <= "300") {$optsb = array("--font", "LEGEND:7:$mono_font",
"--font", "AXIS:6:$mono_font",
"--font-render-mode", "normal");}
$opts = array_merge($optsa, $optsb);
$ret = rrd_graph("$imgfile", $opts, count($opts));
if( !is_array($ret) ) {
$err = rrd_error();
#echo "rrd_graph() ERROR: $err\n";
return FALSE;
} else {
return $imgfile;
}
}
function unixfsgraph_dev ($device, $graph, $from, $to, $width, $height, $title, $vertical) {
global $rrdtool, $installdir, $mono_font;
$optsa = array( "--start", $from, "--end", $to, "--width", $width, "--height", $height, "--vertical-label", $vertical, "--alt-autoscale-max",
"-l 0",