[rrd-users] Re: Fetching Data from an RRD

Charles A. Crayne ccrayne at crayne.org
Fri Apr 30 06:16:41 MEST 2004


On Thu, 29 Apr 2004 22:37:50 -0400
Rick Blundell <rickb at servercove.com> wrote:

:I can't find any good examples of RRD Fetch with either perl or shell
:scripting.

Here's one I put together. It's pretty primitive, but it will show you the
technique.

#!/usr/bin/perl -w
#
# rrds.list
#
# list values from rrd log file
#############################################
# set values for this run
my $logdir = "/var/www/html/mrtg/";
my $logfile = "dwtr1.rrd";
my $cf = "AVERAGE";
my $stepsize = 60;
my $stepnum = 60;
#############################################
use lib qw(/usr/lib/mrtg2 /usr/lib/perl5/5.8.3/i386-linux-thread-multi);
use strict;
use RRDs 1.000011;
my $ltime = localtime;
my $time = time;
my $endtime = int($time/$stepsize) * $stepsize;
my $starttime = $endtime - ($stepsize * ($stepnum - 1));
print "$ltime\t","Log:         ", "$logdir$logfile\n";
# Display information about log
 my $info = RRDs::info "$logdir$logfile";
 my $ERR=RRDs::error;
 die "ERROR while fetching $logdir.$logfile: $ERR\n" if $ERR;
 foreach my $key (sort(keys%$info)) {
   print "$key = $$info{$key}\n";
 }

my ($start,$step,$names,$data) = RRDs::fetch ("$logdir$logfile", "$cf", "-r
$stepsize", "-s $starttime", "-e $endtime"); 
$ERR=RRDs::error;
die "ERROR while fetching $logdir.$logfile: $ERR\n" if $ERR;
  print "Log:         ", "$logdir$logfile\n";
  print "CF:          ", "$cf\n";
  print "Start:       ", scalar localtime($start), " ($start)\n";
  print "Step size:   $step seconds\n";
  print "DS names:    ", join (", ", @$names)."\n";
  print "Data points: ", $#$data + 1, "\n";
  print "Data:\n";
  foreach my $line (@$data) {
    print "  ", scalar localtime($start), " ($start) ";
    $start += $step;
    foreach my $val (@$line) {
      printf "%12.1f ", $val;
    }
    print "\n";
  }




--
Unsubscribe mailto:rrd-users-request at list.ee.ethz.ch?subject=unsubscribe
Help        mailto:rrd-users-request at list.ee.ethz.ch?subject=help
Archive     http://www.ee.ethz.ch/~slist/rrd-users
WebAdmin    http://www.ee.ethz.ch/~slist/lsg2.cgi



More information about the rrd-users mailing list