5 RRDp - Attach RRDtool from within a perl script via a set of pipes;
11 B<RRDp::start> I<path to RRDtool executable>
13 B<RRDp::cmd> I<rrdtool commandline>
15 $answer = B<RRD::read>
19 B<$RRDp::user>, B<$RRDp::sys>, B<$RRDp::real>, B<$RRDp::error_mode>, B<$RRDp::error>
23 With this module you can safely communicate with the RRDtool.
25 After every B<RRDp::cmd> you have to issue an B<RRDp::read> command to get
26 B<RRDtool>s answer to your command. The answer is returned as a pointer,
27 in order to speed things up. If the last command did not return any
28 data, B<RRDp::read> will return an undefined variable.
30 If you import the PERFORMANCE variables into your namespace,
31 you can access RRDtool's internal performance measurements.
37 Load the RRDp::pipe module.
39 =item B<RRDp::start> I<path to RRDtool executable>
41 start RRDtool. The argument must be the path to the RRDtool executable
43 =item B<RRDp::cmd> I<rrdtool commandline>
45 pass commands on to RRDtool. check the RRDtool documentation for
46 more info on the RRDtool commands.
48 =item $answer = B<RRDp::read>
50 read RRDtool's response to your command. Note that the $answer variable will
51 only contain a pointer to the returned data. The reason for this is, that
52 RRDtool can potentially return quite excessive amounts of data
53 and we don't want to copy this around in memory. So when you want to
54 access the contents of $answer you have to use $$answer which dereferences
57 =item $status = B<RRDp::end>
59 terminates RRDtool and returns RRDtool's status ...
61 =item B<$RRDp::user>, B<$RRDp::sys>, B<$RRDp::real>
63 these variables will contain totals of the user time, system time and
64 real time as seen by RRDtool. User time is the time RRDtool is
65 running, System time is the time spend in system calls and real time
66 is the total time RRDtool has been running.
68 The difference between user + system and real is the time spent
69 waiting for things like the hard disk and new input from the perl
72 =item B<$RRDp::error_mode> and B<$RRDp::error>
74 If you set the variable $RRDp::error_mode to the value 'catch' before you run RRDp::read a potential
75 ERROR message will not cause the program to abort but will be returned in this variable. If no error
76 occurs the variable will be empty.
78 $RRDp::error_mode = 'catch';
79 RRDp::cmd qw(info file.rrd);
80 print $RRDp::error if $RRDp::error;
88 RRDp::start "/usr/local/bin/rrdtool";
89 RRDp::cmd qw(create demo.rrd --step 100
91 RRA:AVERAGE:0.5:1:10);
94 ($usertime,$systemtime,$realtime) = ($RRDp::user,$RRDp::sys,$RRDp::real);
98 For more information on how to use RRDtool, check the manpages.
102 Tobias Oetiker <tobi@oetiker.ch>
105 #' this is to make cperl.el happy
112 use vars qw($Sequence $RRDpid $VERSION);
123 $VERSION=1.299907080300;
126 croak "rrdtool is already running"
127 if defined $Sequence;
129 my $rrdtool = shift @_;
130 $RRDpid = open2 \*RRDreadHand,\*RRDwriteHand, $rrdtool,"-"
131 or croak "Can't Start rrdtool: $!";
132 RRDwriteHand->autoflush(); #flush after every write
133 fcntl RRDreadHand, F_SETFL,O_NONBLOCK|O_NDELAY; #make readhandle NON BLOCKING
139 croak "RRDp::read can only be called after RRDp::cmd"
140 unless $Sequence eq 'C';
141 $RRDp::error = undef;
149 vec($inmask,fileno(RRDreadHand),1) = 1; # setup select mask for Reader
152 $nfound = select($rout=$inmask,undef,undef,2);
154 # here, we could do something sensible ...
157 sysread(RRDreadHand,$srbuf,4096);
159 while ($minibuf =~ s|^(.+?)\n||s) {
162 $RRDp::error = undef;
163 if ($line =~ m|^ERROR|) {
164 $RRDp::error_mode eq 'catch' ? $RRDp::error = $line : croak $line;
170 elsif ($line =~ m|^OK(?: u:([\d\.]+) s:([\d\.]+) r:([\d\.]+))?|){
171 ($RRDp::sys,$RRDp::user,$RRDp::real)=($1,$2,$3);
174 $buffer .= $line. "\n";
181 croak "RRDp::cmd can only be called after RRDp::read or RRDp::start"
182 unless $Sequence eq 'R' or $Sequence eq 'S';
184 my $cmd = join " ", @_;
185 if ($Sequence ne 'S') {
189 print RRDwriteHand "$cmd\n";
193 croak "RRDp::end can only be called after RRDp::start"