A Picture is Worth a Thousand Lines of Code...
Drawing the Graphs
The following function figures out how many seconds back each one of your time intervals is, and sends that and a few other key pieces of information to the graph() function.
my $VARDIR = '/var/rrd/myapp';
sub draw_graphs {
#
# draws all the pretty graphs
opendir(LS, $VARDIR) or
die "couldn't open $VARDIR: $!n";
my %IMAGES = ();
my %STARTS = (
day => time - (3600*24),
week => time - (3600*24*7),
month => time - (3600*24*30)
);
while(local $_ = readdir LS) {
chomp;
next unless /(.+).rrd$/;
my $host = $1;
my $rrd = "$VARDIR/$_";
foreach my $type (keys %STARTS) {
graph($host,$type,$STARTS{$type},$rrd);
}
}
closedir LS;
}
No real magic there. This function gets a directory listing of the RRD's directory and calls the graph() function for all the files in that directory that end in '.rrd'.
Pretty Pictures!
Day

Week

Month

Where to Go from Here ...
I've attached the following archive that contains the code that I wrote some time ago that served as inspiration to this article. I'm not offering support for the code, but I thought it would assist the reader in getting a clearer picture of how a number of my favorite CPAN modules can work together. The code presented in the article is straight out of the code in the attached archive.
A picture is worth a thousand words. Thanks to perl and RRDtool, a picture could be worth quite a lot more.
About the Author
Brad Lhotsky is a Software Developer whose focus is primarily web based application in Perl and PHP. He has over 5 years experience developing systems for end users and system and network administrators. Brad has been active on Perl beginner's mailing lists and forums for years, attempting to give something back to the community.



Solid state disks (SSDs) made a splash in consumer technology, and now the technology has its eyes on the enterprise storage market. Download this eBook to see what SSDs can do for your infrastructure and review the pros and cons of this potentially game-changing storage technology.