Discussion:
[rrd-users] rrd_graph() producing a 0 bytes image
(too old to reply)
folkert
2014-08-21 20:30:09 UTC
Permalink
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
folkert
2014-08-21 20:38:55 UTC
Permalink
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());
Post by folkert
Hi,
I'm trying to generate a graph from an rrd-file using rrd_graph() in
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));
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.
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
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
Pablo Sanchez
2014-08-21 20:40:44 UTC
Permalink
[ Comments below, in-line ]
Post by folkert
Sigh. Only 5 minutes after I wrote that e-mail in despair I found how
... however, you provided the fix so it's all good! :)

--
Pablo Sanchez - Blueoak Database Engineering, Inc
Ph: 819.459.1926 Blog: http://pablo-blog.blueoakdb.com
iNum: 883.5100.0990.1054
folkert
2014-08-21 20:43:11 UTC
Permalink
Post by Pablo Sanchez
[ Comments below, in-line ]
Post by folkert
Sigh. Only 5 minutes after I wrote that e-mail in despair I found how
... however, you provided the fix so it's all good! :)
Yeah I'm hoping this gets in the google-archives and stays there.

The results of rrdtool are very fine but documentation may need some
attention. Especially the c++ api.


Folkert van Heusden
--
Multitail es una herramienta flexible que permite visualizar los "log
file" y seguir la ejecución de comandos. Permite filtrar, añadir
colores, combinar archivos, la visualización de diferencias (diff-
view), etc. http://www.vanheusden.com/multitail/
----------------------------------------------------------------------
Phone: +31-6-41278122, PGP-key: 1F28D8AE, www.vanheusden.com
Loading...