2022-04-10 18:44:34 +03:00
use anyhow ::Error ;
2019-05-16 11:24:23 +03:00
2022-04-21 16:04:59 +03:00
use pbs_api_types ::{ Authid , BackupNamespace , BackupType } ;
2022-04-10 18:44:34 +03:00
use pbs_client ::{ BackupWriter , HttpClient , HttpClientOptions } ;
2019-05-16 11:24:23 +03:00
2020-07-17 16:39:17 +03:00
async fn upload_speed ( ) -> Result < f64 , Error > {
2019-05-16 11:24:23 +03:00
let host = " localhost " ;
let datastore = " store2 " ;
2020-10-08 16:19:39 +03:00
let auth_id = Authid ::root_auth_id ( ) ;
2019-05-16 11:24:23 +03:00
2021-01-25 16:42:57 +03:00
let options = HttpClientOptions ::default ( )
2020-01-25 14:18:00 +03:00
. interactive ( true )
. ticket_cache ( true ) ;
2020-10-08 16:19:39 +03:00
let client = HttpClient ::new ( host , 8007 , auth_id , options ) ? ;
2019-05-16 11:24:23 +03:00
2021-10-08 12:19:37 +03:00
let backup_time = proxmox_time ::epoch_i64 ( ) ;
2019-07-25 14:44:01 +03:00
2022-04-10 18:44:34 +03:00
let client = BackupWriter ::start (
2024-03-28 15:36:25 +03:00
& client ,
2022-04-10 18:44:34 +03:00
None ,
datastore ,
2022-05-09 16:39:29 +03:00
& BackupNamespace ::root ( ) ,
& ( BackupType ::Host , " speedtest " . to_string ( ) , backup_time ) . into ( ) ,
2022-04-10 18:44:34 +03:00
false ,
true ,
)
. await ? ;
2019-05-16 11:24:23 +03:00
2019-05-23 08:20:05 +03:00
println! ( " start upload speed test " ) ;
2022-06-15 11:19:55 +03:00
let res = client . upload_speedtest ( ) . await ? ;
2019-05-16 11:24:23 +03:00
Ok ( res )
}
2022-04-10 18:44:34 +03:00
fn main ( ) {
2021-11-19 19:36:06 +03:00
match proxmox_async ::runtime ::main ( upload_speed ( ) ) {
2019-08-29 10:58:20 +03:00
Ok ( mbs ) = > {
println! ( " average upload speed: {} MB/s " , mbs ) ;
}
Err ( err ) = > {
eprintln! ( " ERROR: {} " , err ) ;
2019-05-16 11:24:23 +03:00
}
2019-08-29 10:58:20 +03:00
}
2019-05-16 11:24:23 +03:00
}