Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include number of active clients in summary #1688

Merged
merged 1 commit into from
Oct 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/api/docs/content/specs/stats.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions src/api/stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down