]> git.ipfire.org Git - collecty.git/commitdiff
graphs: Make it configurable if the graph is reversed
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 4 Oct 2025 12:01:50 +0000 (12:01 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 4 Oct 2025 12:01:50 +0000 (12:01 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/daemon/graph.c
src/daemon/graph.h
src/daemon/graphs/conntrack.c
src/daemon/graphs/contextswitches.c
src/daemon/graphs/loadavg.c

index 0f1e55e698a15586808c6e6f652ab63cc2976fa0..a5f26fe4bca1a8ba35a3c24b0c60dc42b33a8fbe 100644 (file)
@@ -60,10 +60,6 @@ const char* DEFAULT_RENDER_ARGS[] = {
        // Add a watermark
        "--watermark=" PACKAGE_NAME,
 
-       // Invert legend order. This way, we can draw graphs from back to front
-       // to be able to user overlay and transparency.
-       "--legend-direction=bottomup",
-
        // Honour upper/lower limit
        "--rigid",
 
@@ -317,6 +313,15 @@ int collecty_graph_render(collecty_graph* self, const char* object,
                }
        }
 
+       // Invert the legend?
+       // This way, we can draw graphs from back to front
+       // to be able to user overlay and transparency.
+       if (self->impl->flags & COLLECTY_GRAPH_REVERSE) {
+               r = collecty_args_push(args, "--legend-direction=bottomup");
+               if (r < 0)
+                       goto ERROR;
+       }
+
        // Write the graph to the output stream
        r = collecty_args_push(args, "-");
        if (r < 0)
index 59a9abc454630c87fc703bc5f49c60f9b037038e..2f1fc62fc25fecad737d8175c451fc7704cb80c4 100644 (file)
@@ -32,6 +32,11 @@ typedef struct collecty_graph_impl {
        // Name
        const char* name;
 
+       // Flags
+       enum {
+               COLLECTY_GRAPH_REVERSE = (1 << 0),
+       } flags;
+
        // Limits
        long lower_limit;
        long upper_limit;
index 5e13910ffc5a0e9f3e21f16dd208c550a3583cf8..c19762b512263b64956928cb95d06bc77b30095a 100644 (file)
@@ -42,12 +42,8 @@ static int conntrack_render(collecty_ctx* ctx,
        if (r < 0)
                return r;
 
-       // Limit
-       DRAW_LINE1_WITH_LABEL(args, "max", LIMIT, _("Limit"), DASHES SKIPSCALE);
-       PRINT_LARGE_INTEGER(args, "max_cur");
-       PRINT_NOTHING(args);
-       PRINT_NOTHING(args);
-       PRINT_NOTHING(args, EOL);
+       // Header
+       PRINT_HEADER4(args, _("Current"), _("Average"), _("Minimum"), _("Maximum"));
 
        // Entries
        DRAW_AREA_WITH_LABEL(args, "count", GREEN, _("Entries"));
@@ -56,8 +52,12 @@ static int conntrack_render(collecty_ctx* ctx,
        PRINT_LARGE_INTEGER(args, "count_min");
        PRINT_LARGE_INTEGER(args, "count_max", EOL);
 
-       // Header
-       PRINT_HEADER4(args, _("Current"), _("Average"), _("Minimum"), _("Maximum"));
+       // Limit
+       DRAW_LINE1_WITH_LABEL(args, "max", LIMIT, _("Limit"), DASHES SKIPSCALE);
+       PRINT_LARGE_INTEGER(args, "max_cur");
+       PRINT_NOTHING(args);
+       PRINT_NOTHING(args);
+       PRINT_NOTHING(args, EOL);
 
        return 0;
 }
index 446318a2e424b64d02eb85adc155c8384bc354ba..45089efd9fb32e322ef278878f6405b289e65443 100644 (file)
@@ -42,6 +42,9 @@ static int contextswitches_render(collecty_ctx* ctx,
        if (r < 0)
                return r;
 
+       // Header
+       PRINT_HEADER4(args, _("Current"), _("Average"), _("Minimum"), _("Maximum"));
+
        // Context Switches
        DRAW_AREA_WITH_LABEL(args, "ctxt", GREEN, _("Context Switches"));
        PRINT_LARGE_INTEGER(args, "ctxt_cur");
@@ -49,9 +52,6 @@ static int contextswitches_render(collecty_ctx* ctx,
        PRINT_LARGE_INTEGER(args, "ctxt_min");
        PRINT_LARGE_INTEGER(args, "ctxt_max", EOL);
 
-       // Header
-       PRINT_HEADER4(args, _("Current"), _("Average"), _("Minimum"), _("Maximum"));
-
        return 0;
 }
 
index 4ce63d0cc9b7de4cfe9d70bdc71cbb929972a5e6..ffc691b58ae9ece33ed1f1ae73355a880d36180f 100644 (file)
@@ -75,6 +75,9 @@ const collecty_graph_impl loadavg_graph = {
        .title   = loadavg_title,
        .vlabel  = loadavg_title,
 
+       // Flags
+       .flags   = COLLECTY_GRAPH_REVERSE,
+
        // Limits
        .lower_limit = 0,
        .upper_limit = LONG_MAX,