dcsimg
August 19, 2018
Hot Topics:

A Picture is Worth a Thousand Lines of Code...

  • August 25, 2005
  • By Brad Lhotsky
  • Send Email »
  • More Articles »

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

day graph

Week

week graph

Month

month graph

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.



Page 4 of 4



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

By submitting your information, you agree that developer.com may send you developer offers via email, phone and text message, as well as email offers about other products and services that developer believes may be of interest to you. developer will process your information in accordance with the Quinstreet Privacy Policy.

Sitemap

Thanks for your registration, follow us on our social networks to keep up-to-date