4

I'm slightly new to Perl, definitely new to RRDs, and I have a Perl script that runs some webservice tests and also retrieves lines from garbage collection logs. The script does other tasks as well but I only need to have a graph related to those two.

This piece of the script reads a results report .html, extracts some time values from a table and stores them in a variable.

my $html = "./report/archive/results-$now/web_results.html";
my @headers = qw( Page Initial Resource STB UI );
my $te = HTML::TableExtract->new(headers => \@headers);
$te->parse_file($html);
my ($table) = $te->tables;
for my $row ($te->rows) {
    my $pageDisplay = "@$row[0]";
    $pageDisplay =~ s/\D//g;

    my $initialLoad = "@$row[1]";
    $initialLoad =~ s/\D//g;

    my $resourceAudit = "@$row[2]";
    $resourceAudit =~ s/\D//g;

    my $uiRefresh = "@$row[3]";
    $uiRefresh =~ s/\D//g;

    my $stbRefresh = "@$row[4]";
    $stbRefresh =~ s/\D//g;
}

I would like to use RRDTool::OO or RRD::Simple to store these variables in an RRD and update them after each loop of the script.

I'd also like to do the same with another piece of the script that loops through some garbage collection log lines and returns a runtime for each.

open LOG,"<","./report/archive/logs-$now/garbage.collection.txt" or die "Unable to read file: $!";
    while (my $line = <LOG>) {
        my ($time) = $line =~ m/\breal=([0-9.]+)/;
    }
close LOG;

I believe RRDTool::OO has an update function that can be called with my variables, but my main problem is creating the RRD(s) to begin with so they can be updated with them. I'm not sure whether I need to have more than one RRD, what step value would be best, data sources, etc..

If I can get the RRD or RRDs created/updated successfully I'm pretty sure I can follow Cacti's Externally Updated RRDs doc to get them loaded onto cacti to be graphed. Although someone may have a better approach. Any help is appreciated!

EDIT

I've tried the following on the second part of my script...

#RRDTool::OO

my $rrd = RRDTool::OO->new(
             file => "gcRuntimes.rrd" );

$rrd->create(
     step        => 1,
     data_source => { name      => "GC",
                      type      => "GAUGE" },
     archive     => { rows      => 50 });
...

open LOG,"<","./report/archive/logs-$now/garbage.collection.txt" or die "Unable to read file: $!";
    while (my $line = <LOG>) {
        my ($time) = $line =~ m/\breal=([0-9.]+)/;
        $rrd->update($time);
}
close LOG;

..But that fails with an error: rrdtool create gcRuntimes.rrd --step 1 DS:GC:GAUGE:2:U:U RRA:MAX:0.5:1:5 failed: creating 'gcRuntimes.rrd': Invalid argument at /home/foo/perl5/lib/perl5/RRDTool/OO.pm line 438

Running strace with my script will show this (invalid argument) at the mmap2 syscall.

mmap2(NULL, 1344, PROT_READ|PROT_WRITE, MAP_SHARED, 3, 0) = -1 EINVAL (Invalid argument)
close(3)

It doesn't matter to me if I use RRD::Simple or RRDTool::OO, but currently they both return the same error.

MrTunaDeluxe
  • 152
  • 5
  • 20
  • You want only 5 rows? I think you need to start with the rrdtool documentation (e.g., `man rrdcreate`), to understand what those parameters you're passing to create mean. Start with `man rrd-beginners`. – derobert Aug 15 '12 at 17:12
  • @derobert No I don't want five rows, I'm going to need more than that I'm sure. But I don't see why calling the create function this way will fail with that error. – MrTunaDeluxe Aug 16 '12 at 13:36
  • Actually, trying your example code now, it works here, at least through the create. Maybe run it under strace to see where the 'invalid argument' is coming from if its a syscall? – derobert Aug 16 '12 at 16:46
  • @derobert ran strace on the script using both `RRDTool::OO` and `RRD::Simple`, and they will both return the same 'invalid argument'. `mmap2(NULL, 1344, PROT_READ|PROT_WRITE, MAP_SHARED, 3, 0) = -1 EINVAL (Invalid argument) close(3)` – MrTunaDeluxe Aug 17 '12 at 12:45
  • Have you check location of the file "gcRuntimes.rrd" you try to create: writable file system, write permission on parent folder ? – Yves Martin Aug 25 '12 at 22:06
  • @YvesMartin The permissions on the parent folder are read/write/execute for both user and vboxsf group, but nothing for "other". I've tried `chmod -Rv 776 folder` and it shows that the permissions for each file are being set but once I check with `ls -latr` they revert back to no permissions on "other". Does not having any "other" permissions cause my problem? And if so, is the fact that `folder` is part of a `sf_shared` directory the reason why I can't change permissions? – MrTunaDeluxe Aug 27 '12 at 18:23
  • So I guess you try to write on a virtual box shared mount point... – Yves Martin Aug 27 '12 at 19:36

2 Answers2

1

According to this bug report, it is most likely that the vboxfs file system on which the file is created is in trouble to support mmap system call in write mode.

You should try your code at another location on a regular Linux file system (ext3, ext4, reiserfs...)

Yves Martin
  • 10,217
  • 2
  • 38
  • 77
0

You could as well just call the rrdtool commands on your own within your perl script.

my $result = `/usr/bin/rrdtool create /path/to/gcRuntimes.rrd --step 1 DS:GC:GAUGE:2:U:U RRA:MAX:0.5:1:5`;

and

my $result = `/usr/bin/rrdtool update /path/to/gcRuntimes.rrd $time:$data`;