From: Michael Tremer Date: Fri, 3 Apr 2026 14:15:39 +0000 (+0000) Subject: graphs: memory: Refactor the entire legend X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5557e1d6e2e8a4eb812287649b888a95a5e75e60;p=collecty.git graphs: memory: Refactor the entire legend Signed-off-by: Michael Tremer --- diff --git a/src/daemon/graphs/graph.h b/src/daemon/graphs/graph.h index 09c3a8e..25aee73 100644 --- a/src/daemon/graphs/graph.h +++ b/src/daemon/graphs/graph.h @@ -191,7 +191,6 @@ static inline int __DRAW(td_args* args, const char* what, const char* field, // Add something to the legend of the graph #define PRINT_EMPTY_LINE(args) SCRIPT(args, "COMMENT: \\n") -#define PRINT_HEADLINE(args, headline) SCRIPT(args, "COMMENT:%s\\n", headline) #define PRINT_HEADER(args, label) SCRIPT(args, "COMMENT:" COLUMN, label) #define PRINT_LABEL(args, label) SCRIPT(args, "COMMENT: %-31s", label) #define PRINT_EMPTY_LABEL(args) SCRIPT(args, "COMMENT: ") @@ -200,6 +199,25 @@ static inline int __DRAW(td_args* args, const char* what, const char* field, SCRIPT(args, "GPRINT:" FIELD ":" format, FIELD_AND_OBJECT(field, object), ##__VA_ARGS__) #define PRINT_EOL(args) SCRIPT(args, "COMMENT:" EOL) +// Headlines +#define __PRINT_HEADLINE(args, headline) SCRIPT(args, "COMMENT:%-32s", headline) + +#define PRINT_HEADLINE(args, headline) \ + { \ + __PRINT_HEADLINE(args, headline); \ + PRINT_EOL(args); \ + } while (0) + +#define PRINT_HEADLINE_WITH_CURRENT(args, headline, field, object, format, ...) \ + { \ + __PRINT_HEADLINE(args, headline); \ + PRINT_CURRENT(args, field, object, format, ##__VA_ARGS__); \ + PRINT_NOTHING(args); \ + PRINT_NOTHING(args); \ + PRINT_NOTHING(args); \ + PRINT_EOL(args); \ + } while (0) + /* Prints CURRENT, AVERAGE, MINIMUM and MAXIMUM */ diff --git a/src/daemon/graphs/memory.c b/src/daemon/graphs/memory.c index 13d08ab..dbe2112 100644 --- a/src/daemon/graphs/memory.c +++ b/src/daemon/graphs/memory.c @@ -54,44 +54,45 @@ static int memory_render(td_ctx* ctx, td_graph* graph, COMPUTE_DIFFERENCE(args, "swap_used", NULL, "swap_total", NULL, "swap_free", NULL); COMPUTE_PERCENTAGE(args, "swap_used", NULL, "swap_total", NULL); + // Headline + PRINT_HEADLINE_WITH_CURRENT(args, _("Memory"), "mem_total", NULL, BYTES, BYTES_UNIT); + + // Draw the total memory as a line + DRAW_LINE(args, 1, "mem_total", NULL, COLOR_MEM_TOTAL, SKIPSCALE); + // Draw the stacked background first DRAW_AREA_BACKGROUND(args, "mem_used", NULL, COLOR_MEM_USED, 0); DRAW_AREA_BACKGROUND(args, "buffers", NULL, COLOR_BUFFERS, STACKED); DRAW_AREA_BACKGROUND(args, "cached", NULL, COLOR_CACHED, STACKED); // Draw the area outlines afterwards - DRAW_AREA_OUTLINE_WITH_LABEL(args, "mem_used", NULL, COLOR_MEM_USED, 0, _("Used Memory")); - PRINT_CAMM(args, "mem_used", NULL, LARGE_FLOAT); + DRAW_AREA_OUTLINE_WITH_LABEL(args, "mem_used", NULL, COLOR_MEM_USED, 0, _("Used")); + PRINT_CAMM(args, "mem_used", NULL, BYTES, BYTES_UNIT); PRINT_EMPTY_LABEL(args); PRINT_CAMM(args, FIELD_PERCENT("mem_used"), NULL, PERCENTAGE); DRAW_AREA_OUTLINE_WITH_LABEL(args, "buffers", NULL, COLOR_BUFFERS, STACKED, _("Buffers")); - PRINT_CAMM(args, "buffers", NULL, LARGE_FLOAT); + PRINT_CAMM(args, "buffers", NULL, BYTES, BYTES_UNIT); DRAW_AREA_OUTLINE_WITH_LABEL(args, "cached", NULL, COLOR_CACHED, STACKED, _("Cached")); - PRINT_CAMM(args, "cached", NULL, LARGE_FLOAT); - - // Draw the total memory as a line - DRAW_LINE(args, 1, "mem_total", NULL, COLOR_MEM_TOTAL, SKIPSCALE); + PRINT_CAMM(args, "cached", NULL, BYTES, BYTES_UNIT); // Make some space for swap PRINT_EMPTY_LINE(args); - DRAW_LINE_WITH_LABEL(args, 1, "swap_used", NULL, COLOR_SWAP_USED, DASHED, _("Used Swap")); - PRINT_CAMM(args, "swap_used", NULL, LARGE_FLOAT); + // Headline + PRINT_HEADLINE_WITH_CURRENT(args, _("Swap"), "swap_total", NULL, BYTES, BYTES_UNIT); + + // Draw the total swap as a line + DRAW_LINE(args, 1, "swap_total", NULL, COLOR_SWAP_TOTAL, DASHED | SKIPSCALE); + + DRAW_LINE_WITH_LABEL(args, 1, "swap_used", NULL, COLOR_SWAP_USED, DASHED, _("Used")); + PRINT_CAMM(args, "swap_used", NULL, BYTES, BYTES_UNIT); PRINT_EMPTY_LABEL(args); PRINT_CAMM(args, FIELD_PERCENT("swap_used"), NULL, PERCENTAGE); - DRAW_LINE_WITH_LABEL(args, 1, "swap_total", NULL, - COLOR_SWAP_TOTAL, DASHED | SKIPSCALE, _("Total Swap")); - PRINT(args, FIELD_CURRENT("swap_used"), NULL, LARGE_FLOAT); - PRINT_NOTHING(args); - PRINT_NOTHING(args); - PRINT_NOTHING(args); - PRINT_EOL(args); - return 0; }