From 13147c2a2246808d21af7b08b1f42be7ef7767d4 Mon Sep 17 00:00:00 2001 From: Lucy Date: Thu, 26 Dec 2024 02:08:43 -0500 Subject: [PATCH] ping logging subsystem --- .../controllers/subsystem/ping_logging.dm | 44 +++++++++++++++++++ tgstation.dme | 1 + 2 files changed, 45 insertions(+) create mode 100644 monkestation/code/controllers/subsystem/ping_logging.dm diff --git a/monkestation/code/controllers/subsystem/ping_logging.dm b/monkestation/code/controllers/subsystem/ping_logging.dm new file mode 100644 index 000000000000..d85384a64a2d --- /dev/null +++ b/monkestation/code/controllers/subsystem/ping_logging.dm @@ -0,0 +1,44 @@ +SUBSYSTEM_DEF(ping_logging) + name = "Ping Logging" + wait = 0.5 SECONDS + flags = SS_KEEP_TIMING + priority = FIRE_PRIORITY_TICKER + runlevels = ALL + var/last_overall_avg = 0 + var/active_spike = FALSE + +/datum/controller/subsystem/ping_logging/Initialize() + fire() + WRITE_LOG("[GLOB.log_directory]/ping.log", "average ping at init: [last_overall_avg]ms") + return SS_INIT_NO_NEED + +/datum/controller/subsystem/ping_logging/Recover() + flags |= SS_NO_INIT + last_overall_avg = SSping_logging.last_overall_avg + active_spike = SSping_logging.active_spike + +/datum/controller/subsystem/ping_logging/fire(resumed = FALSE) + var/overall_avg = 0 + var/clients = 0 + for(var/client/client as anything in GLOB.clients) + var/avgping = client?.avgping + if(avgping > 10) + overall_avg += avgping + clients++ + if(!clients) + last_overall_avg = 0 + return + overall_avg = round(overall_avg / clients, 1) + if(!active_spike) + if(overall_avg >= 1000) + WRITE_LOG("[GLOB.log_directory]/ping.log", "ping spike detected (avg >=1000ms): [overall_avg]ms") + active_spike = TRUE + else + if(overall_avg < 500) + WRITE_LOG("[GLOB.log_directory]/ping.log", "spike possibly ended ([overall_avg]ms)") + active_spike = FALSE + last_overall_avg = overall_avg + +/datum/controller/subsystem/ping_logging/stat_entry(msg) + msg = "LAST:[last_overall_avg]ms" + return ..() diff --git a/tgstation.dme b/tgstation.dme index 6d7052a6722a..833284853ec7 100644 --- a/tgstation.dme +++ b/tgstation.dme @@ -5924,6 +5924,7 @@ #include "monkestation\code\controllers\subsystem\glowshroom.dm" #include "monkestation\code\controllers\subsystem\init_profiler.dm" #include "monkestation\code\controllers\subsystem\job.dm" +#include "monkestation\code\controllers\subsystem\ping_logging.dm" #include "monkestation\code\controllers\subsystem\plexora.dm" #include "monkestation\code\controllers\subsystem\profiler.dm" #include "monkestation\code\controllers\subsystem\z_priority_effects.dm"