Only collect server stats when clients

This commit is contained in:
Andrew 2022-10-20 15:33:51 -04:00
parent a96753d3a7
commit 23b3e642a0

View File

@ -1223,6 +1223,9 @@ class ServerInstance:
# **********************************************************************************
def realtime_stats(self):
# only get stats if clients are connected.
# no point in burning cpu
if len(self.helper.websocket_helper.clients) > 0:
total_players = 0
max_players = 0
servers_ping = []
@ -1276,7 +1279,9 @@ class ServerInstance:
"version": raw_ping_result.get("version"),
"icon": raw_ping_result.get("icon"),
"crashed": self.is_crashed,
"created": datetime.datetime.now().strftime("%Y/%m/%d, %H:%M:%S"),
"created": datetime.datetime.now().strftime(
"%Y/%m/%d, %H:%M:%S"
),
},
)
total_players += int(raw_ping_result.get("online"))
@ -1284,7 +1289,9 @@ class ServerInstance:
self.record_server_stats()
if (len(servers_ping) > 0) & (len(self.helper.websocket_helper.clients) > 0):
if (len(servers_ping) > 0) & (
len(self.helper.websocket_helper.clients) > 0
):
try:
self.helper.websocket_helper.broadcast_page(
"/panel/dashboard", "update_server_status", servers_ping