not count stale games as active games because they will get deletet after ttl expire into redis
Build and Push Docker Container / build-and-push (push) Successful in 56s
Build and Push Docker Container / build-and-push (push) Successful in 56s
This commit is contained in:
@@ -2,7 +2,6 @@ import time
|
||||
|
||||
from server.metrics.MetricsManager import MetricsManager
|
||||
|
||||
|
||||
class ServerMetricsCollector:
|
||||
def __init__(self, metrics_manager:MetricsManager, game_state_local_cache:bool, metrics_backend:str, game_state_backend:str, stale_game_timeout_sec:int, game_last_seen_unix:dict, game_move_counts:dict,):
|
||||
self._manager = metrics_manager
|
||||
@@ -122,15 +121,23 @@ class ServerMetricsCollector:
|
||||
oldest_active_age = (
|
||||
max(0, now - min(game_last_seen_unix.values())) if game_last_seen_unix else 0
|
||||
)
|
||||
|
||||
stale_candidates = sum(
|
||||
1
|
||||
for last_seen in game_last_seen_unix.values()
|
||||
if now - last_seen >= self._stale_game_timeout_sec
|
||||
)
|
||||
|
||||
if self._game_state_backend_is_redis:
|
||||
report_stale_candidates = 0
|
||||
report_active_games = len(game_last_seen_unix) - stale_candidates
|
||||
else:
|
||||
report_stale_candidates = stale_candidates
|
||||
report_active_games = len(game_last_seen_unix)
|
||||
|
||||
return {
|
||||
**self._metrics,
|
||||
'active_games': len(game_last_seen_unix),
|
||||
'active_games': report_active_games,
|
||||
'tracked_games': len(game_move_counts),
|
||||
'avg_turns_per_game': round(avg_turns, 2),
|
||||
'win_rate': round(win_rate, 4),
|
||||
@@ -139,7 +146,7 @@ class ServerMetricsCollector:
|
||||
'move_direction_counts': dict(self._metrics['move_direction_counts']),
|
||||
'oldest_active_game_age_sec': oldest_active_age,
|
||||
'stale_game_timeout_sec': self._stale_game_timeout_sec,
|
||||
'active_games_stale': stale_candidates,
|
||||
'active_games_stale': report_stale_candidates,
|
||||
}
|
||||
|
||||
async def build_snapshot(self, game_last_seen_unix:dict, game_move_counts:dict) -> dict:
|
||||
|
||||
Reference in New Issue
Block a user