Skip to content

Commit

Permalink
ping logging subsystem
Browse files Browse the repository at this point in the history
  • Loading branch information
Absolucy committed Dec 26, 2024
1 parent f24cb08 commit 13147c2
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
44 changes: 44 additions & 0 deletions monkestation/code/controllers/subsystem/ping_logging.dm
Original file line number Diff line number Diff line change
@@ -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 ..()
1 change: 1 addition & 0 deletions tgstation.dme
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 13147c2

Please sign in to comment.