mirror of
https://mirror.suhoan.cn/https://github.com/EasyTier/EasyTier.git
synced 2025-12-12 04:37:23 +08:00
cli: improve peer table display with shorter columns for small display (#1342)
- Add short column names for latency, loss rate, rx/tx bytes, tunnel protocol and NAT type - Format loss rate as percentage with one decimal place - Change table style from modern to markdown for better readability
This commit is contained in:
@@ -47,7 +47,7 @@ use easytier::{
|
|||||||
rpc_types::controller::BaseController,
|
rpc_types::controller::BaseController,
|
||||||
},
|
},
|
||||||
tunnel::tcp::TcpTunnelConnector,
|
tunnel::tcp::TcpTunnelConnector,
|
||||||
utils::{cost_to_str, float_to_str, PeerRoutePair},
|
utils::{cost_to_str, PeerRoutePair},
|
||||||
};
|
};
|
||||||
|
|
||||||
rust_i18n::i18n!("locales", fallback = "en");
|
rust_i18n::i18n!("locales", fallback = "en");
|
||||||
@@ -484,12 +484,19 @@ impl CommandHandler<'_> {
|
|||||||
ipv4: String,
|
ipv4: String,
|
||||||
hostname: String,
|
hostname: String,
|
||||||
cost: String,
|
cost: String,
|
||||||
|
#[tabled(rename = "lat(ms)")]
|
||||||
lat_ms: String,
|
lat_ms: String,
|
||||||
|
#[tabled(rename = "loss")]
|
||||||
loss_rate: String,
|
loss_rate: String,
|
||||||
|
#[tabled(rename = "rx")]
|
||||||
rx_bytes: String,
|
rx_bytes: String,
|
||||||
|
#[tabled(rename = "tx")]
|
||||||
tx_bytes: String,
|
tx_bytes: String,
|
||||||
|
#[tabled(rename = "tunnel")]
|
||||||
tunnel_proto: String,
|
tunnel_proto: String,
|
||||||
|
#[tabled(rename = "NAT")]
|
||||||
nat_type: String,
|
nat_type: String,
|
||||||
|
#[tabled(skip)]
|
||||||
id: String,
|
id: String,
|
||||||
version: String,
|
version: String,
|
||||||
}
|
}
|
||||||
@@ -497,6 +504,11 @@ impl CommandHandler<'_> {
|
|||||||
impl From<PeerRoutePair> for PeerTableItem {
|
impl From<PeerRoutePair> for PeerTableItem {
|
||||||
fn from(p: PeerRoutePair) -> Self {
|
fn from(p: PeerRoutePair) -> Self {
|
||||||
let route = p.route.clone().unwrap_or_default();
|
let route = p.route.clone().unwrap_or_default();
|
||||||
|
let lat_ms = if route.cost == 1 {
|
||||||
|
p.get_latency_ms().unwrap_or(0.0)
|
||||||
|
} else {
|
||||||
|
route.path_latency_latency_first() as f64
|
||||||
|
};
|
||||||
PeerTableItem {
|
PeerTableItem {
|
||||||
cidr: route.ipv4_addr.map(|ip| ip.to_string()).unwrap_or_default(),
|
cidr: route.ipv4_addr.map(|ip| ip.to_string()).unwrap_or_default(),
|
||||||
ipv4: route
|
ipv4: route
|
||||||
@@ -506,12 +518,8 @@ impl CommandHandler<'_> {
|
|||||||
.unwrap_or_default(),
|
.unwrap_or_default(),
|
||||||
hostname: route.hostname.clone(),
|
hostname: route.hostname.clone(),
|
||||||
cost: cost_to_str(route.cost),
|
cost: cost_to_str(route.cost),
|
||||||
lat_ms: if route.cost == 1 {
|
lat_ms: format!("{:.2}", lat_ms),
|
||||||
float_to_str(p.get_latency_ms().unwrap_or(0.0), 3)
|
loss_rate: format!("{:.1}%", p.get_loss_rate().unwrap_or(0.0) * 100.0),
|
||||||
} else {
|
|
||||||
route.path_latency_latency_first().to_string()
|
|
||||||
},
|
|
||||||
loss_rate: float_to_str(p.get_loss_rate().unwrap_or(0.0), 3),
|
|
||||||
rx_bytes: format_size(p.get_rx_bytes().unwrap_or(0), humansize::DECIMAL),
|
rx_bytes: format_size(p.get_rx_bytes().unwrap_or(0), humansize::DECIMAL),
|
||||||
tx_bytes: format_size(p.get_tx_bytes().unwrap_or(0), humansize::DECIMAL),
|
tx_bytes: format_size(p.get_tx_bytes().unwrap_or(0), humansize::DECIMAL),
|
||||||
tunnel_proto: p
|
tunnel_proto: p
|
||||||
@@ -1460,7 +1468,7 @@ where
|
|||||||
{
|
{
|
||||||
match format {
|
match format {
|
||||||
OutputFormat::Table => {
|
OutputFormat::Table => {
|
||||||
println!("{}", tabled::Table::new(items).with(Style::modern()));
|
println!("{}", tabled::Table::new(items).with(Style::markdown()));
|
||||||
}
|
}
|
||||||
OutputFormat::Json => {
|
OutputFormat::Json => {
|
||||||
println!("{}", serde_json::to_string_pretty(items)?);
|
println!("{}", serde_json::to_string_pretty(items)?);
|
||||||
@@ -1752,7 +1760,7 @@ async fn main() -> Result<(), Error> {
|
|||||||
builder.push_record(vec![format!("Listener {}", idx).as_str(), l]);
|
builder.push_record(vec![format!("Listener {}", idx).as_str(), l]);
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("{}", builder.build().with(Style::modern()));
|
println!("{}", builder.build().with(Style::markdown()));
|
||||||
}
|
}
|
||||||
Some(NodeSubCommand::Config) => {
|
Some(NodeSubCommand::Config) => {
|
||||||
println!("{}", node_info.config);
|
println!("{}", node_info.config);
|
||||||
|
|||||||
Reference in New Issue
Block a user