From 8dfbba2f749476ede8d78dc29ecb5a6033d64301 Mon Sep 17 00:00:00 2001
From: "Rob Swindell (on Windows 11)" <rob@synchro.net>
Date: Thu, 11 Jul 2024 18:30:53 -0700
Subject: [PATCH] Track/log/publish-to-MQTT services server (total) client
 highwater mark

Like the other servers.

A sysop likely would want to know which services/protocols had what
utilization (as a portion of the total highwater mark), so that'll have to
be added later.
---
 src/sbbs3/services.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/src/sbbs3/services.c b/src/sbbs3/services.c
index ac6a27edea..968899b1cf 100644
--- a/src/sbbs3/services.c
+++ b/src/sbbs3/services.c
@@ -62,6 +62,7 @@ static char*	text[TOTAL_TEXT];
 static volatile bool	terminated=false;
 static time_t	uptime=0;
 static ulong	served=0;
+static volatile uint32_t client_highwater=0;
 static str_list_t pause_semfiles;
 static str_list_t recycle_semfiles;
 static str_list_t shutdown_semfiles;
@@ -210,8 +211,17 @@ static ulong active_clients(void)
 
 static void update_clients(void)
 {
+	ulong client_count = active_clients();
 	if(startup!=NULL && startup->clients!=NULL)
-		startup->clients(startup->cbdata,active_clients());
+		startup->clients(startup->cbdata, client_count);
+
+	if(client_count > client_highwater) {
+		client_highwater = client_count;
+		if(client_highwater > 1)
+			lprintf(LOG_NOTICE, "New active client highwater mark: %u"
+				,client_highwater);
+		mqtt_pub_uintval(&mqtt, TOPIC_SERVER, "highwater", client_highwater);
+	}
 }
 
 static void client_on(SOCKET sock, client_t* client, bool update)
@@ -1762,7 +1772,7 @@ static void cleanup(int code)
 
 	thread_down();
 	if(terminated || code)
-		lprintf(LOG_INFO,"#### Services thread terminated (%lu clients served)",served);
+		lprintf(LOG_INFO,"#### Services thread terminated (%lu clients served, %u concurrently)",served, client_highwater);
 	set_state(SERVER_STOPPED);
 	mqtt_shutdown(&mqtt);
 	if(startup!=NULL && startup->terminated!=NULL)
-- 
GitLab