From: Michael Tremer Date: Wed, 1 Oct 2025 17:06:09 +0000 (+0000) Subject: graph: Create the basic to render a graph X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c02cf46624e88c244e55bbed8c8149694c246e0e;p=collecty.git graph: Create the basic to render a graph Signed-off-by: Michael Tremer --- diff --git a/src/daemon/graph.c b/src/daemon/graph.c index 696ad4b..39d8069 100644 --- a/src/daemon/graph.c +++ b/src/daemon/graph.c @@ -21,6 +21,9 @@ #include #include +#include + +#include "args.h" #include "ctx.h" #include "daemon.h" #include "graph.h" @@ -107,15 +110,55 @@ char* collecty_graph_get_bus_path(collecty_graph* self) { int collecty_graph_render(collecty_graph* self, const char* object, char** buffer, size_t* length) { - char* p = NULL; + collecty_args* args = NULL; + FILE* f = NULL; + int w = 0; + int h = 0; int r; - r = asprintf(&p, "GRAPH"); + // Log action + DEBUG(self->ctx, "Rendering %s...\n", collecty_graph_get_name(self)); + + // Open a file handle to the output buffer + f = open_memstream(buffer, length); + if (!f) { + ERROR(self->ctx, "Failed to open memory stream: %m\n"); + r = -errno; + goto ERROR; + } + + // Allocate a new argument list + r = collecty_args_create(&args, self->ctx); if (r < 0) - return r; + goto ERROR; - *buffer = p; - *length = r; + // XXX TODO Fill this with content - return 0; + // Dump the command + r = collecty_args_dump(args); + if (r < 0) + goto ERROR; + + // Render the graph + r = rrd_graph(collecty_args_argc(args), (char**)collecty_args_argv(args), + NULL, &w, &h, f, NULL, NULL); + if (r < 0) { + ERROR(self->ctx, "Failed to generate the graph: %s\n", rrd_get_error()); + rrd_clear_error(); + r = -ENOTSUP; + goto ERROR; + } + + // 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); + +ERROR: + if (args) + collecty_args_unref(args); + if (f) + fclose(f); + + return r; }