diff --git a/html/graph.php b/html/graph.php index f32cdf05b..0faeab8c9 100644 --- a/html/graph.php +++ b/html/graph.php @@ -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': diff --git a/html/pages/device/dev-overview.inc b/html/pages/device/dev-overview.inc index 54392313e..dd4126acd 100644 --- a/html/pages/device/dev-overview.inc +++ b/html/pages/device/dev-overview.inc @@ -50,7 +50,11 @@ echo(""); echo(""); if($interfaces['total']) { + echo("
+

Total Traffic

" . device_traffic_image($device['id'], 490, 100, $day, $now) . "
"); +} +if($interfaces['total']) { echo("
"); echo("

Interfaces

"); diff --git a/includes/functions.php b/includes/functions.php index 5785e7047..cc51b88bb 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -68,6 +68,11 @@ function generatedevicelink($device, $text=0) { return $link; } + +function device_traffic_image($device, $width, $height, $from, $to) { + return ""; +} + function devclass($device) { if ($device['status'] == '0') { $class = "list-device-down"; } else { $class = "list-device"; } if ($device['ignore'] == '1') { diff --git a/includes/graphing.php b/includes/graphing.php index dbf573507..414f260fa 100644 --- a/includes/graphing.php +++ b/includes/graphing.php @@ -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("
");
+#  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;
+  }
+}
+
+
 ?>