From: Michael Tremer Date: Sun, 12 Jul 2026 11:59:20 +0000 (+0000) Subject: graphs: knot-resolver: Add a new latency graph X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=da419745e21b814727330ec5fe632049dcefefdd;p=telemetry.git graphs: knot-resolver: Add a new latency graph Signed-off-by: Michael Tremer --- diff --git a/src/daemon/graphs.c b/src/daemon/graphs.c index 2c0a6c1..071e06d 100644 --- a/src/daemon/graphs.c +++ b/src/daemon/graphs.c @@ -99,6 +99,7 @@ static const td_graph_impl* graph_impls[] = { &knot_resolver_transports_graph, &knot_resolver_responses_graph, &knot_resolver_response_time_graph, + &knot_resolver_latency_graph, // Unbound &unbound_cache_performance_graph, diff --git a/src/daemon/graphs/graph.h b/src/daemon/graphs/graph.h index 3c7b4a5..e205fb8 100644 --- a/src/daemon/graphs/graph.h +++ b/src/daemon/graphs/graph.h @@ -292,6 +292,15 @@ static inline int __DRAW(td_args* args, const char* what, const char* field, #define COMPUTE_CDEF(args, cdef, ...) SCRIPT(args, "CDEF:" cdef, ##__VA_ARGS__) +#define COMPUTE_ADD(args, sum, object1, summand1, object2, summand2) \ + do { \ + COMPUTE_CDEF(args, FIELD "=" FIELD "," TOSTRING(summand2) ",+", \ + FIELD_AND_OBJECT(sum, object1), \ + FIELD_AND_OBJECT(summand1, object2) \ + ); \ + VALUE_ALL(args, sum, object1); \ + } while (0) + #define COMPUTE_SUM(args, sum, object1, summand1, object2, summand2, object3) \ do { \ COMPUTE_CDEF(args, FIELD "=" FIELD "," FIELD ",+", \ @@ -321,6 +330,25 @@ static inline int __DRAW(td_args* args, const char* what, const char* field, VALUE_ALL(args, product, object1); \ } while (0) +#define COMPUTE_DIVIDE(args, fraction, object1, dividend, object2, divisor) \ + do { \ + COMPUTE_CDEF(args, FIELD "=" FIELD "," TOSTRING(divisor) ",/", \ + FIELD_AND_OBJECT(fraction, object1), \ + FIELD_AND_OBJECT(dividend, object2) \ + ); \ + VALUE_ALL(args, fraction, object1); \ + } while (0) + +#define COMPUTE_DIVIDE_BY(args, fraction, object1, dividend, object2, divisor, object3) \ + do { \ + COMPUTE_CDEF(args, FIELD "=" FIELD "," FIELD ",/", \ + FIELD_AND_OBJECT(fraction, object1), \ + FIELD_AND_OBJECT(dividend, object2), \ + FIELD_AND_OBJECT(divisor, object3) \ + ); \ + VALUE_ALL(args, fraction, object1); \ + } while (0) + // Converts bytes to bits #define COMPUTE_BITS(args, bits, object, bytes) \ COMPUTE_MULTIPLY(args, bits, object, bytes, object, 8) @@ -344,15 +372,6 @@ static inline int __DRAW(td_args* args, const char* what, const char* field, VALUE_ALL(args, FIELD_FAHRENHEIT(field), object); \ } while (0) -#define COMPUTE_DIVIDE(args, fraction, object1, dividend, object2, divisor) \ - do { \ - COMPUTE_CDEF(args, FIELD "=" FIELD "," TOSTRING(divisor) ",/", \ - FIELD_AND_OBJECT(fraction, object1), \ - FIELD_AND_OBJECT(dividend, object2) \ - ); \ - VALUE_ALL(args, fraction, object1); \ - } while (0) - #define COMPUTE_PERCENTAGE(args, field, object1, total, object2) \ do { \ COMPUTE_CDEF(args, FIELD "=100," FIELD ",*," FIELD ",/", \ diff --git a/src/daemon/graphs/knot-resolver.c b/src/daemon/graphs/knot-resolver.c index bb4e322..1ec08e5 100644 --- a/src/daemon/graphs/knot-resolver.c +++ b/src/daemon/graphs/knot-resolver.c @@ -347,3 +347,51 @@ const td_graph_impl knot_resolver_response_time_graph = { .lower_limit = 0, .upper_limit = LONG_MAX, }; + +// Latency + +static int knot_resolver_latency_title(td_ctx* ctx, td_graph* graph, + const char* object, char* title, size_t length) { + return __td_string_set(title, length, _("Latency")); +} + +static int knot_resolver_latency_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; + + // Add one to the total so we won't divide by zero + COMPUTE_ADD(args, "answer_totalp1", NULL, "answer_total", NULL, 1); + + // Compute average response time + COMPUTE_DIVIDE_BY(args, "latency_ms", NULL, + "answer_sum_ms", NULL, "answer_totalp1", NULL); + + // Convert into seconds + COMPUTE_DIVIDE(args, "latency", NULL, "latency_ms", NULL, 1000); + + // Header + PRINT_HEADER4(args, _("Current"), _("Average"), _("Minimum"), _("Maximum")); + + // Draw the latency + DRAW_LINE_WITH_LABEL(args, 1, "latency", NULL, COLOR_LATENCY, 0, _("Latency")); + PRINT_CAMM(args, "latency", NULL, SECONDS_HIGHRES); + + return 0; +} + +const td_graph_impl knot_resolver_latency_graph = { + .name = "KnotResolverLatency", + .can_render = knot_resolver_can_render, + .render = knot_resolver_latency_render, + .title = knot_resolver_latency_title, + .vlabel = td_graph_vlabel_seconds, + + // 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 849c4c0..266cd2c 100644 --- a/src/daemon/graphs/knot-resolver.h +++ b/src/daemon/graphs/knot-resolver.h @@ -28,5 +28,6 @@ extern const td_graph_impl knot_resolver_cache_graph; extern const td_graph_impl knot_resolver_transports_graph; extern const td_graph_impl knot_resolver_responses_graph; extern const td_graph_impl knot_resolver_response_time_graph; +extern const td_graph_impl knot_resolver_latency_graph; #endif /* TELEMETRY_GRAPH_KNOT_RESOLVER_H */