add mac accounting improvements and fixes to graph display page

git-svn-id: http://www.observium.org/svn/observer/trunk@471 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
Adam Amstrong
2009-09-22 12:02:54 +00:00
parent 128a26a4f1
commit 661d0935a3
9 changed files with 134 additions and 77 deletions

View File

@@ -30,6 +30,7 @@ RewriteRule ^vrf/(.+)/(.+)/(.+)/ ?page=vrf&id=$1&opta=$2&optb=$3
RewriteRule ^vrf/(.+)/(.+)/ ?page=vrf&id=$1&opta=$2
RewriteRule ^vrf/(.+)/ ?page=vrf&id=$1
RewriteRule ^device/([0-9]+)/([a-z]+)/(.+)/(.+)/(.+)/(.+)/(.+)/ ?page=device&id=$1&section=$2&opta=$3&optb=$4&optc=$5&optd=$6&opte=$7
RewriteRule ^device/([0-9]+)/([a-z]+)/(.+)/(.+)/(.+)/(.+)/ ?page=device&id=$1&section=$2&opta=$3&optb=$4&optc=$5&optd=$6
RewriteRule ^device/([0-9]+)/([a-z]+)/(.+)/(.+)/(.+)/ ?page=device&id=$1&section=$2&opta=$3&optb=$4&optc=$5
RewriteRule ^device/([0-9]+)/([a-z]+)/(.+)/(.+)/ ?page=device&id=$1&section=$2&opta=$3&optb=$4

View File

@@ -0,0 +1,10 @@
<?php
$cpu = only_alphanumeric($_GET['cpu']);
$dir = $config['collectd_dir'] . "/" . $hostname ."/cpu-" . $cpu;
$graph = graph_collectd_cpu ($dir, $graphfile, $from, $to, $width, $height, $title, $vertical);
?>

View File

@@ -0,0 +1,65 @@
<?php
function graph_mac_acc_total ($interface, $graph, $from, $to, $width, $height, $title, $vertical) {
global $config, $installdir;
list($interface, $type) = explode("-", $interface);
$imgfile = $config['install_dir'] . "/graphs/" . "$graph";
$options = "--alt-autoscale-max -E --start $from --end " . ($to - 150) . " --width $width --height $height ";
$options .= $config['rrdgraph_def_text'];
if($height < "99") { $options .= " --only-graph "; }
$hostname = gethostbyid($device);
$sql = "SELECT *, (bps_in + bps_out) AS bps FROM `mac_accounting` AS M, `interfaces` AS I, `devices` AS D WHERE M.interface_id = '$interface'
AND I.interface_id = M.interface_id AND I.device_id = D.device_id ORDER BY bps DESC LIMIT 0,10";
$query = mysql_query($sql);
if($width <= "300") { $options .= "--font LEGEND:7:".$config['mono_font']." --font AXIS:6:".$config['mono_font']." --font-render-mode normal "; }
$pluses = ""; $iter = '0';
$options .= " COMMENT:' In Out\\\\n'";
while($acc = mysql_fetch_array($query)) {
if($type == "pkts") {
$this_rrd = $config['rrd_dir'] . "/" . $acc['hostname'] . "/mac-accounting/" . $acc['ifIndex'] . "-" . $acc['mac'] . "-pkts.rrd";
$units='pps';
} else {
$this_rrd = $config['rrd_dir'] . "/" . $acc['hostname'] . "/mac-accounting/" . $acc['ifIndex'] . "-" . $acc['mac'] . ".rrd";
$units='bps';
}
if(is_file($this_rrd)) {
$name = $acc['mac'];
$addy = mysql_fetch_array(mysql_query("SELECT * FROM ipv4_mac where mac_address = '".$acc['mac']."'"));
if($addy) {
$name = @gethostbyaddr($addy['ipv4_address']);
}
$this_id = str_replace(".", "", $acc['mac']);
if(!$config['graph_colours'][$iter]) { $iter = 0; }
$colour=$config['graph_colours'][$iter];
$descr = str_pad($name, 36);
$descr = substr($descr,0,36);
$options .= " DEF:in".$this_id."=$this_rrd:IN:AVERAGE ";
$options .= " DEF:out".$this_id."temp=$this_rrd:OUT:AVERAGE ";
$options .= " CDEF:inB".$this_id."=in".$this_id.",8,* ";
$options .= " CDEF:outB".$this_id."temp=out".$this_id."temp,8,*";
$options .= " CDEF:outB".$this_id."=outB".$this_id."temp,-1,*";
$options .= " CDEF:octets".$this_id."=inB".$this_id.",outB".$this_id."temp,+";
$options .= " VDEF:totin".$this_id."=inB".$this_id.",TOTAL";
$options .= " VDEF:totout".$this_id."=outB".$this_id."temp,TOTAL";
$options .= " VDEF:tot".$this_id."=octets".$this_id.",TOTAL";
$options .= " AREA:inB".$this_id."#" . $colour . ":'" . $descr . "':STACK";
if($optionsb) {$stack="STACK";}
$optionsb .= " AREA:outB".$this_id."#" . $colour . "::$stack";
$options .= " GPRINT:inB".$this_id.":LAST:%6.2lf%s$units";
$options .= " GPRINT:totin".$this_id.":\(%6.2lf%sB\)";
$options .= " GPRINT:outB".$this_id."temp:LAST:%6.2lf%s$units";
$options .= " GPRINT:totout".$this_id.":\(%6.2lf%sB\)\\\\n";
$iter++;
}
}
$options .= $optionsb;
$thing = shell_exec($config['rrdtool'] . " graph $imgfile $options");
return $imgfile;
}
$port = $_GET['if'];
$graph = graph_mac_acc_total ($port, $graphfile, $from, $to, $width, $height, $title, $vertical);
?>

View File

@@ -176,7 +176,7 @@ echo("</td>");
echo("</td></tr>");
// If we're showing graphs, generate the graph and print the img tags
if($graph_type && is_file($config['rrd_dir'] . "/" . $hostname . "/". $interface['ifIndex'] . ".rrd")) {
if($graph_type && is_file($config['rrd_dir'] . "/" . $device['hostname'] . "/". $interface['ifIndex'] . ".rrd")) {
$type = $graph_type;

View File

@@ -62,7 +62,7 @@ echo("
echo(" | Mac Accounting :
<a href='".$config['base_url']."/device/" . $device['device_id'] . "/interface/".$interface['interface_id']."/macaccounting/bits/'>Bits</a>
(<a href='".$config['base_url']."/device/" . $device['device_id'] . "/interface/".$interface['interface_id']."/macaccounting/bits/thumbs/'>Mini</a>) |
(<a href='".$config['base_url']."/device/" . $device['device_id'] . "/interface/".$interface['interface_id']."/macaccounting/bits/thumbs/'>Mini</a>|<a href='".$config['base_url']."/device/" . $device['device_id'] . "/interface/".$interface['interface_id']."/macaccounting/bits/top10/'>Top10</a>) |
<a href='".$config['base_url']."/device/" . $device['device_id'] . "/interface/".$interface['interface_id']."/macaccounting/pkts/'>Packets</a>
(<a href='".$config['base_url']."/device/" . $device['device_id'] . "/interface/".$interface['interface_id']."/macaccounting/pkts/thumbs/'>Mini</a>)");
}

View File

@@ -17,28 +17,56 @@
$i = 1;
$inf = fixifName($ifname);
$query = mysql_query("SELECT *, (M.bps_in + M.bps_out) as bps FROM `mac_accounting` AS M, `interfaces` AS I, `devices` AS D WHERE M.interface_id = '".$interface['interface_id']."' AND I.interface_id = M.interface_id AND I.device_id = D.device_id ORDER BY bps DESC");
echo("<div style='clear: both;'>");
if($_GET['optd'] == "top10") {
if($_GET['opte']) {
$from = "-" . $_GET['opte'];
} else { $from = "-1day"; }
echo("<div style='margin: auto; width: 831px;';>
<img src='".$config['base_url']."/graph.php?if=".$interface['interface_id']."&type=mac_acc_total&from=$from&to=now&width=750&height=245' />
<div style='width: 200; float: left;'>
<span class=device-head style='line-height: 30px;'>Day</span>
<a href='".$config['base_url']."/device/" . $device['device_id'] . "/interface/".$interface['interface_id']."/macaccounting/bits/top10/1day/'>
<img src='".$config['base_url']."/graph.php?if=".$interface['interface_id']."&type=mac_acc_total&from=-1day&to=now&width=150&height=50' />
</a>
</div>
<div style='width: 200; float: left;'>
<span class=device-head style='line-height: 30px;'>Week</span>
<a href='".$config['base_url']."/device/" . $device['device_id'] . "/interface/".$interface['interface_id']."/macaccounting/bits/top10/1week/'>
<img src='".$config['base_url']."/graph.php?if=".$interface['interface_id']."&type=mac_acc_total&from=-1week&to=now&width=150&height=50' />
</a>
</div>
<div style='width: 200; float: left;'>
<span class=device-head style='line-height: 30px;'>Month</span>
<a href='".$config['base_url']."/device/" . $device['device_id'] . "/interface/".$interface['interface_id']."/macaccounting/bits/top10/1month/'>
<img src='".$config['base_url']."/graph.php?if=".$interface['interface_id']."&type=mac_acc_total&from=-1month&to=now&width=150&height=50' />
</a>
</div>
<div style='width: 200; float: left;'>
<span class=device-head style='line-height: 30px;'>Year</span>
<a href='".$config['base_url']."/device/" . $device['device_id'] . "/interface/".$interface['interface_id']."/macaccounting/bits/top10/1year/'>
<img src='".$config['base_url']."/graph.php?if=".$interface['interface_id']."&type=mac_acc_total&from=-1year&to=now&width=150&height=50' />
</a>
</div>
</div>
");
unset($query);
}
while($acc = mysql_fetch_array($query)) {
if(!is_integer($i/2)) { $row_colour = $list_colour_a; } else { $row_colour = $list_colour_b; }
$addy = mysql_fetch_array(mysql_query("SELECT * FROM ipv4_mac where mac_address = '".$acc['mac']."'"));
$name = gethostbyaddr($addy['ipv4_address']);
if($name == $addy['ipv4_address']) { unset ($name); }
if(mysql_result(mysql_query("SELECT count(*) FROM bgpPeers WHERE device_id = '".$acc['device_id']."' AND bgpPeerIdentifier = '".$addy['ipv4_address']."'"),0)) {
$peer_query = mysql_query("SELECT * FROM bgpPeers WHERE device_id = '".$acc['device_id']."' AND bgpPeerIdentifier = '".$addy['ipv4_address']."'");
$peer_info = mysql_fetch_array($peer_query);
} else { unset ($peer_info); }
if($peer_info) { $asn = "AS".$peer_info['bgpPeerRemoteAs']; $astext = $peer_info['astext']; } else {
unset ($as); unset ($astext); unset($asn);
}
@@ -84,13 +112,10 @@
$daily_traffic = "graph.php?id=" . $acc['ma_id'] . "&type=$graph_type&from=$day&to=$now&width=210&height=100";
$daily_url = "graph.php?id=" . $acc['ma_id'] . "&type=$graph_type&from=$day&to=$now&width=500&height=150";
$weekly_traffic = "graph.php?id=" . $acc['ma_id'] . "&type=$graph_type&from=$week&to=$now&width=210&height=100";
$weekly_url = "graph.php?id=" . $acc['ma_id'] . "&type=$graph_type&from=$week&to=$now&width=500&height=150";
$monthly_traffic = "graph.php?id=" . $acc['ma_id'] . "&type=$graph_type&from=$month&to=$now&width=210&height=100";
$monthly_url = "graph.php?id=" . $acc['ma_id'] . "&type=$graph_type&from=$month&to=$now&width=500&height=150";
$yearly_traffic = "graph.php?id=" . $acc['ma_id'] . "&type=$graph_type&from=$year&to=$now&width=210&height=100";
$yearly_url = "graph.php?id=" . $acc['ma_id'] . "&type=$graph_type&from=$year&to=$now&width=500&height=150";
@@ -103,7 +128,6 @@
echo("<a href='?page=interface&id=" . $interface['ma_id'] . "' onmouseover=\"return overlib('<img src=\'$yearly_url\'>', LEFT".$config['overlib_defaults'].", WIDTH, 350);\" onmouseout=\"return nd();\">
<img src='$yearly_traffic' border=0></a>");
echo("</div>");
$i++;
}

View File

@@ -34,7 +34,6 @@ echo("
if($_GET['opta'] == graphs ) {
if($_GET['optb']) { $graph_type = $_GET['optb']; } else { $graph_type = "bits"; }
$dographs = 1;
}
if($_GET['optc'] == thumbs) {

View File

@@ -571,47 +571,6 @@ function graph_mac_acc ($id, $graph, $from, $to, $width, $height) {
}
function graph_mac_acc_interface ($interface, $graph, $from, $to, $width, $height) {
global $config, $installdir;
$imgfile = $config['install_dir'] . "/graphs/" . "$graph";
$options = "--alt-autoscale-max -E --start $from --end " . ($to - 150) . " --width $width --height $height ";
$options .= $config['rrdgraph_def_text'];
if($height < "99") { $options .= " --only-graph"; }
$hostname = gethostbyid($device);
$query = mysql_query("SELECT * FROM `mac_accounting` AS M, `interfaces` AS I, `devices` AS D WHERE M.interface_id = '$interface' AND I.interface_id = M.interface_id AND I.device_id = D.device_id");
if($width <= "300") { $options .= "--font LEGEND:7:".$config['mono_font']." --font AXIS:6:".$config['mono_font']." --font-render-mode normal "; }
$pluses = "";
$options .= " COMMENT:' In Out\\\\n'";
while($acc = mysql_fetch_array($query)) {
$this_rrd = $config['rrd_dir'] . "/" . $acc['hostname'] . "/mac-accounting/" . $acc['ifIndex'] . "-" . $acc['peer_ip'] . ".rrd";
if(is_file($this_rrd)) {
$this_id = str_replace(".", "", $acc['peer_ip']);
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); } else {$colour="C600C6";}
$descr = str_pad($acc['peer_desc'], 36);
$descr = substr($descr,0,36);
$options .= " DEF:in".$this_id."=$this_rrd:IN:AVERAGE ";
$options .= " DEF:out".$this_id."temp=$this_rrd:OUT:AVERAGE ";
$options .= " CDEF:out".$this_id."=out".$this_id."temp,-1,* ";
$options .= " CDEF:octets".$this_id."=in".$this_id.",out".$this_id."temp,+";
$options .= " VDEF:totin".$this_id."=in".$this_id.",TOTAL";
$options .= " VDEF:totout".$this_id."=out".$this_id."temp,TOTAL";
$options .= " VDEF:tot".$this_id."=octets".$this_id.",TOTAL";
$options .= " LINE1.25:in".$this_id."#" . $colour . ":'" . $descr . "'";
$options .= " LINE1.25:out".$this_id."#" . $colour . "::";
$options .= " GPRINT:in".$this_id.":LAST:%6.2lf%sbps";
$options .= " GPRINT:totin".$this_id.":\(%6.2lf%sB\)";
$options .= " GPRINT:out".$this_id."temp:LAST:%6.2lf%sbps";
$options .= " GPRINT:totout".$this_id.":\(%6.2lf%sB\)\\\\n";
$iter++;
}
}
#echo($config['rrdtool'] . " graph $imgfile $options");
$thing = shell_exec($config['rrdtool'] . " graph $imgfile $options");
return $imgfile;
}
function graph_bits ($rrd, $graph, $from, $to, $width, $height, $title, $vertical, $inverse = '0', $legend = '1') {
global $config;
$database = $config['rrd_dir'] . "/" . $rrd;

View File

@@ -1,6 +1,5 @@
<?php
function formatMac($mac) {
$mac = preg_replace("/(..)(..)(..)(..)(..)(..)/", "\\1:\\2:\\3:\\4:\\5:\\6", $mac);
return $mac;