morellon / rrd-ffi

A ruby wrapper for librrd (rrdtool) using ffi.
MIT License
71 stars 20 forks source link

RRD::Wrapper.graph PRINTs #22

Closed geoffgarside closed 11 years ago

geoffgarside commented 11 years ago

Does the RRD::Wrapper.graph method eat up all of the PRINT output from the graph call? Using PRINT in graph is only way to get calculated data out of an RRD, but it looks like the wrapper method just returns true and I never get any of the stats I need.

morellon commented 11 years ago

This happens because we check for the int returned by the C function rrd_graph in rrd_graph(args.size+1, argv, calcpr_ptr, xsize_ptr, ysize_ptr, nil, ymin_ptr, ymax_ptr) == 0 I suggest investigating from which C function or parameter you could get this printable outputs and maybe propose a pull request. I honestly never used the print command, that's why I never researched its implementation.

geoffgarside commented 11 years ago

The output comes from the char ***prdata argument to the rrd_graph function. So the data will be in the calcpr_ptr variable in your code.

The rrd_tool.c code relevant to this is

        if (rrd_graph
            (argc - 1, &argv[1], &calcpr, &xsize, &ysize, NULL, &ymin,
             &ymax) == 0) {
            if (!tostdout && !imginfo)
                printf("%dx%d\n", xsize, ysize);
            if (calcpr) {
                for (i = 0; calcpr[i]; i++) {
                    if (!tostdout)
                        printf("%s\n", calcpr[i]);
                    free(calcpr[i]);
                }
                free(calcpr);
            }
        }

the relevant part being printf("%s\n", calcpr[i]); so the RRD::Wrapper.graph method needs to capture this and return it appropriately. I'll see if I can work out enough of FFI to get these strings out, for now though it looks like I can require both rrd-ffi and the 'RRD' ruby bindings and get the bindings version of the RRD.graph method.

geoffgarside commented 11 years ago

Would you be adverse to the RRD::Wrapper.graph method returning an array of strings instead of true if theres PRINT output to return?

morellon commented 11 years ago

Nice job. I'm ok with that, since the rrd graph does output the PRINT output to the cli.