X-Git-Url: https://git.octo.it/?p=rrdtool.git;a=blobdiff_plain;f=bindings%2Fperl-piped%2FRRDp.pm;h=65e9bb664112787a1c7ea54d846deb5fb0f432c3;hp=1d3043b5c94bd4282e19230e99a009b3b3ece1c7;hb=2a9b0ff9cf29cf82b7b12ea80889c59273d66008;hpb=0dc5d6d50c0d95ba4f04b656358b26518d4ce854 diff --git a/bindings/perl-piped/RRDp.pm b/bindings/perl-piped/RRDp.pm index 1d3043b..65e9bb6 100644 --- a/bindings/perl-piped/RRDp.pm +++ b/bindings/perl-piped/RRDp.pm @@ -16,7 +16,7 @@ $answer = B $status = B -B<$RRDp::user>, B<$RRDp::sys>, B<$RRDp::real> +B<$RRDp::user>, B<$RRDp::sys>, B<$RRDp::real>, B<$RRDp::error_mode>, B<$RRDp::error> =head1 DESCRIPTION @@ -42,9 +42,12 @@ start RRDtool. The argument must be the path to the RRDtool executable =item B I -pass commands on to RRDtool. check the RRDtool documentation for +pass commands on to RRDtool. Check the RRDtool documentation for more info on the RRDtool commands. +B: Due to design limitations, B does not support the +C command - use C instead. + =item $answer = B read RRDtool's response to your command. Note that the $answer variable will @@ -66,9 +69,19 @@ running, System time is the time spend in system calls and real time is the total time RRDtool has been running. The difference between user + system and real is the time spent -waiting for things like the hard disk and new input from the perl +waiting for things like the hard disk and new input from the Perl script. +=item B<$RRDp::error_mode> and B<$RRDp::error> + +If you set the variable $RRDp::error_mode to the value 'catch' before you run RRDp::read a potential +ERROR message will not cause the program to abort but will be returned in this variable. If no error +occurs the variable will be empty. + + $RRDp::error_mode = 'catch'; + RRDp::cmd qw(info file.rrd); + print $RRDp::error if $RRDp::error; + =back @@ -89,9 +102,10 @@ For more information on how to use RRDtool, check the manpages. =head1 AUTHOR -Tobias Oetiker +Tobias Oetiker =cut + #' this is to make cperl.el happy use strict; @@ -110,7 +124,7 @@ sub cmd (@); sub end (); sub read (); -$VERSION=1.2009; +$VERSION=1.4002; sub start ($){ croak "rrdtool is already running" @@ -128,6 +142,7 @@ sub start ($){ sub read () { croak "RRDp::read can only be called after RRDp::cmd" unless $Sequence eq 'C'; + $RRDp::error = undef; $Sequence = 'R'; my $inmask = 0; my $srbuf; @@ -135,7 +150,6 @@ sub read () { my $buffer; my $nfound; my $timeleft; - my $ERR = 0; vec($inmask,fileno(RRDreadHand),1) = 1; # setup select mask for Reader while (1) { my $rout; @@ -148,14 +162,18 @@ sub read () { $minibuf .= $srbuf; while ($minibuf =~ s|^(.+?)\n||s) { my $line = $1; - # print $line,"\n"; - if ($line =~ m|^ERROR|) { - croak $line; - $ERR = 1; + # print $line,"\n"; + $RRDp::error = undef; + if ($line =~ m|^ERROR|) { + $RRDp::error_mode eq 'catch' ? $RRDp::error = $line : croak $line; + $RRDp::sys = undef; + $RRDp::user = undef; + $RRDp::real = undef; + return undef; } - elsif ($line =~ m|^OK u:([\d\.]+) s:([\d\.]+) r:([\d\.]+)|){ + elsif ($line =~ m|^OK(?: u:([\d\.]+) s:([\d\.]+) r:([\d\.]+))?|){ ($RRDp::sys,$RRDp::user,$RRDp::real)=($1,$2,$3); - return $ERR == 1 ? undef : \$buffer; + return \$buffer; } else { $buffer .= $line. "\n"; } @@ -172,6 +190,13 @@ sub cmd (@){ } $cmd =~ s/\n/ /gs; $cmd =~ s/\s/ /gs; + + # The generated graphs aren't necessarily terminated by a newline, + # causing RRDp::read() to wait for a line matching '^OK' forever. + if ($cmd =~ m/^\s*graph\s+-\s+/) { + croak "RRDp does not support the 'graph -' command - " + . "use 'graphv -' instead"; + } print RRDwriteHand "$cmd\n"; }