traffic_core: продакшн-фиксы runtime и валидации
This commit is contained in:
@@ -24,6 +24,11 @@ pub fn print_status(cfg: &Config) -> anyhow::Result<()> {
|
||||
Ok(t) => t,
|
||||
Err(e) => {
|
||||
println!(" container: not available ({e})");
|
||||
println!(" container_id: n/a");
|
||||
println!(" pid: n/a");
|
||||
println!(" netns: n/a");
|
||||
println!(" interface: n/a");
|
||||
print_degraded_sections(cfg)?;
|
||||
return Ok(());
|
||||
}
|
||||
};
|
||||
@@ -215,9 +220,112 @@ pub fn print_status(cfg: &Config) -> anyhow::Result<()> {
|
||||
}
|
||||
}
|
||||
|
||||
print_reboot_section();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn print_degraded_sections(cfg: &Config) -> anyhow::Result<()> {
|
||||
println!("Peers:");
|
||||
println!(" unavailable (container/netns not discovered)");
|
||||
|
||||
println!("WireGuard clients:");
|
||||
println!(" unavailable (container/netns not discovered)");
|
||||
|
||||
println!("Traffic desired:");
|
||||
println!(" peer_limit: {}", cfg.traffic.peer_limit);
|
||||
println!(" root_rate: {}", cfg.traffic.root_rate);
|
||||
println!(" ifb_name: {}", cfg.traffic.ifb_name);
|
||||
println!(" class_start_id: {}", cfg.traffic.class_start_id);
|
||||
|
||||
println!("Traffic actual:");
|
||||
println!(" drift: unknown (container/netns not discovered)");
|
||||
|
||||
println!("Anti-torrent:");
|
||||
println!(" enabled: {}", cfg.anti_torrent.enabled);
|
||||
println!(
|
||||
" max_connections_per_peer: {}",
|
||||
cfg.anti_torrent.max_connections_per_peer
|
||||
);
|
||||
if cfg.anti_torrent.enabled {
|
||||
match firewall::antitorrent_drop_counter(cfg) {
|
||||
Ok(Some((packets, bytes))) => {
|
||||
println!(" dropped_packets: {}", packets);
|
||||
println!(" dropped_bytes: {}", bytes);
|
||||
}
|
||||
Ok(None) => println!(" dropped_packets: n/a"),
|
||||
Err(e) => println!(" dropped_packets: inspect error ({e})"),
|
||||
}
|
||||
}
|
||||
|
||||
println!("Swap:");
|
||||
println!(" enabled: {}", cfg.swap.enabled);
|
||||
println!(" path: {}", cfg.swap.path);
|
||||
println!(" size_mb: {}", cfg.swap.size_mb);
|
||||
println!(" priority: {}", cfg.swap.priority);
|
||||
|
||||
println!("Conntrack:");
|
||||
let ct_count = Command::new("sysctl")
|
||||
.args(["-n", "net.netfilter.nf_conntrack_count"])
|
||||
.output()
|
||||
.ok()
|
||||
.map(|o| String::from_utf8_lossy(&o.stdout).trim().to_string())
|
||||
.unwrap_or_else(|| "n/a".to_string());
|
||||
let ct_max = Command::new("sysctl")
|
||||
.args(["-n", "net.netfilter.nf_conntrack_max"])
|
||||
.output()
|
||||
.ok()
|
||||
.map(|o| String::from_utf8_lossy(&o.stdout).trim().to_string())
|
||||
.unwrap_or_else(|| "n/a".to_string());
|
||||
println!(" nf_conntrack_count: {}", ct_count);
|
||||
println!(" nf_conntrack_max: {}", ct_max);
|
||||
|
||||
println!("Last actions:");
|
||||
let last = fs::read_to_string("/run/awg2-harness/last_action.state").unwrap_or_default();
|
||||
if last.trim().is_empty() {
|
||||
println!(" no persisted state");
|
||||
} else {
|
||||
for line in last.lines() {
|
||||
println!(" {}", line);
|
||||
}
|
||||
}
|
||||
|
||||
println!("Recent events:");
|
||||
let events = fs::read_to_string("/run/awg2-harness/events.log").unwrap_or_default();
|
||||
let lines: Vec<&str> = events.lines().collect();
|
||||
if lines.is_empty() {
|
||||
println!(" no recent events");
|
||||
} else {
|
||||
for l in lines.iter().rev().take(10).rev() {
|
||||
println!(" {l}");
|
||||
}
|
||||
}
|
||||
|
||||
print_reboot_section();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn print_reboot_section() {
|
||||
println!("Reboot scheduler:");
|
||||
let svc = Command::new("systemctl")
|
||||
.args(["is-active", "awg2-reboot-scheduler"])
|
||||
.output();
|
||||
match svc {
|
||||
Ok(out) if out.status.success() => println!(" service: active"),
|
||||
Ok(_) => println!(" service: inactive"),
|
||||
Err(_) => println!(" service: unknown"),
|
||||
}
|
||||
|
||||
let plan = fs::read_to_string("/run/awg2-harness/reboot.plan").unwrap_or_default();
|
||||
if plan.trim().is_empty() {
|
||||
println!(" planned: n/a");
|
||||
} else {
|
||||
for line in plan.lines() {
|
||||
println!(" {}", line);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn handshake_is_online(epoch: Option<u64>, threshold_secs: u64) -> &'static str {
|
||||
if let Some(ts) = epoch {
|
||||
let now = SystemTime::now()
|
||||
|
||||
Reference in New Issue
Block a user