[rrd-developers] RRDs:create($string); strange eror when using a string variable but not when using the content of the variable.
Matthew Boyle
mlb-rrd at decisionsoft.co.uk
Thu Jan 7 13:04:43 CET 2010
AllSort ofQuestions wrote:
> Hi everybody
>
> I am sorry if I am posting on the wrong list, I am writing a perl script (beginner level) and I believe that this is the right place to ask my question.
> If I am wrong please let me know and I will ask on the other lists.
>
> Here is the code I am using
>
>
> use RRDs;
> @DataSources=('input','output','memory','CPU');
> for ($i=0; $i<$#DataSources+1; $i=$i+1)
> {
> $DS=($DS.'"DS:'.$DataSources[$i].':GAUGE:6300:0:100000",');
> }
> $string='"databse.rrd",'.$DS.'"RRA:AVERAGE:0.5:120:360"';
> RRDs::create ($string);
> my $error = RRDs::error;
> warn "ERROR: $error\n" if $error;
>
> In the end, before creating the database, $string has the value: "database.rrd","DS:input:GAUGE:6300:0:100000","DS:output:GAUGE:6300:0:100000","DS:memory:GAUGE:6300:0:100000","DS:CPU:GAUGE:6300:0:100000","RRA:AVERAGE:0.5:120:360"
> and I receive this error: "ERROR: you must define at least one Round Robin Archive"
>
> If I use
>
>
> use RRDs;
> RRDs::create ("databse.rrd","DS:input:GAUGE:6300:0:100000","DS:output:GAUGE:6300:0:100000","DS:memory:GAUGE:6300:0:100000","DS:CPU:GAUGE:6300:0:100000","RRA:AVERAGE:0.5:120:360");
> my $error = RRDs::error;
> warn "ERROR: $error\n" if $error;
>
> I just used the string instead of creating it like in the first example and now I am not receiving any errors and the file is created.
here you're passing 6 arguments to create(): the filename, 4 DS and an
RRA. in the code you posted, you're just passing one (the string).
you'll want something like this (usual caveats apply: not tested, may
eat your dog, etc).
----8<---------
my @data_sources;
foreach my $source (qw/input output memory CPU/) {
push @data_sources, "DS:$source:GAUGE:6300:0:100000");
}
RRDs::create('database.rrd', @data_sources, 'RRA:AVERAGE:0.5:120:360');
# usual error handling, etc.
----8<---------
cheers,
--matt
--
Matthew Boyle, Systems Administrator, CoreFiling Limited
Telephone: +44-1865-203192 Website: http://www.corefiling.com
More information about the rrd-developers
mailing list