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:
@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user