]> git.ipfire.org Git - telemetry.git/commitdiff
graph: Show the hostname at the bottom of the image
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 4 Dec 2025 16:54:50 +0000 (16:54 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 4 Dec 2025 16:54:50 +0000 (16:54 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/daemon/graph.c

index cfbe998eb99334740384d450c1e136f05e85df30..4d9b008a7ccd5691c401379e7b068111b9e50a0c 100644 (file)
@@ -22,6 +22,7 @@
 #include <limits.h>
 #include <locale.h>
 #include <stdlib.h>
+#include <unistd.h>
 
 #include <rrd.h>
 
@@ -83,9 +84,6 @@ const char* DEFAULT_RENDER_ARGS[] = {
        // Show nicer labels
        "--dynamic-labels",
 
-       // Add a watermark
-       "--watermark=" PACKAGE_NAME,
-
        // Honour upper/lower limit
        "--rigid",
 
@@ -284,6 +282,7 @@ static void td_graph_reset_locale(td_ctx* ctx, char* locale) {
 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 hostname[HOST_NAME_MAX] = "";
        char vlabel[VLABEL_MAX] = "";
        char** data = NULL;
        FILE* f = NULL;
@@ -343,6 +342,19 @@ int td_graph_render(td_graph* self, const char* object,
        if (r < 0)
                goto ERROR;
 
+       // Fetch the system's hostname
+       r = gethostname(hostname, sizeof(hostname));
+       if (r < 0) {
+               ERROR(self->ctx, "Failed to fetch the hostname: %m\n");
+               r = -errno;
+               goto ERROR;
+       }
+
+       // Add a watermark
+       r = td_args_push(args, "--watermark=%s - %s", PACKAGE_NAME, hostname);
+       if (r < 0)
+               goto ERROR;
+
        // Select the output format
        if (options->format) {
                r = td_args_push(args, "--imgformat=%s", options->format);