Skip to content

Commit

Permalink
Add others section to upstream servers pie chart
Browse files Browse the repository at this point in the history
Signed-off-by: DL6ER <dl6er@dl6er.de>
  • Loading branch information
DL6ER committed Jan 19, 2022
1 parent 48e7bd8 commit 03c2987
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
33 changes: 22 additions & 11 deletions src/api/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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() / counters->queries;
}
else if(i == -1)
{
// Others
ip = "other";
name = ip;

if(counters->queries > 0)
// Whats the percentage of cached queries on the total amount of queries?
percentage = 1e2f * cached_queries() / totalqueries;
percentage = 1e2f * others / counters->queries;
}
else
{
Expand All @@ -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:
Expand Down
11 changes: 6 additions & 5 deletions test/test_suite.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down

0 comments on commit 03c2987

Please sign in to comment.