Compare commits

..
2 Commits
Author SHA1 Message Date
irrlichtandClaude Opus 5.5 599a048015 fix: nur physische Netzwerk-Interfaces zählen
Virtuelle Interfaces (Bridges, veth, Docker, VPN-Tunnel) führen denselben
Traffic wie die physische Karte und wurden bisher doppelt gezählt. Gezählt
werden jetzt nur Interfaces mit /sys/class/net/<iface>/device; Loopback
fällt damit ebenfalls raus.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 21:33:19 +01:00
irrlichtandClaude Opus 5.5 f6543eb228 feat: Netzwerk-Traffic in Mbit/s anzeigen
Dezimale Megabit pro Sekunde statt KiB/s, damit sich die Anzeige direkt
mit der Bandbreite des Internetanschlusses vergleichen lässt.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 21:33:19 +01:00
+13 -8
View File
@@ -81,7 +81,8 @@ fn query_cpu_temp() -> String {
} }
} }
// Sums rx/tx byte counters across all interfaces except loopback. // Sums rx/tx byte counters across physical interfaces only. Virtual ones
// (loopback, bridges, veth, VPN tunnels) would count the same traffic twice.
fn read_net_bytes() -> (u64, u64) { fn read_net_bytes() -> (u64, u64) {
let mut down = 0u64; let mut down = 0u64;
let mut up = 0u64; let mut up = 0u64;
@@ -96,7 +97,8 @@ fn read_net_bytes() -> (u64, u64) {
let Some((iface, rest)) = line.split_once(':') else { let Some((iface, rest)) = line.split_once(':') else {
continue; continue;
}; };
if iface.trim() == "lo" { // Only physical interfaces have a backing device in sysfs.
if !Path::new("/sys/class/net").join(iface.trim()).join("device").exists() {
continue; continue;
} }
let fields: Vec<&str> = rest.split_whitespace().collect(); let fields: Vec<&str> = rest.split_whitespace().collect();
@@ -110,10 +112,13 @@ fn read_net_bytes() -> (u64, u64) {
(down, up) (down, up)
} }
// Fixed-width, fixed-unit (KiB/s) formatting so the bar doesn't change size // Fixed-width, fixed-unit (Mbit/s, decimal like ISP rates) formatting so the
// as traffic fluctuates. // bar doesn't change size as traffic fluctuates.
fn format_net(down_rate: u64, up_rate: u64) -> String { fn format_net(down_bytes_per_sec: u64, up_bytes_per_sec: u64) -> String {
format!("net:↓{down_rate:>5} ↑{up_rate:>5} KiB/s") let to_mbps = |b: u64| b as f64 * 8.0 / 1_000_000.0;
let down = to_mbps(down_bytes_per_sec);
let up = to_mbps(up_bytes_per_sec);
format!("net:↓{down:>5.1} ↑{up:>5.1} Mbit/s")
} }
fn main() { fn main() {
@@ -157,8 +162,8 @@ fn main() {
loop { loop {
std::thread::sleep(INTERVAL); std::thread::sleep(INTERVAL);
let (down, up) = read_net_bytes(); let (down, up) = read_net_bytes();
let down_rate = down.saturating_sub(prev_down) / INTERVAL.as_secs() / 1024; let down_rate = down.saturating_sub(prev_down) / INTERVAL.as_secs();
let up_rate = up.saturating_sub(prev_up) / INTERVAL.as_secs() / 1024; let up_rate = up.saturating_sub(prev_up) / INTERVAL.as_secs();
tx.send(Update::Net(format_net(down_rate, up_rate))).unwrap(); tx.send(Update::Net(format_net(down_rate, up_rate))).unwrap();
prev_down = down; prev_down = down;
prev_up = up; prev_up = up;