@@ -4,10 +4,12 @@ use std::path::PathBuf;
44use std:: time:: Duration ;
55use sysinfo:: { Pid , ProcessesToUpdate , System } ;
66use temper_config:: server_config:: get_global_config;
7+ use temper_performance:: memory:: MemoryUnit ;
78use temper_state:: GlobalState ;
89use tokio:: sync:: broadcast:: Sender ;
910use tokio:: time:: interval;
1011use tracing:: { debug, error} ;
12+ use uuid:: Uuid ;
1113
1214#[ derive( Clone , Debug , Serialize ) ]
1315pub struct ServerMetric {
@@ -23,6 +25,14 @@ pub struct ServerMetric {
2325 pub storage_used : u64 ,
2426 /// Number of connected players
2527 pub player_count : usize ,
28+ pub tps : f32 ,
29+ pub players : Vec < PlayerInfo > ,
30+ }
31+
32+ #[ derive( Clone , Debug , Serialize ) ]
33+ pub struct PlayerInfo {
34+ name : String ,
35+ uuid : Uuid ,
2636}
2737
2838/// Events sent from the server to the dashboard (websocket)
@@ -69,15 +79,31 @@ pub async fn start_telemetry_loop(tx: Sender<DashboardEvent>, state: GlobalState
6979 0
7080 } ;
7181
82+ let cpu_count = sys. cpus ( ) . len ( ) as f32 ;
83+
7284 let player_count = state. players . player_list . len ( ) ;
85+ let mut perf_lock = state
86+ . performance
87+ . lock ( )
88+ . expect ( "Failed to lock performance resource" ) ;
7389
7490 let metric = ServerMetric {
75- cpu_usage : process. cpu_usage ( ) ,
76- ram_usage : process . memory ( ) ,
91+ cpu_usage : process. cpu_usage ( ) / cpu_count ,
92+ ram_usage : perf_lock . memory . get_memory ( MemoryUnit :: Bytes ) . 0 ,
7793 total_ram : sys. total_memory ( ) ,
7894 uptime : process. run_time ( ) ,
7995 storage_used,
8096 player_count,
97+ tps : perf_lock. tps . tps ( Duration :: from_secs ( 1 ) ) ,
98+ players : state
99+ . players
100+ . player_list
101+ . iter ( )
102+ . map ( |kv| PlayerInfo {
103+ name : kv. value ( ) . 1 . clone ( ) ,
104+ uuid : Uuid :: from_u128 ( kv. value ( ) . 0 ) ,
105+ } )
106+ . collect ( ) ,
81107 } ;
82108
83109 // Broadcast to all connected web clients
0 commit comments