6 my $dbh = DBI->connect("dbi:Pg:dbname=snmpfetch;host=violet.tg05.gathering.org", "snmpfetch", "removed")
7 or die "Couldn't connect to database";
8 print $cgi->header(-type=>'text/html', -refresh=>'45; http://nms.tg05.gathering.org/nettkart-telnet.pl');
13 <title>nettkart - telnet</title>
19 my $q = $dbh->prepare('select * from switches natural join placements natural left join
20 ( select switch,sum(bytes_in)/count(*) as
21 bytes_in,sum(bytes_out)/count(*) as bytes_out from get_datarate() group
24 while (my $ref = $q->fetchrow_hashref()) {
25 $ref->{'placement'} =~ /\((\d+),(\d+)\),\((\d+),(\d+)\)/;
27 my $traffic = 4.0 * $ref->{'bytes_in'} + $ref->{'bytes_out'}; # average and convert to bits (should be about the same in practice)
29 if ($traffic >= 1_000_000_000) {
30 $ttext = sprintf "%.2f Gbit/port/sec", $traffic/1_000_000_000;
31 } elsif ($traffic => 1_000_000) {
32 $ttext = sprintf "%.2f Mbit/port/sec", $traffic/1_000_000;
34 $ttext = sprintf "%.2f kbit/port/sec", $traffic/1_000;
37 printf " <area shape=\"rect\" coords=\"%u,%u,%u,%u\" target=\"blank\" href=\"telnet://$ref->{'ip'}\" alt=\"%s (%s)\" onmouseover=\"window.status='%s (%s)'; return true\" onmouseout=\"window.status=''\" />\n",
38 $3, $4, $1, $2, $ref->{'switch'}, $ref->{'sysname'},
39 $ttext, $ref->{'sysname'}, $ttext;
46 <p><img src="nettkart.pl" usemap="#switches" /></p>