From: Michael Tremer Date: Fri, 10 Jul 2026 11:13:19 +0000 (+0000) Subject: sources: knot-resolver: Connect to socket instead of kresctl X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9eca7ff2e5b2f69cfaf40e3e609c53f8eff11bf5;p=telemetry.git sources: knot-resolver: Connect to socket instead of kresctl This has significantly less overhead than calling the rather slow Python command line tool. Signed-off-by: Michael Tremer --- diff --git a/src/daemon/sources/knot-resolver.c b/src/daemon/sources/knot-resolver.c index 2d67892..e0e758d 100644 --- a/src/daemon/sources/knot-resolver.c +++ b/src/daemon/sources/knot-resolver.c @@ -23,8 +23,8 @@ #include #include -#include "../command.h" #include "../ctx.h" +#include "../request.h" #include "../source.h" #include "../string.h" #include "knot-resolver.h" @@ -159,14 +159,14 @@ static int knot_resolver_parse_metrics(td_ctx* ctx, return 0; } -static int knot_resolver_on_success(td_ctx* ctx, td_file* stdout, void* data) { +static int knot_resolver_on_success(td_ctx* ctx, td_file* output, void* data) { sd_json_variant* json = NULL; td_metrics* metrics = NULL; td_source* source = data; int r; // Parse the output as JSON - r = td_file_parse_json(stdout, &json, 0); + r = td_file_parse_json(output, &json, 0); if (r < 0) goto ERROR; @@ -193,12 +193,35 @@ ERROR: } static int knot_resolver_heartbeat(td_ctx* ctx, td_source* source) { - // Run kresctl to fetch metrics - const char* argv[] = { - "kresctl", "metrics", NULL, - }; + td_request* request = NULL; + int r; + + // Create a new request + r = td_source_create_request(source, &request); + if (r < 0) + goto ERROR; + + // Set the URL + r = td_request_set_url(request, "http://localhost/metrics/json"); + if (r < 0) + goto ERROR; - return td_source_run_command(source, NULL, argv, knot_resolver_on_success, source); + // Set the socket + r = td_request_set_socket(request, "/var/run/knot-resolver/kres-api.sock"); + if (r < 0) + goto ERROR; + + // Configure the success callback + td_request_on_success(request, knot_resolver_on_success, source); + + // Launch the request + r = td_request_launch(request); + +ERROR: + if (request) + td_request_unref(request); + + return r; } const td_source_impl knot_resolver_source = {