[rrd-users] rrd_graph() producing a 0 bytes image

folkert folkert at vanheusden.com
Thu Aug 21 22:38:55 CEST 2014


Sigh. Only 5 minutes after I wrote that e-mail in despair I found how
to fix it:

        char *data_line = NULL;
        asprintf(&data_line, "DEF:ds0=%s:ds0:AVERAGE", rrd_file_name);

        const char *const args[] = {
                "--end=now",	// (also important to use the x=y format)
                "--start=-1d",
                "-",                // <---- THIS IS THE ONE
                data_line,
                "LINE1:ds0#00ff00:ds0",
                NULL };

        FILE *fh = open_memstream(data, data_len);
        if (!fh)
                error_exit(true, "open_memstream failed");

        char **prdata = NULL;
        int xsize = 0, ysize = 0;
        double ymin = 0, ymax = 0;
        int rc = rrd_graph(5, (char **)args, &prdata, &xsize, &ysize, fh, &ymin, &ymax);

        fclose(fh);

        free(data_line);

        if (rc != 0)
                error_exit(true, "Failed drawing RRD file %s: %s", rrd_file_name, rrd_get_error());


On Thu, Aug 21, 2014 at 10:30:09PM +0200, folkert wrote:
> Hi,
> 
> I'm trying to generate a graph from an rrd-file using rrd_graph() in
> c++:
> 
> const char *rrd_file_name = "myrrdfile.rrd";
> 
>         char *data_line = NULL;
>         asprintf(&data_line, "DEF:ds0=%s:ds0:AVERAGE", rrd_file_name);
> 
>         const char *const args[] = {
>                 "--width",
>                 "640",
>                 "--height",
>                 "480",
>                 "--end",
>                 "now",
>                 "--start",
>                 "-1d",
>                 data_line,
>                 "LINE1:ds0#00ff00:ds0",
>                 NULL };
> 
>         FILE *fh = open_memstream(data, data_len);
>         if (!fh)
>                 error_exit(true, "open_memstream failed");
> 
>         char **prdata = NULL;
>         int xsize = 640, ysize = 480;
>         double ymin = 0, ymax = 0;
>         int rc = rrd_graph(10, (char **)args, &prdata, &xsize, &ysize, fh, &ymin, &ymax);
> 
>         fclose(fh);
> 
>         free(data_line);
> 
> 	printf("%d,%d %p,%d\n", xsize, ysize, *data, (int)(*data_len));
> 
> What this produces:
> 481,535 0x7f2760000e00,0
> 
> So: rrd_graph does something; it figures out it should create an image
> of 481x535 pixels. But then something goes wrong because it retuns 0
> bytes.
> 
> For completeness sake, myrrdfile.rrd:
>                             ds0
> 
> 1408573800: -nan
> ...
> 1408658100: -nan
> 1408658400: 5.7286432161e-03
> 1408658700: -nan
> 1408659000: -nan
> 1408659300: -nan
> 1408659600: -nan
> 1408659900: 0.0000000000e+00
> 1408660200: -nan
> 
> So there's data in it.
> 
> Any ideas what I might be doing wrong?
> 
> The return value is 0 by the way and also rrd_get_error() does not
> return anything.
> 
> 
> Folkert van Heusden
> 
> -- 
> Wintips voor de staatsloterij? http://www.vanheusden.com/sl.php
>      Meer weten over Bitcoins? http://www.vanheusden.com/bitcoins/
>           Meer weten over TOR? http://www.vanheusden.com/tor/
> ----------------------------------------------------------------------
> Phone: +31-6-41278122, PGP-key: 1F28D8AE, www.vanheusden.com
> 
> _______________________________________________
> rrd-users mailing list
> rrd-users at lists.oetiker.ch
> https://lists.oetiker.ch/cgi-bin/listinfo/rrd-users


Folkert van Heusden

-- 
MultiTail ist eine flexible Applikation um Logfiles und Kommando
Eingaben zu überprüfen. Inkl. Filter, Farben, Zusammenführen,
Ansichten etc. http://www.vanheusden.com/multitail/
----------------------------------------------------------------------
Phone: +31-6-41278122, PGP-key: 1F28D8AE, www.vanheusden.com



More information about the rrd-users mailing list