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"
|
path = "src/main.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
chrono = "0.4.20"
|
chrono = "0.4"
|
||||||
clap = { version = "3.2.16", features = ["derive"] }
|
clap = { version = "3.2", features = ["derive"] }
|
||||||
sysinfo = "0.25.1"
|
sysinfo = "0.25"
|
||||||
|
|
||||||
[package.metadata.deb]
|
[package.metadata.deb]
|
||||||
depends = "fio"
|
depends = "fio"
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
use chrono::prelude::*;
|
use std::process;
|
||||||
use std::{fs,process};
|
|
||||||
|
|
||||||
use crate::text;
|
use crate::text;
|
||||||
|
|
||||||
@ -60,23 +59,20 @@ pub fn jitter_test(address: &str, count: &u16) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// timed file copy test to guage bandwidth speeds
|
// timed file copy test to guage bandwidth speeds
|
||||||
pub fn bandwidth_test(download: &str, output: &str) {
|
pub fn bandwidth_test(host: &str) {
|
||||||
println!("Testing network bandwidth by downloading {}.", download);
|
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 output = process::Command::new("iperf3")
|
||||||
let start_time = Utc::now();
|
.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
|
// grab and print the command's results
|
||||||
let finish_time = Utc::now();
|
let results_raw = &String::from_utf8_lossy(&output.stdout);
|
||||||
// compute time to complete
|
println!("{}", results_raw);
|
||||||
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),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
12
src/main.rs
12
src/main.rs
@ -142,12 +142,10 @@ enum NetCommands {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// bandwidth test subcommand
|
// 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 {
|
Bandwidth {
|
||||||
#[clap(short = 'd', long, default_value_t = String::from("https://www.bitgoblin.tech/hardware-tests/export-01.mp4"))]
|
#[clap(short = 'a', long, required = true)]
|
||||||
download: String,
|
host: String,
|
||||||
#[clap(short = 't', long, default_value_t = String::from("/tmp/bw-test.tmp"))]
|
|
||||||
output: String,
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -206,10 +204,10 @@ fn main() {
|
|||||||
benchmarks::network::jitter_test(address, count);
|
benchmarks::network::jitter_test(address, count);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
NetCommands::Bandwidth { download, output } => {
|
NetCommands::Bandwidth { host } => {
|
||||||
for i in 0..cli.iterations {
|
for i in 0..cli.iterations {
|
||||||
println!("Test run number {}.", i + 1);
|
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