[rrd-users] Problems when using C library

Francisco Sant'Anna chico.santanna at uol.com.br
Wed Nov 28 13:40:10 MET 2001


Hello,

I want to update an RRD database inside a C program.

For that I use rrd_last() to check if the database already exists.
If it does I just uptade it with rrd_update().
If it doesn't I create it with rrd_create() and then update it with
rrd_update().

When I run the program the first time (the RRD database doesn't exists),
after the rrd_update() call, I get the error:
"ERROR: Not enough arguments"

The second time the problem doesn't accurs!
It just happens when I call rrd_create() followed by rrd_update().

Using pipes I don't get the problem.

-=-=-=-=-=-=-=-

Here is the output for the two consecutives runs:

[root at nas niacap]# ./a.out 
COMMAND: last test.rrd
ERROR: opening 'test.rrd': No such file or directory	<----- OK, IT
DOESN'T EXISTS
COMMAND: create --start 1000000000 test.rrd
        DS:out:COUNTER:600:U:U
        DS:in:COUNTER:600:U:U
        RRA:AVERAGE:0.5:1:288
        RRA:AVERAGE:0.5:6:326
COMMAND: update test.rrd 1000000001:1000:1000
ERROR: Not enough arguments				<----- THE ERROR

[root at nas niacap]# ./a.out 
COMMAND: last test.rrd					<----- IT EXISTS
COMMAND: update test.rrd 1000000001:1000:1000		<----- NO ERROR
[root at nas niacap]# 

-=-=-=-=-=-=-=-

Here is the code for this program that simulates the problem:

#include <stdio.h>
#include <string.h>
#include <rrd.h>

void r_erro (void)
{
	if (rrd_test_error())
	{
		fprintf(stdout, "ERROR: %s\n", rrd_get_error());
		rrd_clear_error();
	}
}

unsigned int r_last (char *rrd_nome)
{
	char *argv[2] = { "last", rrd_nome };
	unsigned int t;

	printf("COMMAND: %s %s\n", argv[0], argv[1]);
	t = rrd_last(2, argv);
	r_erro();

	return ((int)t == -1) ? 0 : t;
}

int main (void)
{
	int i;
	unsigned int last;

	char r_nome[50] = "test.rrd";
	char r_update_temp[50];
	char *r_update[3] = { "update", r_nome, r_update_temp };

	char *r_create[8] =
	{
		"create", "--start", "1000000000", r_nome,
		"DS:out:COUNTER:600:U:U",
		"DS:in:COUNTER:600:U:U",
		"RRA:AVERAGE:0.5:1:288",
		"RRA:AVERAGE:0.5:6:326"
	};

	if ( !(last = r_last(r_nome)) )
	{
		printf("COMMAND: %s %s %s %s\n\t%s\n\t%s\n\t%s\n\t%s\n",
			r_create[0], r_create[1], r_create[2], r_create[3],
			r_create[4], r_create[5], r_create[6], r_create[7]);
		rrd_create(8, r_create);
		r_erro();
	}

	sprintf(r_update_temp, "%u:%u:%u", ++last, 1000, 1000);
	printf("COMMAND: %s %s %s\n", r_update[0], r_update[1], r_update[2]);

	rrd_update(3, r_update);
	r_erro();
}

-- 
-chico

--
Unsubscribe mailto:rrd-users-request at list.ee.ethz.ch?subject=unsubscribe
Help        mailto:rrd-users-request at list.ee.ethz.ch?subject=help
Archive     http://www.ee.ethz.ch/~slist/rrd-users
WebAdmin    http://www.ee.ethz.ch/~slist/lsg2.cgi



More information about the rrd-users mailing list