]> git.ipfire.org Git - collecty.git/commitdiff
graphs: knot-resolver: Add a cache performance graph
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 10 Jul 2026 14:32:14 +0000 (14:32 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 10 Jul 2026 14:32:14 +0000 (14:32 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/daemon/graphs.c
src/daemon/graphs/knot-resolver.c
src/daemon/graphs/knot-resolver.h

index 5f25ee4bc1a75b899b22ab42855ec95c0e26bac0..5d8e6b10ed68af9985d3f746787e41fa4b6a3cd6 100644 (file)
@@ -95,6 +95,7 @@ static const td_graph_impl* graph_impls[] = {
 
        // Knot Resolver
        &knot_resolver_queries_graph,
+       &knot_resolver_cache_graph,
 
        // Unbound
        &unbound_cache_performance_graph,
index 7c71066e6eb250bcbf5ef65221987d8bbc1c3746..aab50bbf1989a88988944118f5c1e53355ccc4fc 100644 (file)
@@ -28,6 +28,8 @@ static int knot_resolver_can_render(td_ctx* ctx, td_graph* graph,
        return td_graph_requires_source(graph, "knot-resolver", NULL);
 }
 
+// Queries
+
 static int knot_resolver_queries_title(td_ctx* ctx, td_graph* graph,
                const char* object, char* title, size_t length) {
        return __td_string_set(title, length, _("DNS Queries"));
@@ -63,3 +65,60 @@ const td_graph_impl knot_resolver_queries_graph = {
        .lower_limit = 0,
        .upper_limit = LONG_MAX,
 };
+
+// Cache
+
+static int knot_resolver_cache_title(td_ctx* ctx, td_graph* graph,
+               const char* object, char* title, size_t length) {
+       return __td_string_set(title, length, _("Cache Performance"));
+}
+
+static int knot_resolver_cache_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_load_source(graph, args, "knot-resolver", NULL);
+       if (r < 0)
+               return r;
+
+       // Compute cache misses
+       COMPUTE_DIFFERENCE(args, "answer_missed", NULL,
+               "answer_total", NULL, "answer_cached", NULL);
+
+       // Header
+       PRINT_HEADER4(args, _("Current"), _("Average"), _("Minimum"), _("Maximum"));
+
+       // Show the total queries
+       PRINT_LABEL(args, _("Total"));
+       PRINT_CAMM(args, "answer_total", NULL, QPS, QPS_UNIT);
+
+       PRINT_EMPTY_LINE(args);
+
+       // Draw the stacked background first
+       DRAW_AREA_BACKGROUND(args, "answer_cached", NULL, COLOR_CACHE_HIT, 0);
+       DRAW_AREA_BACKGROUND(args, "answer_missed", NULL, COLOR_CACHE_MISS, STACKED);
+
+       // Draw the area outlines afterwards
+       DRAW_AREA_OUTLINE_WITH_LABEL(args, "answer_cached", NULL,
+               COLOR_CACHE_HIT, 0, _("Cache Hits"));
+       PRINT_CAMM(args, "answer_cached", NULL, QPS, QPS_UNIT);
+
+       DRAW_AREA_OUTLINE_WITH_LABEL(args, "answer_missed", NULL,
+               COLOR_CACHE_MISS, STACKED, _("Cache Miss"));
+       PRINT_CAMM(args, "answer_missed", NULL, QPS, QPS_UNIT);
+
+       return 0;
+}
+
+const td_graph_impl knot_resolver_cache_graph = {
+       .name        = "KnotResolverCache",
+       .can_render  = knot_resolver_can_render,
+       .render      = knot_resolver_cache_render,
+       .title       = knot_resolver_cache_title,
+       .vlabel      = td_graph_vlabel_qps,
+
+       // Limits
+       .lower_limit = 0,
+       .upper_limit = LONG_MAX,
+};
index 1354802475041c758c3120e749d116878bbb2108..15cb1656b93f70798ee8ad6f061b95a43afd8490 100644 (file)
@@ -24,5 +24,6 @@
 #include "../graph.h"
 
 extern const td_graph_impl knot_resolver_queries_graph;
+extern const td_graph_impl knot_resolver_cache_graph;
 
 #endif /* TELEMETRY_GRAPH_KNOT_RESOLVER_H */