Skip to content

Commit 68f1036

Browse files
authored
Merge pull request #19 from temper-mc/fix/dashboard
Use redesigned dashboard
2 parents c85ac9b + e62420d commit 68f1036

File tree

12 files changed

+73
-21
lines changed

12 files changed

+73
-21
lines changed

src/app/runtime/src/game_loop.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ use temper_game_systems::{
2424
use temper_messages::register_messages;
2525
use temper_net_runtime::connection::{NewConnection, handle_connection};
2626
use temper_net_runtime::server::create_server_listener;
27-
use temper_performance::ServerPerformance;
2827
use temper_performance::tick::TickData;
2928
use temper_protocol::{PacketSender, create_packet_senders};
3029
use temper_resources::register_resources;
@@ -209,7 +208,10 @@ pub fn start_game_loop(global_state: GlobalState, no_tui: bool) -> Result<(), Bi
209208
ran_count,
210209
};
211210

212-
let mut performance = ecs_world.resource_mut::<ServerPerformance>();
211+
let mut performance = global_state
212+
.performance
213+
.lock()
214+
.expect("Failed to lock performance resource");
213215
performance.tps.record_tick(tick_data);
214216
}
215217
}

src/dashboard/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ serde_json = { workspace = true }
1414
include_dir = { workspace = true }
1515
mime_guess = { workspace = true }
1616
dir-size = { workspace = true }
17+
uuid = { workspace = true, features = ["serde"] }
1718

1819
# temper local crates
1920
temper-state = { workspace = true }
2021
temper-general-purpose = { workspace = true }
2122
temper-config = { workspace = true }
23+
temper-performance = { workspace = true }
2224

2325
[build-dependencies]
2426
reqwest = { workspace = true }

src/dashboard/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use zip::ZipArchive;
88
// CONFIGURATION
99
// Since we set up the GitHub Action to release to 'latest', we can use this URL.
1010
const DASHBOARD_URL: &str =
11-
"https://github.com/ferrumc-rs/dashboard/releases/download/latest/ferrumc-dashboard.zip";
11+
"https://github.com/temper-mc/dashboard/releases/download/latest/temper-dashboard.zip";
1212

1313
fn main() -> Result<()> {
1414
// Tell Cargo about our custom cfg flags to suppress warnings

src/dashboard/src/handshake.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ pub struct SystemData {
1111
pub cpu_cores: usize,
1212
/// Number of logical threads (including hyperthreading)
1313
pub cpu_threads: usize,
14+
/// OS name and version (e.g., "Windows 10 Pro 10.0.19044")
15+
pub os: String,
1416
}
1517

1618
/// Server configuration data
@@ -42,10 +44,18 @@ impl Handshake {
4244
let cpu_cores = System::physical_core_count().unwrap_or(1);
4345
let cpu_threads = sys.cpus().len();
4446

47+
let os = format!(
48+
"{} {} {}",
49+
System::name().unwrap_or_default(),
50+
System::os_version().unwrap_or_default(),
51+
System::kernel_version().unwrap_or_default()
52+
);
53+
4554
let system = SystemData {
4655
cpu_model,
4756
cpu_cores,
4857
cpu_threads,
58+
os,
4959
};
5060

5161
let config = ConfigData {

src/dashboard/src/telemetry.rs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ use std::path::PathBuf;
44
use std::time::Duration;
55
use sysinfo::{Pid, ProcessesToUpdate, System};
66
use temper_config::server_config::get_global_config;
7+
use temper_performance::memory::MemoryUnit;
78
use temper_state::GlobalState;
89
use tokio::sync::broadcast::Sender;
910
use tokio::time::interval;
1011
use tracing::{debug, error};
12+
use uuid::Uuid;
1113

1214
#[derive(Clone, Debug, Serialize)]
1315
pub 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

src/default_commands/src/tps.rs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,28 @@
1+
use bevy_ecs::prelude::ResMut;
12
use std::time::Duration;
2-
3-
use bevy_ecs::system::ResMut;
43
use temper_commands::Sender;
54
use temper_macros::command;
6-
use temper_performance::{memory::MemoryUnit, ServerPerformance};
5+
use temper_performance::memory::MemoryUnit;
6+
use temper_state::GlobalStateResource;
77
use temper_text::{NamedColor, TextComponent, TextComponentBuilder};
88

99
#[command("tps")]
10-
fn tps_command(#[sender] sender: Sender, performance_res: ResMut<ServerPerformance>) {
11-
let performance = performance_res.into_inner();
10+
fn tps_command(#[sender] sender: Sender, state: ResMut<GlobalStateResource>) {
11+
let (current, peak) = {
12+
let mut perf_lock = state
13+
.0
14+
.performance
15+
.lock()
16+
.expect("Failed to lock performance resource");
17+
perf_lock.memory.get_memory(MemoryUnit::Kilobytes)
18+
};
1219

13-
let tps = &performance.tps;
14-
let (current, peak) = performance.memory.get_memory(MemoryUnit::Kilobytes);
20+
let perf_lock = state
21+
.0
22+
.performance
23+
.lock()
24+
.expect("Failed to lock performance resource");
25+
let tps = &perf_lock.tps;
1526

1627
sender.send_message(
1728
TextComponentBuilder::new("Server Performance\n")

src/performance/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ version.workspace = true
88
bevy_ecs = { workspace = true }
99
sysinfo = { workspace = true }
1010
tracing = { workspace = true }
11+
serde = { workspace = true }
1112

1213
[lints]
1314
workspace = true

src/performance/src/lib.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use bevy_ecs::resource::Resource;
21
use tracing::warn;
32

43
use crate::{memory::MemoryUsage, tps::TPSMonitor};
@@ -9,7 +8,7 @@ pub mod tps;
98

109
pub const WINDOW_SECONDS: usize = 60;
1110

12-
/// Core ECS resource for all server performance metrics.
11+
/// Core tracker for all server performance metrics.
1312
///
1413
/// This resource is updated once per tick by the main scheduler
1514
/// loop and can be queried by commands, debug tools, or plugins.
@@ -36,7 +35,6 @@ pub const WINDOW_SECONDS: usize = 60;
3635
/// - Tick durations
3736
/// - Rolling TPS (1s / 5s / 15s windows)
3837
/// - Memory Usage (Current / Peak)
39-
#[derive(Resource)]
4038
pub struct ServerPerformance {
4139
pub tps: TPSMonitor,
4240
pub memory: MemoryUsage,
@@ -45,7 +43,7 @@ pub struct ServerPerformance {
4543
impl ServerPerformance {
4644
pub fn new(tps: u32) -> Self {
4745
if !sysinfo::IS_SUPPORTED_SYSTEM {
48-
warn!("System does not support 'sysinfo', disabling server performance statisics.");
46+
warn!("System does not support 'sysinfo', metrics are likely to be inaccurate or unavailable");
4947
}
5048

5149
Self {

src/performance/src/tick.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub struct TickData {
99
}
1010
#[derive(Debug)]
1111
pub(crate) struct TickHistory {
12-
buffer: VecDeque<TickData>,
12+
pub(crate) buffer: VecDeque<TickData>,
1313
capacity: usize,
1414
}
1515

src/resources/src/lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@ use crate::time::WorldTime;
44
use crate::world_sync_tracker::WorldSyncTracker;
55
use bevy_ecs::prelude::World;
66
use crossbeam_channel::Receiver;
7-
use temper_config::server_config::get_global_config;
87
use temper_entities::PhysicalRegistry;
98
use temper_net_runtime::connection::NewConnection;
10-
use temper_performance::ServerPerformance;
119
use temper_state::GlobalStateResource;
1210

1311
pub mod new_conn;
@@ -27,7 +25,6 @@ pub fn register_resources(
2725
last_synced: std::time::Instant::now(),
2826
});
2927
world.insert_resource(WorldTime::default());
30-
world.insert_resource(ServerPerformance::new(get_global_config().tps));
3128
world.insert_resource(ServerCommandReceiver(server_command_recv));
3229
world.insert_resource(PhysicalRegistry::new());
3330
}

0 commit comments

Comments
 (0)