From: Michael Tremer Date: Fri, 28 Nov 2025 13:09:01 +0000 (+0000) Subject: graphs: unbound: Add a cache usage graph X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3ee85c05feb56c806605bfec2ea49baa8e7f1c94;p=telemetry.git graphs: unbound: Add a cache usage graph Signed-off-by: Michael Tremer --- diff --git a/src/daemon/colors.h b/src/daemon/colors.h index 70ae99b..b8f7148 100644 --- a/src/daemon/colors.h +++ b/src/daemon/colors.h @@ -88,6 +88,12 @@ // Temperature #define COLOR_TEMPERATURE COLOR_RED +// DNS +#define COLOR_DNS_KEYS COLOR_RED +#define COLOR_DNS_INFRA COLOR_GREY +#define COLOR_DNS_RRSETS COLOR_BLUE +#define COLOR_DNS_MSGS COLOR_GREEN + // CPU Colors static inline const char* COLOR_CPU(long i) { diff --git a/src/daemon/graph.c b/src/daemon/graph.c index 4042b96..f9c6a51 100644 --- a/src/daemon/graph.c +++ b/src/daemon/graph.c @@ -560,6 +560,11 @@ int td_graph_vlabel_days(td_ctx* ctx, td_graph* graph, return __td_string_set(vlabel, length, _("Days")); } +int td_graph_vlabel_objects(td_ctx* ctx, td_graph* graph, + const td_graph_render_options* options, const char* object, char* vlabel, size_t length) { + return __td_string_set(vlabel, length, _("Objects")); +} + int td_graph_vlabel_qps(td_ctx* ctx, td_graph* graph, const td_graph_render_options* options, const char* object, char* vlabel, size_t length) { return __td_string_set(vlabel, length, _("Queries Per Second")); diff --git a/src/daemon/graph.h b/src/daemon/graph.h index 5269f23..76f5deb 100644 --- a/src/daemon/graph.h +++ b/src/daemon/graph.h @@ -126,6 +126,9 @@ int td_graph_vlabel_bytes(td_ctx* ctx, td_graph* graph, int td_graph_vlabel_days(td_ctx* ctx, td_graph* graph, const td_graph_render_options* options, const char* object, char* vlabel, size_t length); +int td_graph_vlabel_objects(td_ctx* ctx, td_graph* graph, + const td_graph_render_options* options, const char* object, char* vlabel, size_t length); + int td_graph_vlabel_qps(td_ctx* ctx, td_graph* graph, const td_graph_render_options* options, const char* object, char* vlabel, size_t length); diff --git a/src/daemon/graphs.c b/src/daemon/graphs.c index 37242c6..e6253a4 100644 --- a/src/daemon/graphs.c +++ b/src/daemon/graphs.c @@ -70,6 +70,7 @@ static const td_graph_impl* graph_impls[] = { // Unbound &unbound_cache_performance_graph, + &unbound_cache_usage_graph, &unbound_recursion_time_graph, // Legacy diff --git a/src/daemon/graphs/unbound.c b/src/daemon/graphs/unbound.c index ef8aa45..33db5ab 100644 --- a/src/daemon/graphs/unbound.c +++ b/src/daemon/graphs/unbound.c @@ -73,6 +73,65 @@ const td_graph_impl unbound_cache_performance_graph = { .upper_limit = LONG_MAX, }; +static int unbound_cache_usage_title(td_ctx* ctx, td_graph* graph, + const char* object, char* title, size_t length) { + return __td_string_set(title, length, _("DNS Cache Usage")); +} + +static int unbound_cache_usage_render(td_ctx* ctx, td_graph* graph, + const td_graph_render_options* options, td_args* args, const char* object) { + int r; + + // Load all sources + r = td_graph_require_source(graph, args, "unbound", NULL); + if (r < 0) + return r; + + // Draw the stacked background first + DRAW_AREA_BACKGROUND(args, "cache_key_objects", NULL, COLOR_DNS_KEYS, 0); + DRAW_AREA_BACKGROUND(args, "cache_infra_objects", NULL, COLOR_DNS_INFRA, STACKED); + DRAW_AREA_BACKGROUND(args, "cache_rrset_objects", NULL, COLOR_DNS_RRSETS, STACKED); + DRAW_AREA_BACKGROUND(args, "cache_msg_objects", NULL, COLOR_DNS_MSGS, STACKED); + + // Draw the area outlines afterwards + DRAW_AREA_OUTLINE_WITH_LABEL(args, "cache_key_objects", NULL, + COLOR_DNS_KEYS, 0, _("Key Objects")); + PRINT_CAMM(args, "cache_key_objects", NULL, LARGE_INTEGER); + + DRAW_AREA_OUTLINE_WITH_LABEL(args, "cache_infra_objects", NULL, + COLOR_DNS_INFRA, STACKED, _("Infrastructure Objects")); + PRINT_CAMM(args, "cache_infra_objects", NULL, LARGE_INTEGER); + + DRAW_AREA_OUTLINE_WITH_LABEL(args, "cache_rrset_objects", NULL, + COLOR_DNS_RRSETS, STACKED, _("RRSet Objects")); + PRINT_CAMM(args, "cache_rrset_objects", NULL, LARGE_INTEGER); + + DRAW_AREA_OUTLINE_WITH_LABEL(args, "cache_msg_objects", NULL, + COLOR_DNS_MSGS, STACKED, _("Message Objects")); + PRINT_CAMM(args, "cache_msg_objects", NULL, LARGE_INTEGER); + + PRINT_EMPTY_LINE(args); + + // Header + PRINT_HEADER4(args, _("Current"), _("Average"), _("Minimum"), _("Maximum")); + + return 0; +} + +const td_graph_impl unbound_cache_usage_graph = { + .name = "UnboundCacheUsage", + .render = unbound_cache_usage_render, + .title = unbound_cache_usage_title, + .vlabel = td_graph_vlabel_objects, + + // Flags + .flags = TELEMETRY_GRAPH_REVERSE, + + // Limits + .lower_limit = 0, + .upper_limit = LONG_MAX, +}; + static int unbound_recursion_time_title(td_ctx* ctx, td_graph* graph, const char* object, char* title, size_t length) { return __td_string_set(title, length, _("DNS Recursion Time")); diff --git a/src/daemon/graphs/unbound.h b/src/daemon/graphs/unbound.h index 54f10fc..669e352 100644 --- a/src/daemon/graphs/unbound.h +++ b/src/daemon/graphs/unbound.h @@ -24,6 +24,7 @@ #include "../graph.h" extern const td_graph_impl unbound_cache_performance_graph; +extern const td_graph_impl unbound_cache_usage_graph; extern const td_graph_impl unbound_recursion_time_graph; #endif /* TELEMETRY_GRAPH_UNBOUND_H */