46 lines
1.1 KiB
Rust
46 lines
1.1 KiB
Rust
mod cfg;
|
|
mod macros;
|
|
mod math;
|
|
mod measure;
|
|
mod sysfs;
|
|
|
|
use std::{env, thread::sleep};
|
|
|
|
use sysfs::NetdevError;
|
|
|
|
use crate::{cfg::Config, measure::LinkSpeed};
|
|
|
|
fn main() -> eyre::Result<()> {
|
|
let config = Config::from_file()?;
|
|
|
|
let arg_netdev = env::args().nth(1);
|
|
|
|
// prefer given argument over the config file
|
|
#[allow(clippy::match_same_arms)]
|
|
let netdev_name = match (config.netdev, arg_netdev) {
|
|
(Some(_), Some(na)) => na,
|
|
(Some(nc), None) => nc,
|
|
(None, Some(na)) => na,
|
|
(None, None) => {
|
|
eyre::bail!(
|
|
"No network device specified. Please provide a network device name as an argument or in the config file.\n\n{}",
|
|
NetdevError::available_netdevs_msg()
|
|
);
|
|
}
|
|
};
|
|
|
|
let link_speed = LinkSpeed::new(&netdev_name)?;
|
|
|
|
link_speed.for_each(|measurement| {
|
|
println!(
|
|
"RX: {:.0} MBit/s, TX: {:.0} MBit/s",
|
|
mbit!(measurement.rx),
|
|
mbit!(measurement.tx)
|
|
);
|
|
|
|
sleep(config.interval);
|
|
});
|
|
|
|
Ok(())
|
|
}
|