[rrd-users] Re: rrd_graph and once more calling

Torleiv Ringer ringert at consumption.net
Sat Nov 10 23:05:31 MET 2001


Using the following patch, your program (and mine) now works:

###################################### begin patch
--- rrdtool-1.0.33/src/rrd_graph.c      Thu Feb 22 04:02:47 2001
+++ rrdtool-1.0.33.patch/src/rrd_graph.c        Sat Nov 10 14:53:01 2001
@@ -2799,6 +2799,8 @@
     char *parsetime_error = NULL;
     int stroff;

+    optind = 1; /* reset so that we can loop and re-parse options */
+
     (*prdata)=NULL;

     parsetime("end-24h", &start_tv);
###################################### end patch

Essentially, it just resets the "optind" variable from getopt. What
seemed to happen was that this was not getting reset, and it was left
at the position (3, or 4) from the last parse through the options. This
would start the option parsing at the wrong place in argv, and depending
on how the arguments were passed to rrd_graph, sometimes it could fail,
other times it would not fail.

The patch resets optind each time a graph gets called. Not having used
getopt before, it may be better to reset optind at the end of rrd_graph,
rather than the beginning like above.

Is this an acceptable fix? Have others had this problem before?

torleiv

On Sat, 10 Nov 2001, Frank Swasey wrote:

> Yes, your program does work the following one doesn't...  The only thing
> I changed was I'm varying the start time instead of the comment.  The
> file0.png and file1.png files are IDENTICAL, they shouldn't be!
>
> ---------8<------------8<-----------8<---------8<-----------8<-------
> #include <stdio.h>
> #include <stdlib.h>
> #include <string.h>
>
> #include <rrdtool/rrd.h>
>
> int
> main(int argc, char** argv) {
>     char **calcpr;
>     int xsize, ysize;
>     int i, j;
>     int num_graphs = 2;
>     char tfilename[24];
>     char tstart[24];
>     char tcom[24];
>     char *filename = "file";
>     char *com = "COMMENT:Number ";
>     char *ga[6];
>
>     ga[0] = "graph";
>     ga[1] = tfilename;
>     ga[2] = "-s";
>     ga[3] = tstart;
>     ga[4] = "DEF:temp=testg.rrd:temp:AVERAGE";
>     ga[5] = "COMMENT:Yup, this is one";
>
>     for (i = 0; i < num_graphs ; i++) {
> 	sprintf(tfilename, "%s%i.png", filename, i);
> 	sprintf(tstart,"%d", (i+1) * (-86400) );
>
> 	printf("Before: ");
>         for (j=0; j<6; j++) {
> 	    printf("%s ", ga[j]);
> 	}
> 	printf("\n");
>
> 	printf("making %s \t", tfilename);
>
> 	if ( rrd_graph(6, ga, &calcpr, &xsize, &ysize) != -1 ) {
> 	    printf("%dx%d\n", xsize, ysize);
> 	}
>
> 	if ( rrd_test_error() ) {
> 	    printf("ERROR: %s\n", rrd_get_error() );
> 	    rrd_clear_error();
> 	}
>
> 	printf("After: ");
>         for (j=0; j<6; j++) {
> 	    printf("%s ", ga[j]);
> 	}
> 	printf("\n\n");
>
>     }
>
>     return 0;
> }
> ---------8<------------8<-----------8<---------8<-----------8<-------
>
> Here's what it prints out....  Why did the values in ga[1], [2], and [3]
> moved during the first call to rrd_graph?
>
> ---------8<------------8<-----------8<---------8<-----------8<-------
> $ ./testg
> Before: graph file0.png -s -86400 DEF:temp=testg.rrd:temp:AVERAGE COMMENT:Yup, this is one
> making file0.png 	495x155
> After: graph -s -86400 file0.png DEF:temp=testg.rrd:temp:AVERAGE COMMENT:Yup, this is one
>
> Before: graph -s -172800 file1.png DEF:temp=testg.rrd:temp:AVERAGE COMMENT:Yup, this is one
> making file1.png 	495x155
> After: graph -s -172800 file1.png DEF:temp=testg.rrd:temp:AVERAGE COMMENT:Yup, this is one
>
> ---------8<------------8<-----------8<---------8<-----------8<-------
>
> cmp file0.png file1.png shows NO DIFFERENCES.  There are two days worth
> of sample data in the rrd file but both png files only have 24 hours of
> graph.
>
> I'd like to be able to generate the daily, weekly, monthly, yearly type
> graphs I'm familiar with from MRTG using a C program that has a loop
> around rrd_graph modifying the start time and step intervals.
>
> It would appear that there is some other step that must be done to clear
> rrd_graph's recollection of what the arguments were.  What is that step?
>
> Thanks,
>

¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤


--
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