Domanda

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.

È stato utile?

Soluzione

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...)

Altri suggerimenti

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`;
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top