use std::time::{SystemTime, UNIX_EPOCH}; #[derive(Debug, Clone)] pub struct NodeMetrics { pub block_height: u64, pub peer_count: u32, pub tx_pool_size: usize, pub sync_progress: f64, pub cpu_usage: f64, pub memory_usage: f64, pub disk_usage: f64, pub timestamp: u64, } impl NodeMetrics { pub fn collect() -> Self { let timestamp = SystemTime::now() .duration_since(UNIX_EPOCH) .unwrap() .as_secs(); Self { block_height: 12345, peer_count: 42, tx_pool_size: 128, sync_progress: 99.9, cpu_usage: 25.5, memory_usage: 45.2, disk_usage: 60.1, timestamp, } } pub fn display(&self) { println!("📊 节点指标"); println!(" 区块高度: {}", self.block_height); println!(" 连接节点: {}", self.peer_count); println!(" 交易池: {}", self.tx_pool_size); println!(" 同步进度: {:.1}%", self.sync_progress); println!(" CPU使用: {:.1}%", self.cpu_usage); println!(" 内存使用: {:.1}%", self.memory_usage); println!(" 磁盘使用: {:.1}%", self.disk_usage); } }