pub fn measure_latency(pinger: tokio_ping::Pinger, config: structs::Config) {
    if config.endpoints.is_empty() {
        // Skip to the tcp monitoring threads if ICMP targets is empty
        measure_tcp_latency(config);
    } else {
        // Iterate over the ICMP targets
        for endp in config.endpoints.iter() {
            let ip_lookup = resolve_host(endp);
            let ip_v4 = ip_lookup.unwrap();
            let endpoint_name = endp.to_string().clone();
            let config_copy = config.clone();
            let ping: tokio_ping::PingFuture = pinger.chain(ip_v4).send();
            tokio::spawn(
                ping.and_then(move |resp| {
                    if let Some(delay) = resp {
                        println!(
                            "ICMP Target: {:?} Latency: {:?}ms",
                            endpoint_name,
                            delay.as_millis(),
                        );
                        tsdb::write_tsdb(&config_copy, endpoint_name, PROTO_ICMP, delay);
                    }
                    Ok(())
                })
                .map_err(|e| {
                    eprintln!("{:?}", e);
                }),
            );
        }
        // Call the tcp monitoring threads
        measure_tcp_latency(config);
    }
}
// spawn the threads for the async pings for each endpoint
spawn the threads for the async pings for each endpoint
spawn the threads for the async pings for each endpoint
pub fn measure_latency(pinger: tokio_ping::Pinger, config: structs::Config) {
    if config.endpoints.is_empty() {
        // Skip to the tcp monitoring threads if ICMP targets is empty
        measure_tcp_latency(config);
    } else {
        // Iterate over the ICMP targets
        for endp in config.endpoints.iter() {
            let ip_lookup = resolve_host(endp);
            let ip_v4 = ip_lookup.unwrap();
            let endpoint_name = endp.to_string().clone();
            let config_copy = config.clone();
            let ping: tokio_ping::PingFuture = pinger.chain(ip_v4).send();
            tokio::spawn(
                ping.and_then(move |resp| {
                    if let Some(delay) = resp {
                        println!(
                            "ICMP Target: {:?} Latency: {:?}ms",
                            endpoint_name,
                            delay.as_millis(),
                        );
                        tsdb::write_tsdb(&config_copy, endpoint_name, PROTO_ICMP, delay);
                    }
                    Ok(())
                })
                .map_err(|e| {
                    eprintln!("{:?}", e);
                }),
            );
        }
        // Call the tcp monitoring threads
        measure_tcp_latency(config);
    }
}
pub fn measure_latency ( pinger : tokio_ping :: Pinger , config : structs :: Config ) { if config . endpoints . is_empty ( ) { // Skip to the tcp monitoring threads if ICMP targets is empty measure_tcp_latency ( config ) ; } else { // Iterate over the ICMP targets for endp in config . endpoints . iter ( ) { let ip_lookup = resolve_host ( endp ) ; let ip_v4 = ip_lookup . unwrap ( ) ; let endpoint_name = endp . to_string ( ) . clone ( ) ; let config_copy = config . clone ( ) ; let ping : tokio_ping :: PingFuture = pinger . chain ( ip_v4 ) . send ( ) ; tokio :: spawn ( ping . and_then ( move | resp | { if let Some ( delay ) = resp { println ! ( " " endpoint_name delay as_millis ( ) ) ; tsdb :: write_tsdb ( & config_copy , endpoint_name , PROTO_ICMP , delay ) ; } Ok ( ( ) ) } ) . map_err ( | e | { eprintln ! ( " " e ) ; } ) , ) ; } // Call the tcp monitoring threads measure_tcp_latency ( config ) ; } }
spawn the threads for the async pings for each endpoint
spawn the threads for the async pings for each endpoint
pinger
tokio_ping::Pinger
config
structs::Config
pinger
tokio_ping::Pinger
config
structs::Config