I got some good replies to my other (first!) posting, so I thought I'd post my whole script here.

This script collects connection information from a F5 BigIP load-balancer (runs BSDi) and generates some nice graphs.

The data structures are really ugly, and I'd love to have some Wise Monks show me how to make this more efficent and clean.

Note: SimpleGraph is a homebrew module which I can not release due to licensing.

#!/usr/bin/perl use simplegraph; # %client_ip = (); # %frontend = (); # %total_conn = (); %vips = (); %scale = (); %name = (); $iteration = 0; # Set the graph max scale per server $scale{'64.210.209.50'} = 3500; $scale{'64.210.209.51'} = 2000; $scale{'64.210.209.54'} = 3500; $scale{'64.210.209.56'} = 100; $scale{'64.210.209.61'} = 3000; $scale{'64.210.209.132'} = 500; # Set VIPs -> names mapping $name{'64.210.209.50'} = 'www.zwire.com'; $name{'64.210.209.51'} = 'www.adquest3d.com'; $name{'64.210.209.54'} = 'bannerads.zwire.com'; $name{'64.210.209.56'} = 'sitemanager.zwire.com'; $name{'64.210.209.61'} = 'imagesource.zwire.com'; $name{'64.210.209.132'} = 'www.carcast.com'; # Loop forever while(1) { $iteration++; # Reset data @connections = `bigpipe conn dump`; foreach $line (@connections) { if ($line =~ /^\s*(\d+\.\d+\.\d+\.\d+):\d+ \s*->\s*(\d+\.\d+\.\d+\.\d+):\d+ \s*->\s*(\d+\.\d+\.\d+\.\d+)/x) { # $client_ip{$1}{$iteration}++; $vips{$2}{$iteration}++; # $frontend{$3}{$iteration}++; } } # Push our new data onto the stack, but remove from the queue if we ha +ve more than 50 foreach $k (keys %vips) { push @{$vips{$k}{'stack'}}, $vips{$k}{$iteration}; if ( $#{ $vips{$k}{'stack'} } > 50 ) { shift @{$vips{$k}{'stack'}}; } } # Make a graph for each VIP foreach $k (keys %vips) { if ($name{$k}) { $label = $name{$k}." connections"; } else { # Skip VIPs that aren't in %name, we don't care about +them next; } my $image = SimpleGraph->new( width => 230, height => 120, yscale => $scale{$k}, marginwidth => 5, borderright => 5, borderleft => 30, gridlabels => yes, gridlines => ($scale{$k} / 4), label => $label, ); my $temp = $vips{$k}{'stack'}; $image->PlotSeries( color => "0,0,255", data => $temp, ); $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`; } sleep 10; }
<-> In general, we find that those who disparage a given operating system, language, or philosophy have never had to use it in pratice. <->

In reply to Need some data structures cooked by ibanix

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.