Include number of active clients in the response of GET /api/stats/summary

Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
DL6ER
2023-10-21 18:44:38 +02:00
parent f798e569a6
commit c951e253a5
2 changed files with 18 additions and 0 deletions
+4
View File
@@ -469,6 +469,10 @@ components:
clients:
type: object
properties:
active:
type: integer
description: Number of active clients (seen in the last 24 hours)
example: 10
total:
type: integer
description: Total number of clients seen by FTL
+14
View File
@@ -106,7 +106,21 @@ int api_stats_summary(struct ftl_conn *api)
JSON_ADD_NUMBER_TO_OBJECT(replies, get_query_reply_str(reply), counters->reply[reply]);
JSON_ADD_ITEM_TO_OBJECT(queries, "replies", replies);
// Count clients that have been active within the most recent 24 hours
unsigned int activeclients = 0;
for(int clientID=0; clientID < counters->clients; clientID++)
{
// Get client pointer
const clientsData* client = getClient(clientID, true);
if(client == NULL)
continue;
if(client->count > 0)
activeclients++;
}
cJSON *clients = JSON_NEW_OBJECT();
JSON_ADD_NUMBER_TO_OBJECT(clients, "active", activeclients);
JSON_ADD_NUMBER_TO_OBJECT(clients, "total", counters->clients);
cJSON *gravity = JSON_NEW_OBJECT();