- if time::Instant::now() - time_last_state_printed >= STATE_PRINT_PERIOD {
- println!("No error detected");
- time_last_state_printed = time::Instant::now();
+ if time::Instant::now() - time_last_state_printed >= STATE_PRINT_PERIOD {
+ println!(
+ "No error detected. Mean of ping time: {} μs",
+ total_ping_duration.as_micros() / number_of_pings
+ );
+ total_ping_duration = Duration::default();
+ number_of_pings = 0;
+ time_last_state_printed = time::Instant::now();
+ }
+ }
+ Err(error) => {
+ error_state = true;
+ println!("Error: {:?}", error);
+ if time::Instant::now() - time_last_email_send >= EMAIL_RESEND_PERIOD {
+ // Send e-mail.
+ println!("Sending email...");
+ match send_email(
+ "Watchdog ERROR",
+ &format!("Error: {:?}", error),
+ &config.smtp_login,
+ &config.smtp_password,
+ ) {
+ Err(email_error) => println!("Error sending email: {:?}", email_error),
+ _ => {
+ println!("Email successfully sent");
+ time_last_email_send = time::Instant::now();
+ }
+ }
+ }