Adding total traffic per device graph generation

git-svn-id: http://www.observium.org/svn/observer/trunk@57 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
Adam Amstrong
2007-04-04 14:25:17 +00:00
parent d4c81b44ea
commit 5154885182
4 changed files with 97 additions and 8 deletions
+13 -8
View File
@@ -11,12 +11,14 @@
include("includes/authenticate.inc");
if($_GET['host']) {
$hostid = $_GET['host'];
$device = $_GET['host'];
} elseif($_GET['device']) {
$device = $_GET['device'];
} else {
$hostid = getifhost($_GET['if']);
$device = getifhost($_GET['if']);
$ifIndex = getifindexbyid($_GET['if']);
}
$hostname = gethostbyid($hostid);
$hostname = gethostbyid($device);
$from = $_GET['from'];
$to = $_GET['to'];
$width = $_GET['width'];
@@ -28,10 +30,13 @@
$graphfile = $hostname . ".". $ifIndex . "-" . $type . ".png";
$os = gethostosbyid($hostid);
$os = gethostosbyid($device);
switch ($type) {
case 'device_bits':
$graph = graph_device_bits ($device, $graphfile, $from, $to, $width, $height, $title, $vertical);
break;
case 'bits':
$graph = trafgraph ($hostname . ".". $ifIndex . ".rrd", $graphfile, $from, $to, $width, $height, $title, $vertical);
break;
@@ -48,7 +53,7 @@
$graph = uptimegraph ($hostname . "-uptime.rrd", $graphfile, $from, $to, $width, $height, $title, $vertical);
break;
case 'unixfs':
$graph = unixfsgraph ($hostid, $graphfile, $from, $to, $width, $height, $title, $vertical);
$graph = unixfsgraph ($device, $graphfile, $from, $to, $width, $height, $title, $vertical);
break;
case 'calls':
$graph = callsgraphSNOM ($hostname . "-data.rrd", $graphfile, $from, $to, $width, $height, $title, $vertical);
@@ -79,7 +84,7 @@
}
break;
case 'temp':
$graph = temp_graph ($hostid, $graphfile, $from, $to, $width, $height, $title, $vertical);
$graph = temp_graph ($device, $graphfile, $from, $to, $width, $height, $title, $vertical);
break;
case 'mem':
if($os == "Linux" || $os == "FreeBSD" || $os == "DragonFly" || $os == "OpenBSD" || $os == "NetBSD" ) {
@@ -116,7 +121,7 @@
break;
case 'unixfs':
if($os == "Linux" || $os == "FreeBSD" || $os == "DragonFly" || $os == "OpenBSD" || $os == "NetBSD" ) {
$graph = unixfsgraph ($hostid, $graphfile, $from, $to, $width, $height, $title, $vertical);
$graph = unixfsgraph ($device, $graphfile, $from, $to, $width, $height, $title, $vertical);
}
break;
case 'postfix':
+4
View File
@@ -50,7 +50,11 @@ echo("</table></div>");
echo("</td><td width=50% valign=top>");
if($interfaces['total']) {
echo("<div style='background-color: #eeeeee; margin: 5px; padding: 5px;'>
<p class=sectionhead>Total Traffic</p>" . device_traffic_image($device['id'], 490, 100, $day, $now) . "</div>");
}
if($interfaces['total']) {
echo("<div style='background-color: #eeeeee; margin: 5px; padding: 5px;'>");
echo("<p class=sectionhead>Interfaces</p><div style='height: 5px;'></div>");
+5
View File
@@ -68,6 +68,11 @@ function generatedevicelink($device, $text=0) {
return $link;
}
function device_traffic_image($device, $width, $height, $from, $to) {
return "<img src='graph.php?device=" . $device . "&type=device_bits&from=" . $from . "&to=" . $to . "&width=" . $width . "&height=" . $height . "' />";
}
function devclass($device) {
if ($device['status'] == '0') { $class = "list-device-down"; } else { $class = "list-device"; }
if ($device['ignore'] == '1') {
+75
View File
@@ -40,4 +40,79 @@ function temp_graph ($device, $graph, $from, $to, $width, $height, $title, $vert
}
}
function graph_device_bits ($device, $graph, $from, $to, $width, $height)
{
global $rrdtool, $installdir, $mono_font, $rrd_dir;
$imgfile = "graphs/" . "$graph";
$opts = array( "--alt-autoscale-max",
"-E",
"--start", $from, "--end", $to,
"--width", $width, "--height", $height);
$hostname = gethostbyid($device);
$query = mysql_query("SELECT `ifIndex` FROM `interfaces` WHERE `host` = '$device'");
while($int = mysql_fetch_row($query)) {
$this_opts = array ("DEF:inoctets" . $int[0] . "=" . $rrd_dir . "/" . $hostname . "." . $int[0] . ".rrd:INOCTETS:AVERAGE",
"DEF:outoctets" . $int[0] . "=" . $rrd_dir . "/" . $hostname . "." . $int[0] . ".rrd:OUTOCTETS:AVERAGE");
$in_thing .= $seperator . "inoctets" . $int[0] . ",UN,0," . "inoctets" . $int[0] . ",IF";
$out_thing .= $seperator . "outoctets" . $int[0] . ",UN,0," . "outoctets" . $int[0] . ",IF";
$pluses .= $plus;
$seperator = ",";
$plus = ",+";
$opts = array_merge($opts, $this_opts);
}
$opts_end = array(
"CDEF:inoctets=" . $in_thing . $pluses,
"CDEF:outoctets=" . $out_thing . $pluses,
"CDEF:doutoctets=outoctets,-1,*",
"CDEF:inbits=inoctets,8,*",
"CDEF:outbits=outoctets,8,*",
"CDEF:doutbits=doutoctets,8,*",
"AREA:inbits#CDEB8B:",
"COMMENT:BPS Current Average Max 95th %\\n",
"LINE1.25:inbits#006600:In ",
"GPRINT:inbits:LAST:%6.2lf%s",
"GPRINT:inbits:AVERAGE:%6.2lf%s",
"GPRINT:inbits:MAX:%6.2lf%s\l",
"AREA:doutbits#C3D9FF:",
"LINE1.25:doutbits#000099:Out",
"GPRINT:outbits:LAST:%6.2lf%s",
"GPRINT:outbits:AVERAGE:%6.2lf%s",
"GPRINT:outbits:MAX:%6.2lf%s",
);
$opts = array_merge($opts, $opts_end);
if($width <= "300") {
$this_opts = array("--font", "LEGEND:7:$mono_font",
"--font", "AXIS:6:$mono_font",
"--font-render-mode", "normal");
$opts = array_merge($opts, $this_opts);
}
# echo("<pre>");
# print_r ($opts);
$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;
}
}
?>