From: Michael Tremer Date: Wed, 29 Oct 2025 16:18:31 +0000 (+0000) Subject: graphs: Add option to omit the title X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=56110b1cc620205375f3451e835b3414cec2f685;p=telemetry.git graphs: Add option to omit the title Signed-off-by: Michael Tremer --- diff --git a/src/client/main.c b/src/client/main.c index 23e2166..1ef0543 100644 --- a/src/client/main.c +++ b/src/client/main.c @@ -31,8 +31,7 @@ static const char* doc = "The telemetry client that can draw graphs"; typedef struct td_client_ctx { enum { - // Enables debugging output - DEBUG = (1 << 0), + OMIT_TITLE = (1 << 0), } flags; // DBus @@ -64,11 +63,12 @@ typedef struct td_client_ctx { } td_client_ctx; enum { - OPT_FORMAT = 1, - OPT_HEIGHT = 2, - OPT_WIDTH = 3, - OPT_SINCE = 4, - OPT_UNTIL = 5, + OPT_FORMAT = 1, + OPT_HEIGHT = 2, + OPT_WIDTH = 3, + OPT_SINCE = 4, + OPT_UNTIL = 5, + OPT_OMIT_TITLE = 6, }; static struct argp_option options[] = { @@ -79,6 +79,9 @@ static struct argp_option options[] = { // Time { "since", OPT_SINCE, "TIMESTAMP", 0, "Start the graph from the specified date", 0 }, { "until", OPT_UNTIL, "TIMESTAMP", 0, "End the graph at the specified date", 0 }, + + // Flags + { "omit-title", OPT_OMIT_TITLE, NULL, 0, "Omit the title in the graph image", 0}, { NULL }, }; @@ -117,6 +120,10 @@ static error_t parse(int key, char* arg, struct argp_state* state) { ctx->interval.until = arg; break; + case OPT_OMIT_TITLE: + ctx->flags |= OMIT_TITLE; + break; + // Called for each argument case ARGP_KEY_ARG: // Take the graph name as first argument @@ -216,6 +223,13 @@ static int render(td_client_ctx* ctx) { goto ERROR; } + // Omit the title? + if (ctx->flags & OMIT_TITLE) { + r = sd_bus_message_append(m, "{sv}", "omit-title", "b", 1); + if (r < 0) + goto ERROR; + } + // Close the array r = sd_bus_message_close_container(m); if (r < 0) diff --git a/src/daemon/graph-bus.c b/src/daemon/graph-bus.c index 3d7e75c..540662e 100644 --- a/src/daemon/graph-bus.c +++ b/src/daemon/graph-bus.c @@ -111,6 +111,9 @@ static int td_graph_bus_render(sd_bus_message* m, void* data, sd_bus_error* erro const char* since = NULL; const char* until = NULL; + // Flags + int omit_title = 0; + // Open the options array r = sd_bus_message_enter_container(m, SD_BUS_TYPE_ARRAY, "{sv}"); if (r < 0) @@ -181,6 +184,15 @@ static int td_graph_bus_render(sd_bus_message* m, void* data, sd_bus_error* erro SD_BUS_ERROR_INVALID_ARGS, "Failed to time '%s'", until); goto ERROR; } + + // Parse "omit-title" + } else if (td_string_equals(key, "omit-title")) { + r = sd_bus_message_read(m, "v", "b", &omit_title); + if (r < 0) + goto ERROR; + + if (omit_title) + options.flags |= TD_GRAPH_OMIT_TITLE; } // Leave the container diff --git a/src/daemon/graph.c b/src/daemon/graph.c index 53d2e4a..ecaad1f 100644 --- a/src/daemon/graph.c +++ b/src/daemon/graph.c @@ -201,11 +201,39 @@ ERROR: return r; } +static int td_graph_render_title(td_graph* self, const char* object, + const td_graph_render_options* options, td_args* args) { + char title[TITLE_MAX] = ""; + int r; + + // Don't render the title if requested to omit + if (options->flags & TD_GRAPH_OMIT_TITLE) + return 0; + + // Call the implementation + if (self->impl->title) { + // Fetch the title + r = self->impl->title(self->ctx, self, object, title, sizeof(title)); + if (r < 0) { + ERROR(self->ctx, "Failed to render the title: %s\n", strerror(-r)); + return r; + } + + // Add the title to the command line + if (*title) { + r = td_args_push(args, "--title=%s", title); + if (r < 0) + return r; + } + } + + return 0; +} + int td_graph_render(td_graph* self, const char* object, const td_graph_render_options* options, char** buffer, size_t* length) { td_args* args = NULL; char vlabel[VLABEL_MAX] = ""; - char title[TITLE_MAX] = ""; char** data = NULL; FILE* f = NULL; int w = 0; @@ -299,21 +327,9 @@ int td_graph_render(td_graph* self, const char* object, } // Set the title - if (self->impl->title) { - // Fetch the title - r = self->impl->title(self->ctx, self, object, title, sizeof(title)); - if (r < 0) { - ERROR(self->ctx, "Failed to render the title: %s\n", strerror(-r)); - goto ERROR; - } - - // Add the title to the command line - if (*title) { - r = td_args_push(args, "--title=%s", title); - if (r < 0) - goto ERROR; - } - } + r = td_graph_render_title(self, object, options, args); + if (r < 0) + goto ERROR; // Set the vertical label if (self->impl->vlabel) { diff --git a/src/daemon/graph.h b/src/daemon/graph.h index 89e6319..01d3a8b 100644 --- a/src/daemon/graph.h +++ b/src/daemon/graph.h @@ -84,6 +84,11 @@ typedef struct td_graph_render_options { time_t t_start; time_t t_end; } interval; + + // Flags + enum { + TD_GRAPH_OMIT_TITLE = (1 << 0), + } flags; } td_graph_render_options; int td_graph_render(td_graph* self, const char* object,