diff --git a/src/api/admin/api.rs b/src/api/admin/api.rs index fb8d5085..9c02e74a 100644 --- a/src/api/admin/api.rs +++ b/src/api/admin/api.rs @@ -1270,17 +1270,10 @@ pub struct LocalGetNodeStatisticsRequest; #[derive(Debug, Clone, Serialize, Deserialize, ToSchema)] #[serde(rename_all = "camelCase")] pub struct LocalGetNodeStatisticsResponse { - // FIXME for v3: remove freeform field and move display logic to garage crate - /// node statistics as a free-form string, kept for compatibility with nodes - /// running older v2.x versions of garage - pub freeform: String, - // FIXME for v3: remove serde(default) for fields below /// metadata table statistics - #[serde(default, skip_serializing_if = "Option::is_none")] - pub table_stats: Option>, + pub table_stats: Vec, /// block manager statistics - #[serde(default, skip_serializing_if = "Option::is_none")] - pub block_manager_stats: Option, + pub block_manager_stats: NodeBlockManagerStats, } #[derive(Debug, Clone, Serialize, Deserialize, ToSchema)] diff --git a/src/api/admin/node.rs b/src/api/admin/node.rs index fda38f8a..8a0c9897 100644 --- a/src/api/admin/node.rs +++ b/src/api/admin/node.rs @@ -1,8 +1,5 @@ -use std::fmt::Write; use std::sync::Arc; -use format_table::format_table_to_string; - use garage_util::error::Error as GarageError; use garage_table::replication::*; @@ -115,27 +112,6 @@ impl RequestHandler for LocalGetNodeStatisticsRequest { garage: &Arc, _admin: &Admin, ) -> Result { - let sys_status = garage.system.local_status(); - - let hostname = sys_status.hostname.unwrap_or_default().to_string(); - let garage_version = garage_util::version::garage_version().to_string(); - let garage_features = garage_util::version::garage_features() - .unwrap() - .iter() - .map(ToString::to_string) - .collect::>(); - let rustc_version = garage_util::version::rust_version().to_string(); - let db_engine_descr = garage.db.engine(); - - let mut ret = format_table_to_string(vec![ - format!("Node ID:\t{:?}", garage.system.id), - format!("Hostname:\t{}", hostname), - format!("Garage version:\t{}", garage_version), - format!("Garage features:\t{}", garage_features.join(", ")), - format!("Rust compiler version:\t{}", rustc_version), - format!("Database engine:\t{}", db_engine_descr), - ]); - let mut table_stats = vec![ gather_table_stats(&garage.admin_token_table)?, gather_table_stats(&garage.bucket_table)?, @@ -155,55 +131,15 @@ impl RequestHandler for LocalGetNodeStatisticsRequest { table_stats.push(gather_table_stats(&garage.k2v.counter_table.table)?); } - // Gather table statistics - let mut table = vec![" Table\tItems\tMklItems\tMklTodo\tInsQueue\tGcTodo".into()]; - table.extend(table_stats.iter().map(|ts| { - format!( - " {}\t{}\t{}\t{}\t{}\t{}", - ts.table_name, - ts.items, - ts.merkle_items, - ts.merkle_queue_len, - ts.insert_queue_len, - ts.gc_queue_len, - ) - })); - - write!( - &mut ret, - "\nTable stats:\n{}", - format_table_to_string(table) - ) - .unwrap(); - let block_manager_stats = NodeBlockManagerStats { rc_entries: garage.block_manager.rc_approximate_len()? as u64, resync_queue_len: garage.block_manager.resync.queue_len() as u64, resync_errors: garage.block_manager.resync.errored() as u64, }; - // Gather block manager statistics - writeln!(&mut ret, "\nBlock manager stats:").unwrap(); - - ret += &format_table_to_string(vec![ - format!( - " number of RC entries:\t{} (~= number of blocks)", - block_manager_stats.rc_entries - ), - format!( - " resync queue length:\t{}", - block_manager_stats.resync_queue_len, - ), - format!( - " blocks with resync errors:\t{}", - block_manager_stats.resync_errors - ), - ]); - Ok(LocalGetNodeStatisticsResponse { - freeform: ret, - table_stats: Some(table_stats), - block_manager_stats: Some(block_manager_stats), + table_stats, + block_manager_stats, }) } } diff --git a/src/garage/cli/remote/node.rs b/src/garage/cli/remote/node.rs index cabb021e..48f8c292 100644 --- a/src/garage/cli/remote/node.rs +++ b/src/garage/cli/remote/node.rs @@ -42,20 +42,84 @@ impl Cli { } pub async fn cmd_stats(&self, cmd: StatsOpt) -> Result<(), Error> { + let query_node = if cmd.all_nodes { + "*".to_string() + } else { + hex::encode(self.rpc_host) + }; + let res = self .api_request(GetNodeStatisticsRequest { - node: if cmd.all_nodes { - "*".to_string() - } else { - hex::encode(self.rpc_host) - }, + node: query_node.clone(), body: LocalGetNodeStatisticsRequest, }) .await?; + let node_info = self + .api_request(GetNodeInfoRequest { + node: query_node.clone(), + body: LocalGetNodeInfoRequest, + }) + .await?; + for (node, res) in res.success.iter() { println!("==== NODE [{:.16}] ====", node); - println!("{}\n", res.freeform); + + if let Some(info) = node_info.success.get(node) { + format_table(vec![ + format!("Node ID:\t{:.16}", node), + format!("Hostname:\t{}", info.hostname.as_deref().unwrap_or("?")), + format!("Garage version:\t{}", info.garage_version), + format!( + "Garage features:\t{}", + info.garage_features + .as_ref() + .map(|x| x.join(", ")) + .unwrap_or("?".to_string()) + ), + format!("Rust compiler version:\t{}", info.rust_version), + format!("Database engine:\t{}", info.db_engine), + ]); + } else { + println!("Failed to fetch node info"); + } + + // Gather table statistics + let mut table = vec![" Table\tItems\tMklItems\tMklTodo\tInsQueue\tGcTodo".into()]; + table.extend(res.table_stats.iter().map(|ts| { + format!( + " {}\t{}\t{}\t{}\t{}\t{}", + ts.table_name, + ts.items, + ts.merkle_items, + ts.merkle_queue_len, + ts.insert_queue_len, + ts.gc_queue_len, + ) + })); + + println!("\nTable stats:"); + format_table(table); + + // Gather block manager statistics + println!("\nBlock manager stats:"); + + format_table(vec![ + format!( + " number of RC entries:\t{} (~= number of blocks)", + res.block_manager_stats.rc_entries + ), + format!( + " resync queue length:\t{}", + res.block_manager_stats.resync_queue_len, + ), + format!( + " blocks with resync errors:\t{}", + res.block_manager_stats.resync_errors + ), + ]); + + println!("\n"); } for (node, err) in res.error.iter() {