[rrd-developers] Need help in RRDtool usage...

Kalpesh Patel kpatel at dli.com
Thu May 30 23:08:56 MEST 2002


Hi Everyone,

I am using the RRDTool for the first time and I need help. Basically I am
trying to insert a single number per day into an RRDTool database. Following
is the perl code that is suppose to insert the number and optionally creates
a RRD file with a single RRA if it does not exist:

#!/usr/local/bin/perl -w

use strict;
use lib '/usr/local/bin/lib/perl/';
use RRDs;
use File::Path;
use Time::Local;

my $file_to_parse;
my $item;
my $ignore;
my $table_type;
my $table_name;
my $table_size;
my $rrd_root_dir = "/var/db_perf/";
my $rrd_dir;
my $rrd_file_name;
my $time;
my $start;
my $ERR;
my $png_file_name;
my $rrd;
my $step = 24*60*60;
my $runs = 3*365;               # Three years worth of data
my @options;

$file_to_parse = shift;

$time = 30*int(time/30);
$start = $time-$runs*$step;

open (FILE, "< $file_to_parse") or die "Can't open $file_to_parse for
reading: $!\n";

@options = ("-b", $start, "-s", $step,
            "DS:rows:DERIVE:200:U:U",
            "RRA:AVERAGE:0.5:1:$runs");

while ($item = <FILE>)
{
    if (index ($item, "about to export") > -1)
       {
         $table_type = (split (/\s+/, $item))[4];
         $table_type = substr ($table_type, 0, length ($table_type) - 2);
         $rrd_dir = $rrd_root_dir."/rrd_data/".$table_type;
         print "Processing $table_type ($rrd_dir) table...\n\n";
       }

    if (index ($item, "exporting table ") > -1)
       {
         ($table_name, $table_size) = (split (/\s+/, $item))[4, 5];
         $rrd_file_name = $rrd_dir."/".$table_name."\.rrd";
         unless (-e $rrd_file_name)
                {
                   unless (-e $rrd_dir)
                          {
                             mkpath ([$rrd_dir], 1, 0700);
                             print "Created $rrd_dir path...\n";
                          }
                   RRDs::create $rrd_file_name, @options;
                   print "Created $rrd_file_name round robin archive...\n";
                }
         print "$time:$table_size";
         RRDs::update $rrd_file_name, "$time:$table_size";
         $ERR = RRDs::error;
         die "Error while updating $rrd_file_name: $ERR\n" if $ERR;

#         $png_file_name = $rrd_root_dir."/pngs/".$table_name."\.png",
#         RRDs::graph  $png_file_name,
#                      "--title", $table_name,
#                      "--start", -$today_start,
#                      "--end", "now",
#                      "-v", "Total Rows",
#                      "-a","GIF",
#                      "-x","HOUR:2:HOUR:6:HOUR:2:0:%H",
#                      "DEF:myrows=$rrd:rows:AVERAGE",
#                      "AREA:myrows#00FF00",
#                      "HRULE:32#0000FF:'Freezing Point (32F)\l'",
#                      "LINE2:myrows#00AA00",
#                      "COMMENT:"  ;
       }
}

It reads a line like below:

. . exporting table                          USERS      55754 rows exported

and suppose to put value of 55754 into RRA.

When fetching using following code:

#!/usr/local/bin/perl -w

#use strict;
use lib '/usr/local/bin/lib/perl/';
use RRDs;
use File::Path;
use Time::Local;

my $start;
my $step;
my $names;
my $data;
my $line;
my $val;

  ($start,$step,$names,$data) = RRDs::fetch
"/var/db_perf/rrd_data/DLI/USERS.rrd", "AVERAGE";
  my $ERR = RRDs::error;
  print "$ERR" if $ERR;
  print "start=$start, step=$step\n";
  print "                    ";
  map {printf("%12s",$_)} @$names ;
  print "\n";
  foreach $line (@$data){
    print "".localtime($start),"   ";
    $start += $step;
    foreach $val (@$line) {
      printf "val=%12.1f", $val;
    }
    print "\n";
  }

The output is as follows:

start=1022630400, step=86400
                            rows
Use of uninitialized value in printf at ./try line 27.
Tue May 28 20:00:00 2002   val=         0.0
Use of uninitialized value in printf at ./try line 27.
Wed May 29 20:00:00 2002   val=         0.0
Use of uninitialized value in printf at ./try line 27.
Thu May 30 20:00:00 2002   val=

If anyone can provide hint as to what I am doing wrong then I will highly
appreciate.

Kalpesh...

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



More information about the rrd-developers mailing list