]> git.ipfire.org Git - fireperf.git/commitdiff
server: Print some useful statistics about open connections
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 29 Jan 2021 15:06:53 +0000 (15:06 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 29 Jan 2021 15:06:53 +0000 (15:06 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/server.c

index 6725389f8c75be3719e0042c6f0bdfca7cc9f200..c6672f166cc5ae45a1f27eb3efc6f12ac58b0586 100644 (file)
@@ -22,6 +22,7 @@
 #include <string.h>
 #include <sys/epoll.h>
 #include <sys/timerfd.h>
+#include <time.h>
 #include <unistd.h>
 
 #include "logging.h"
@@ -36,8 +37,35 @@ struct fireperf_server_stats {
        unsigned int connections;
 };
 
+static char __timespec[20];
+
+static const char* format_timespec(const struct timespec* t) {
+       // Convert to local time
+       struct tm* tm = localtime(&t->tv_sec);
+
+       size_t s = strftime(__timespec, sizeof(__timespec), "%F %T", tm);
+
+       if (s)
+               return __timespec;
+
+       return NULL;
+}
+
 static int dump_stats(struct fireperf_config* conf, const struct fireperf_server_stats* stats) {
-       DEBUG(conf, "Printing statistics...\n");
+       struct timespec now;
+
+       // Fetch the time
+       int r = clock_gettime(CLOCK_REALTIME, &now);
+       if (r) {
+               ERROR(conf, "Could not fetch the time: %s\n", strerror(errno));
+               return 1;
+       }
+
+       // Format timestamp
+       const char* timestamp = format_timespec(&now);
+
+       INFO(conf, "--- %s --------------------\n", timestamp);
+       INFO(conf, "  %-20s: %20u\n", "Open Connection(s)", stats->connections);
 
        return 0;
 }