General discussion
October 15, 2007 at 06:35 PM
danlm

hash of hash’s question – perl

by danlm . Updated 18 years, 10 months ago

Problem:
Server that hosts multiple accounts which each has an outside ip that is defined within the rc.conf.local of a BSD machine. Bandwidth statistics are only provided for the full machine via the router and not by ip. Due to having a limit on bandwidth, a monitor of each ip’s bandwidth would be prudent.

Solution:
The software firewall records bandwidth that passe’s through rule sets. Set up labels to each rule set and you can see what the bandwidth is used for that rule-set(ip). This is then recorded to a database that has breakdowns by 5 minute intervals, 1 day intervals, monthly intervals, and year to date intervals.

Problem:
Graphical representation of this usage. Easy enough to pull the data from the database, but not necessarily easy to build hash Perl hash tables that can be used to produce graphical representation with. Not all ip’s will have bandwidth, so you don’t want to spend the time representing that in the graphic.

Perl hash of hash is perfect data structure for storing the database information. First key level of hash would be your firewall rule set label name.
ie:
debb
20071010 had bandwidth of 50000
dan
20071001 had bandwidth of 2000
steven
20071001 had bandwidth of 0
ssh
20071001 had bandwidth of 25000
20071002 had bandwidth of 100000
20071003 had bandwidth of 10000

hash table name is %CapturedBandwidth;

I can acquire the keys of the first level of this hash of hash’s simply by:
@RuleSets=keys %CapturedBandwidth;

But, is there an easy way to capture the date the bandwidth occurred the same type of way?
I actually have a work around for this because I can determine all of these dates or times when I build the hash table… But, ok… The devil has me by the tail. I would like to know how to get a list of these secondary keys after the table has been built.

Dan

This discussion is locked

All Comments