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>
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 rrdtools 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 rrdtools 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 rrdtools 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
78 RRDp::start "/usr/local/bin/rrdtool";
79 RRDp::cmd qw(create demo.rrd --step 100
81 RRA:AVERAGE:0.5:1:10);
84 ($usertime,$systemtime,$realtime) = ($RRDp::user,$RRDp::sys,$RRDp::real);
88 For more information on how to use rrdtool, check the manpages.
92 Tobias Oetiker <oetiker@ee.ethz.ch>
95 #' this is to make cperl.el happy
102 use vars qw($Sequence $RRDpid $VERSION);
113 $VERSION = 1.000331 ;
116 croak "rrdtool is already running"
117 if defined $Sequence;
119 my $rrdtool = shift @_;
120 $RRDpid = open2 \*RRDreadHand,\*RRDwriteHand, $rrdtool,"-"
121 or croak "Can't Start rrdtool: $!";
122 RRDwriteHand->autoflush(); #flush after every write
123 fcntl RRDreadHand, F_SETFL,O_NONBLOCK|O_NDELAY; #make readhandle NON BLOCKING
129 croak "RRDp::read can only be called after RRDp::cmd"
130 unless $Sequence eq 'C';
139 vec($inmask,fileno(RRDreadHand),1) = 1; # setup select mask for Reader
142 $nfound = select($rout=$inmask,undef,undef,2);
144 # here, we could do something sensible ...
147 sysread(RRDreadHand,$srbuf,4096);
149 while ($minibuf =~ s|^(.+?)\n||s) {
152 if ($line =~ m|^ERROR|) {
156 elsif ($line =~ m|^OK u:([\d\.]+) s:([\d\.]+) r:([\d\.]+)|){
157 ($RRDp::sys,$RRDp::user,$RRDp::real)=($1,$2,$3);
158 return $ERR == 1 ? undef : \$buffer;
160 $buffer .= $line. "\n";
167 croak "RRDp::cmd can only be called after RRDp::read or RRDp::start"
168 unless $Sequence eq 'R' or $Sequence eq 'S';
170 my $cmd = join " ", @_;
171 if ($Sequence ne 'S') {
175 print RRDwriteHand "$cmd\n";
179 croak "RRDp::end can only be called after RRDp::start"