From bbc89ceb3be3e5647894eacf76671be424d5ce9f Mon Sep 17 00:00:00 2001 From: DL6ER Date: Wed, 19 Jan 2022 20:03:27 +0100 Subject: [PATCH 1/3] Add others section to upstream servers pie chart Signed-off-by: DL6ER --- src/api/api.c | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/src/api/api.c b/src/api/api.c index f25c21d9..85852bde 100644 --- a/src/api/api.c +++ b/src/api/api.c @@ -498,7 +498,7 @@ void getTopClients(const char *client_message, const int *sock) void getUpstreamDestinations(const char *client_message, const int *sock) { bool sort = true; - int temparray[counters->upstreams][2], totalqueries = 0, totalcount = 0; + int temparray[counters->upstreams][2], totalcount = 0; if(command(client_message, "unsorted")) sort = false; @@ -525,34 +525,45 @@ void getUpstreamDestinations(const char *client_message, const int *sock) qsort(temparray, counters->upstreams, sizeof(int[2]), cmpdesc); } - totalqueries = totalcount + cached_queries() + blocked_queries(); + const int totalqueries = totalcount + cached_queries() + blocked_queries(); + const int others = counters->queries - totalqueries; // Loop over available forward destinations - for(int i = -2; i < min(counters->upstreams, 8); i++) + for(int i = -3; i < min(counters->upstreams, 8); i++) { float percentage = 0.0f; const char *ip, *name; in_port_t upstream_port = 0; - if(i == -2) + if(i == -3) { // Blocked queries (local lists) ip = "blocklist"; name = ip; - if(totalqueries > 0) + if(counters->queries > 0) // Whats the percentage of locked queries on the total amount of queries? - percentage = 1e2f * blocked_queries() / totalqueries; + percentage = 1e2f * blocked_queries() / counters->queries; } - else if(i == -1) + else if(i == -2) { // Local cache ip = "cache"; name = ip; - if(totalqueries > 0) + if(counters->queries > 0) // Whats the percentage of cached queries on the total amount of queries? - percentage = 1e2f * cached_queries() / totalqueries; + percentage = 1e2f * cached_queries() / counters->queries; + } + else if(i == -1 && others > 0) + { + // Others + ip = "other"; + name = ip; + + if(counters->queries > 0) + // Whats the percentage of cached queries on the total amount of queries? + percentage = 1e2f * others / counters->queries; } else { @@ -574,8 +585,8 @@ void getUpstreamDestinations(const char *client_message, const int *sock) upstream_port = upstream->port; // Get percentage - if(totalqueries > 0) - percentage = 1e2f * count / totalqueries; + if(counters->queries > 0) + percentage = 1e2f * count / counters->queries; } // Send data: From 14db6b47a469d1fca8017fca033ad79d61bd7d10 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Wed, 19 Jan 2022 20:03:27 +0100 Subject: [PATCH 2/3] Add others section to upstream servers pie chart Signed-off-by: DL6ER --- src/api/api.c | 2 +- test/test_suite.bats | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/api/api.c b/src/api/api.c index 85852bde..660a1d6e 100644 --- a/src/api/api.c +++ b/src/api/api.c @@ -555,7 +555,7 @@ void getUpstreamDestinations(const char *client_message, const int *sock) // Whats the percentage of cached queries on the total amount of queries? percentage = 1e2f * cached_queries() / counters->queries; } - else if(i == -1 && others > 0) + else if(i == -1) { // Others ip = "other"; diff --git a/test/test_suite.bats b/test/test_suite.bats index 5de5bb00..e9b67106 100644 --- a/test/test_suite.bats +++ b/test/test_suite.bats @@ -486,11 +486,12 @@ @test "Upstream Destinations reported correctly" { run bash -c 'echo ">forward-dest >quit" | nc -v 127.0.0.1 4711' printf "%s\n" "${lines[@]}" - [[ ${lines[1]} == "-2 17.02 blocklist blocklist" ]] - [[ ${lines[2]} == "-1 27.66 cache cache" ]] - [[ ${lines[3]} == "0 51.06 127.0.0.1#5555 127.0.0.1#5555" ]] - [[ ${lines[4]} == "1 4.26 127.0.0.1#5554 127.0.0.1#5554" ]] - [[ ${lines[5]} == "" ]] + [[ ${lines[1]} == "-3 17.02 blocklist blocklist" ]] + [[ ${lines[2]} == "-2 27.66 cache cache" ]] + [[ ${lines[3]} == "-1 0.00 other other" ]] + [[ ${lines[4]} == "0 51.06 127.0.0.1#5555 127.0.0.1#5555" ]] + [[ ${lines[5]} == "1 4.26 127.0.0.1#5554 127.0.0.1#5554" ]] + [[ ${lines[6]} == "" ]] } @test "Query Types reported correctly" { From 6a11211d013eecc8103618abcb1f197cde9d5cbd Mon Sep 17 00:00:00 2001 From: DL6ER Date: Wed, 19 Jan 2022 22:25:09 +0100 Subject: [PATCH 3/3] Add Query Log filtering for new virtual other upstream Signed-off-by: DL6ER --- src/api/api.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/api/api.c b/src/api/api.c index 660a1d6e..64f2d13d 100644 --- a/src/api/api.c +++ b/src/api/api.c @@ -542,7 +542,7 @@ void getUpstreamDestinations(const char *client_message, const int *sock) name = ip; if(counters->queries > 0) - // Whats the percentage of locked queries on the total amount of queries? + // Whats the percentage of blocked queries on the total amount of queries? percentage = 1e2f * blocked_queries() / counters->queries; } else if(i == -2) @@ -731,10 +731,12 @@ void getAllQueries(const char *client_message, const int *sock) sscanf(client_message, ">getallqueries-forward %255s", forwarddest); filterforwarddest = true; - if(strcmp(forwarddest, "cache") == 0) - forwarddestid = -1; - else if(strcmp(forwarddest, "blocklist") == 0) + if(strcmp(forwarddest, "blocklist") == 0) + forwarddestid = -3; + else if(strcmp(forwarddest, "cache") == 0) forwarddestid = -2; + else if(strcmp(forwarddest, "other") == 0) + forwarddestid = -1; else { // Extract address/name and port @@ -987,10 +989,13 @@ void getAllQueries(const char *client_message, const int *sock) if(filterforwarddest) { // Skip if not from the virtual blocking "upstream" server - if(forwarddestid == -2 && !query->flags.blocked) + if(forwarddestid == -3 && !query->flags.blocked) continue; // Does the user want to see queries answered from local cache? - else if(forwarddestid == -1 && query->status != QUERY_CACHE) + else if(forwarddestid == -2 && query->status != QUERY_CACHE) + continue; + // Does the user want to see queries from the "other" category + else if(forwarddestid == -1 && query->status != QUERY_IN_PROGRESS) continue; // Does the user want to see queries answered by an upstream server? else if(forwarddestid >= 0 && forwarddestid != query->upstreamID)