9 my $dbh = nms::db_connect();
11 GD::Image->trueColor(1);
12 $img = GD::Image->new('bg07.png');
14 my $blk = $img->colorResolve(0, 0, 0);
17 my $i = 3.0 * ($y - 236.0) / (42.0 - 237.0);
18 my $clr = get_color($i);
20 $img->filledRectangle(12,$y,33,$y+1,$clr);
23 $img->stringFT($blk, "/usr/share/fonts/truetype/msttcorefonts/Arial.ttf", 10, 0, 40, 47 + (236-42)*0.0/3.0, "1 Gbit/sec");
24 $img->stringFT($blk, "/usr/share/fonts/truetype/msttcorefonts/Arial.ttf", 10, 0, 40, 47 + (236-42)*1.0/3.0, "100 Mbit/sec");
25 $img->stringFT($blk, "/usr/share/fonts/truetype/msttcorefonts/Arial.ttf", 10, 0, 40, 47 + (236-42)*2.0/3.0, "10 Mbit/sec");
26 $img->stringFT($blk, "/usr/share/fonts/truetype/msttcorefonts/Arial.ttf", 10, 0, 40, 47 + (236-42)*3.0/3.0, "1 Mbit/sec");
27 $img->stringFT($blk, "/usr/share/fonts/truetype/msttcorefonts/Arial.ttf", 10, 0, 1000, 620, "NMS (C) 2005-2007 Tech:Server");
29 my $q = $dbh->prepare('select switch,port,bytes_in,bytes_out,placement,switchtype from switches natural join placements natural join get_datar
30 ate() where switchtype in (\'es3024\')');
32 while (my $ref = $q->fetchrow_hashref()) {
35 # 100kbit/port = all green
36 # 1gbit/port = all red
40 if (defined($ref->{'bytes_in'})) {
42 my $traffic = 4.0 * $ref->{'bytes_in'} + $ref->{'bytes_out'}; # average and convert to bits (should be about the same in practice)
44 my $max = 1_000_000_000.0; # 1Gbit
45 my $min = 1_000_000.0; # 1Mbit
46 if ($traffic >= $min) {
47 $intensity = log($traffic / $min) / log(10);
48 $intensity = 3.0 if ($intensity > 3.0);
50 $clr = get_color($intensity);
52 $clr = $img->colorResolve(0, 0, 255);
55 $ref->{'placement'} =~ /\((\d+),(\d+)\),\((\d+),(\d+)\)/;
56 my $npo = ($ref->{'switchtype'} eq 'es3024') ? 26 : 25;
57 my $f = ($ref->{'port'} - 1) % 2;
58 my $po = ($ref->{'port'} - 1 - $f)/2;
59 my $h = 2*($2-$4)/$npo;
62 $img->filledRectangle($3+$w*$f,$4+$po*$h,$3+$w+$w*$f,$4+$h*($po+1),$clr);
63 # $img->rectangle($3+$w*$f,$4+$po*$h,$3+$w+$w*$f,$4+$h*($po+1),$blk);
64 $img->rectangle($3,$4,$1,$2,$blk);
68 print $cgi->header(-type=>'image/png');
72 my $intensity = shift;
74 if ($intensity > 2.0) {
75 return $img->colorResolve(255.0, 255.0 * (($intensity - 2.0) ** $gamma), 255.0 * (($intensity - 2.0) ** $gamma));
76 } elsif ($intensity > 1.0) {
77 return $img->colorResolve(255.0, 255.0 * ((2.0 - $intensity) ** $gamma), 0);
79 return $img->colorResolve(255.0 * ($intensity ** $gamma), 255, 0);