]> git.ipfire.org Git - collecty.git/commitdiff
graph: Fix calling rrd_graph()
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 2 Oct 2025 10:08:25 +0000 (10:08 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 2 Oct 2025 10:08:25 +0000 (10:08 +0000)
There is pretty much no documenation of librrd and the API has been
changed multiple times. Initially, various arguments have been labeled
optional, but that does not seem to be true for at least the
implementation I am testing against.

So we pass all variables that we function has, and we might as well
include them in the debugging output.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/daemon/graph.c

index 3b6b0769275a7deb986e2cc21b1455719cac41e3..d79893798bf776a5ced7a5d9e8e8fff08b23ec83 100644 (file)
@@ -146,9 +146,12 @@ ERROR:
 int collecty_graph_render(collecty_graph* self,
                const char* object, char** buffer, size_t* length) {
        collecty_args* args = NULL;
+       char** data = NULL;
        FILE* f = NULL;
        int w = 0;
        int h = 0;
+       double ymin = 0;
+       double ymax = 0;
        int r;
 
        // Log action
@@ -183,7 +186,7 @@ int collecty_graph_render(collecty_graph* self,
 
        // Render the graph
        r = rrd_graph(collecty_args_argc(args), (char**)collecty_args_argv(args),
-                       NULL, &w, &h, f, NULL, NULL);
+                       &data, &w, &h, f, &ymin, &ymax);
        if (r < 0) {
                ERROR(self->ctx, "Failed to generate the graph: %s\n", rrd_get_error());
                rrd_clear_error();
@@ -193,10 +196,23 @@ int collecty_graph_render(collecty_graph* self,
 
        // Log action
        DEBUG(self->ctx, "Rendered graph %s:\n", collecty_graph_get_name(self));
-       DEBUG(self->ctx, "    Width  : %d\n", w);
-       DEBUG(self->ctx, "    Height : %d\n", h);
+       DEBUG(self->ctx, "    width    : %d\n", w);
+       DEBUG(self->ctx, "    height   : %d\n", h);
+       DEBUG(self->ctx, "    ymin     : %.2f\n", ymin);
+       DEBUG(self->ctx, "    ymax     : %.2f\n", ymax);
+
+       // Print all content of the data array
+       if (data) {
+               for (unsigned int i = 0; data[i]; i++)
+                       DEBUG(self->ctx, "    data[%2d]: %s\n", i, data[i]);
+       }
 
 ERROR:
+       if (data) {
+               for (unsigned int i = 0; data[i]; i++)
+                       free(data[i]);
+               free(data);
+       }
        if (args)
                collecty_args_unref(args);
        if (f)