]> git.ipfire.org Git - telemetry.git/commitdiff
graphs: unbound: Add a cache usage graph
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 28 Nov 2025 13:09:01 +0000 (13:09 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 28 Nov 2025 13:09:01 +0000 (13:09 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/daemon/colors.h
src/daemon/graph.c
src/daemon/graph.h
src/daemon/graphs.c
src/daemon/graphs/unbound.c
src/daemon/graphs/unbound.h

index 70ae99b0e6165d5c4b52eaae78ba88ffcf0ab8e3..b8f7148b33382d22f2db2e5bdbea4046eb8f2528 100644 (file)
 // 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) {
index 4042b96d95699e3cd6197d17a6e6195214844f68..f9c6a517c1ab1e6b631d95d054aa672207741242 100644 (file)
@@ -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"));
index 5269f23b7aa4080e127ef74d33cddc15a4fb9e22..76f5debd43936e44e51fd7cc3bf65b6dbb35dfef 100644 (file)
@@ -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);
 
index 37242c617bf58c342fac29fc0dcfca487dd54b25..e6253a48316179cb2f8416ff751ee536d464647b 100644 (file)
@@ -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
index ef8aa45b8b589e06deeb552aabab3d01cf8c077d..33db5ab3a03e7c2a6dfbba2523869dcfbbf1d755 100644 (file)
@@ -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"));
index 54f10fcb21a9f8412915d07b26a2d6a203103b19..669e352c69dedf48d140f08e521d4cb44b180ee8 100644 (file)
@@ -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 */