On Sat, Jul 08, 2006 at 02:12:38AM -0300, Rogério Schneider wrote: > How can I create, update and graph directly from the C with RRD? > Is there some include, lib, or some docs and samples of how to do this? I > have read rrd.h but the prototypes is strange to me, and there is no > documentation for C API.
The C API is basically just like the commandline API. E.g. to create a graph you would run a command like rrdcreate myfile.rrd "DS:myval:GAUGE:600:0:U" "RRA:AVERAGE:0.5:1:576" In the C API, you'd just stick the commandline args into a char* table, and pass them off to the appropriate function: char *createparams[] = { "rrdcreate", "myfile.rrd", "DS:myval:GAUGE:600:0:U", "RRA:AVERAGE:0.5:1:576", NULL }; optind = opterr = 0; /* Because rrdtool uses getopt() */ rrd_clear_error(); rrd_create(4, createparams); Likewise for an update - the command line is rrdupdate myfile.rrd "0:42" In C, that would be char *updateparams[] = { "rrdupdate", "myfile.rrd", "0:42", NULL }; optind = opterr = 0; rrd_clear_error(); rrd_update(3, updateparams); rrd_graph works the same, but has some additional parameters that are return values from the rrd_graph function. And this API changed from rrdtool 1.0 -> 1.2. So what I do is like this: char **calcpr = NULL; int rrdargcount, xsize, ysize, result; double ymin, ymax; char *rrdargs[] = { "rrdgraph", "mygraph.png", "-a", "PNG", "--title", "My Fancy Graph", "DEF:myval=myfile.rrd:myval:AVERAGE", "LINE2:myval#00CC00:The value", NULL }; optind = opterr = 0; rrd_clear_error(); #ifdef RRDTOOL12 result = rrd_graph(8, rrdargs, &calcpr, &xsize, &ysize, NULL, &ymin, &ymax); #else result = rrd_graph(8, rrdargs, &calcpr, &xsize, &ysize); #endif /* Was it OK ? */ if (rrd_test_error() || (result != 0)) { if (calcpr) { int i; for (i=0; (calcpr[i]); i++) free(calcpr[i]); calcpr = NULL; } printf("Graph error: %s\n", rrd_get_error()); } I've snipped all of these code samples from the RRD handling code in my monitoring toolkit - feel free to grab the full source from hobbitmon.sourceforge.net. Regards, Henrik -- Unsubscribe mailto:[EMAIL PROTECTED] Help mailto:[EMAIL PROTECTED] Archive http://lists.ee.ethz.ch/rrd-developers WebAdmin http://lists.ee.ethz.ch/lsg2.cgi