Merge pull request #1284 from pi-hole/tweak/upstream_pie_others

Add others section to upstream servers pie chart
This commit is contained in:
DL6ER
2022-01-21 04:47:43 +01:00
committed by GitHub
2 changed files with 39 additions and 22 deletions
+33 -17
View File
@@ -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)
// Whats the percentage of locked queries on the total amount of queries?
percentage = 1e2f * blocked_queries() / totalqueries;
if(counters->queries > 0)
// Whats the percentage of blocked queries on the total amount of queries?
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
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:
@@ -720,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
@@ -976,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)
+6 -5
View File
@@ -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" {