in reply to Need some data structures cooked
Update: As dws points out below, I completly missed the hash growth problem. I added a line below to deal with that (and corrected my obligatory typo also pointed out to me by dws Thanks!)
I didn't think that there was too much wrong with your data structures. You could squash the 3 hashes into 1 but they seem okay as they are. Actually I didn't see to much wrong at all with your code, though I do use warning and strict religously, they aren't obligatory. You really should be checking the return codes from your backtick commands, I left this as comments as I don't know what values would be correct for those two programs. You could probably recode the ... unless $? == 0 to be ... if $?; but you'll need to check the docs for the right values.
Given your code as a starting point there are a few things that I would do differently but most of them are a matter of taste rather than any real benefit.
I offer my lightly reworked version of your code which you may or may not find useful.
#!/usr/bin/perl -w use strict; #use simplegraph; my %vips = (); # Set the graph max scale per server my %scale = ( '64.210.209.50' => 3500, '64.210.209.51' => 2000, '64.210.209.54' => 3500, '64.210.209.56' => 100, '64.210.209.61' => 3000, '64.210.209.132' => 500 ); # Set VIPs -> names mapping my %name = ( '64.210.209.50' => 'www.zwire.com', '64.210.209.51' => 'www.adquest3d.com', '64.210.209.54' => 'bannerads.zwire.com', '64.210.209.56' => 'sitemanager.zwire.com', '64.210.209.61' => 'imagesource.zwire.com', '64.210.209.132' => 'www.carcast.com', ); my $re_ip = qr/(\d+\.\d+\.\d+\.\d+):\d+/; my $re_line = qr/ ^ \s* $re_ip \s* -> \s* $re_ip \s* -> \s* $re_ip /x; my $iteration = 0; # Loop forever do { $iteration++; # Reset data my @connections = `bigpipe conn dump`; # You'll have to check docs for bigpipe to decide what constitutes + a failure code # warn "bigpipe failed with rc:$?\n" and next unless $? >> 8 == 0; +# or whatever foreach my $line (@connections) { $vips{$2}{$iteration}++ if ($line =~ /$re_line/); } # Push our new data onto the stack, but remove from the queue if w +e have more than 50 foreach my $k (keys %vips) { push @{$vips{$k}{'stack'}}, $vips{$k}{$iteration}; shift @{$vips{$k}{'stack'}} if $#{$vips{$k}{'stack'}} > 50; ## THIS LINE SHOULD BE ADDED!! See [dws]'s post below. delete $vips{$k}{$iteration}; } # Make a graph for each VIP foreach my $k (keys %vips) { # Skip VIPs that aren't in %name, we don't care about them next unless $name{$k}; my $image = SimpleGraph->new( width => 230, height => 120, yscale => $scale{$k}, marginwidth => 5, borderright => 5, borderleft => 30, gridlabels => 'yes', gridlines => ($scale{$k} / 4), label => $name{$k}." connections", ); $image->PlotSeries( color => "0,0,255", data => $vips{$k}{'st +ack'} ); $image->Draw( file => "/usr/local/www/local/connections +$k.tmp" ); `mv -f /usr/local/www/local/connections$k.tmp /usr/local/www/l +ocal/connections$k.gif`; # warn "mv failed with rc:$?\n" unless $? >> 8 == 0; # or whate +ver? } } while(sleep 10);
Okay you lot, get your wings on the left, halos on the right. It's one size fits all, and "No!", you can't have a different color.
Pick up your cloud down the end and "Yes" if you get allocated a grey one they are a bit damp under foot, but someone has to get them.
Get used to the wings fast cos its an 8 hour day...unless the Govenor calls for a cyclone or hurricane, in which case 16 hour shifts are mandatory.
Just be grateful that you arrived just as the tornado season finished. Them buggers are real work.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Need some data structures cooked
by dws (Chancellor) on Nov 20, 2002 at 01:28 UTC |