From: Michael Tremer Date: Fri, 10 Jul 2026 14:32:14 +0000 (+0000) Subject: graphs: knot-resolver: Add a cache performance graph X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e3101d67f62beb0cc4cf48da21d2d17ef9d0a5f4;p=telemetry.git graphs: knot-resolver: Add a cache performance graph Signed-off-by: Michael Tremer --- diff --git a/src/daemon/graphs.c b/src/daemon/graphs.c index 5f25ee4..5d8e6b1 100644 --- a/src/daemon/graphs.c +++ b/src/daemon/graphs.c @@ -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, diff --git a/src/daemon/graphs/knot-resolver.c b/src/daemon/graphs/knot-resolver.c index 7c71066..aab50bb 100644 --- a/src/daemon/graphs/knot-resolver.c +++ b/src/daemon/graphs/knot-resolver.c @@ -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, +}; diff --git a/src/daemon/graphs/knot-resolver.h b/src/daemon/graphs/knot-resolver.h index 1354802..15cb165 100644 --- a/src/daemon/graphs/knot-resolver.h +++ b/src/daemon/graphs/knot-resolver.h @@ -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 */