Completed the network bandwidth test function using iperf3; adjusted Cargo.toml a bit to allow patch updates for dependencies
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
parent
7b7150886a
commit
d4d3e37e8d
@ -12,9 +12,9 @@ name = "bgbench"
|
||||
path = "src/main.rs"
|
||||
|
||||
[dependencies]
|
||||
chrono = "0.4.20"
|
||||
clap = { version = "3.2.16", features = ["derive"] }
|
||||
sysinfo = "0.25.1"
|
||||
chrono = "0.4"
|
||||
clap = { version = "3.2", features = ["derive"] }
|
||||
sysinfo = "0.25"
|
||||
|
||||
[package.metadata.deb]
|
||||
depends = "fio"
|
||||
|
@ -1,5 +1,4 @@
|
||||
use chrono::prelude::*;
|
||||
use std::{fs,process};
|
||||
use std::process;
|
||||
|
||||
use crate::text;
|
||||
|
||||
@ -60,23 +59,20 @@ pub fn jitter_test(address: &str, count: &u16) {
|
||||
}
|
||||
|
||||
// timed file copy test to guage bandwidth speeds
|
||||
pub fn bandwidth_test(download: &str, output: &str) {
|
||||
println!("Testing network bandwidth by downloading {}.", download);
|
||||
pub fn bandwidth_test(host: &str) {
|
||||
println!("Testing network bandwidth using iperf; connecting to {}.", host);
|
||||
println!("{}", host);
|
||||
|
||||
// get start time so we can track how long it takes to complete
|
||||
let start_time = Utc::now();
|
||||
let output = process::Command::new("iperf3")
|
||||
.arg("-c")
|
||||
.arg(host)
|
||||
.output()
|
||||
.expect("Failed to execute command");
|
||||
|
||||
// do the download
|
||||
// check that the command succeeded
|
||||
assert!(output.status.success());
|
||||
|
||||
// get finish time
|
||||
let finish_time = Utc::now();
|
||||
// compute time to complete
|
||||
let comp_time = finish_time - start_time;
|
||||
println!("{}", comp_time.num_milliseconds());
|
||||
|
||||
// clean up the test file
|
||||
match fs::remove_file(output) {
|
||||
Ok(()) => println!("Cleaning up..."),
|
||||
Err(e) => println!("There was a problem during cleanup - {}", e),
|
||||
}
|
||||
// grab and print the command's results
|
||||
let results_raw = &String::from_utf8_lossy(&output.stdout);
|
||||
println!("{}", results_raw);
|
||||
}
|
||||
|
12
src/main.rs
12
src/main.rs
@ -142,12 +142,10 @@ enum NetCommands {
|
||||
},
|
||||
|
||||
// bandwidth test subcommand
|
||||
#[clap(name = "bandwidth", about = "Downloads a remote file to determine network bandwidth.")]
|
||||
#[clap(name = "bandwidth", about = "Uses iperf to test network bandwidth.")]
|
||||
Bandwidth {
|
||||
#[clap(short = 'd', long, default_value_t = String::from("https://www.bitgoblin.tech/hardware-tests/export-01.mp4"))]
|
||||
download: String,
|
||||
#[clap(short = 't', long, default_value_t = String::from("/tmp/bw-test.tmp"))]
|
||||
output: String,
|
||||
#[clap(short = 'a', long, required = true)]
|
||||
host: String,
|
||||
},
|
||||
}
|
||||
|
||||
@ -206,10 +204,10 @@ fn main() {
|
||||
benchmarks::network::jitter_test(address, count);
|
||||
}
|
||||
},
|
||||
NetCommands::Bandwidth { download, output } => {
|
||||
NetCommands::Bandwidth { host } => {
|
||||
for i in 0..cli.iterations {
|
||||
println!("Test run number {}.", i + 1);
|
||||
benchmarks::network::bandwidth_test(download, output);
|
||||
benchmarks::network::bandwidth_test(host);
|
||||
}
|
||||
},
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user