generated from PlexSheep/baserepo
Compare commits
No commits in common. "f4c02b3042ada2257fb40b3790af7502ba6f1fe4" and "9b372bf1e3020359017b2d6e9b003eadb96c53ab" have entirely different histories.
f4c02b3042
...
9b372bf1e3
3 changed files with 14 additions and 23 deletions
|
@ -28,7 +28,6 @@ pub mod args;
|
||||||
use args::*;
|
use args::*;
|
||||||
|
|
||||||
//// CONSTANTS /////////////////////////////////////////////////////////////////////////////////////
|
//// CONSTANTS /////////////////////////////////////////////////////////////////////////////////////
|
||||||
#[allow(dead_code)]
|
|
||||||
const EXIT_SUCCESS: i32 = 0;
|
const EXIT_SUCCESS: i32 = 0;
|
||||||
const EXIT_FAILURE_USAGE: i32 = 1;
|
const EXIT_FAILURE_USAGE: i32 = 1;
|
||||||
|
|
||||||
|
|
|
@ -109,15 +109,9 @@ impl Logger {
|
||||||
} else {
|
} else {
|
||||||
let filter = tracing_subscriber::filter::FilterFn::new(|metadata| {
|
let filter = tracing_subscriber::filter::FilterFn::new(|metadata| {
|
||||||
let mut filter = false;
|
let mut filter = false;
|
||||||
|
|
||||||
// if it's this lib, continue
|
|
||||||
filter |= metadata.target().contains(env!("CARGO_PKG_NAME"));
|
filter |= metadata.target().contains(env!("CARGO_PKG_NAME"));
|
||||||
filter |= metadata.target().contains("pt");
|
filter |= metadata.target().contains("pt");
|
||||||
|
|
||||||
// if it's another crate, only show above debug
|
|
||||||
// FIXME, this is not the behaviour I want for a real release
|
|
||||||
filter |= metadata.level() > &Level::DEBUG;
|
|
||||||
|
|
||||||
filter
|
filter
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,9 @@
|
||||||
use std::{fmt, time::Duration};
|
use std::{fmt, time::Duration};
|
||||||
|
|
||||||
//// IMPORTS ///////////////////////////////////////////////////////////////////////////////////////
|
//// IMPORTS ///////////////////////////////////////////////////////////////////////////////////////
|
||||||
use crate::logger::*;
|
// we want the log macros in any case
|
||||||
|
#[allow(unused_imports)]
|
||||||
|
use tracing;
|
||||||
|
|
||||||
use reqwest;
|
use reqwest;
|
||||||
|
|
||||||
|
@ -140,10 +142,10 @@ impl UptimeStatus {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let ratio: f32 = (self.reachable as f32) / (self.urls.len() as f32) * 100f32;
|
let ratio: f32 = (self.reachable as f32) / (self.urls.len() as f32) * 100f32;
|
||||||
trace!("calculated success_ratio: {}", ratio);
|
tracing::trace!("calculated success_ratio: {}", ratio);
|
||||||
self.success_ratio = ratio.floor() as u8;
|
self.success_ratio = ratio.floor() as u8;
|
||||||
self.success = self.success_ratio >= self.success_ratio_target;
|
self.success = self.success_ratio >= self.success_ratio_target;
|
||||||
trace!("calculated success as: {}", self.success)
|
tracing::trace!("calculated success as: {}", self.success)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -216,7 +218,7 @@ pub fn continuous_uptime_monitor(
|
||||||
timeout: u64,
|
timeout: u64,
|
||||||
) {
|
) {
|
||||||
if urls.len() == 0 {
|
if urls.len() == 0 {
|
||||||
error!("No URLs provided. There is nothing to monitor.");
|
tracing::error!("No URLs provided. There is nothing to monitor.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -224,15 +226,11 @@ pub fn continuous_uptime_monitor(
|
||||||
let mut last_downtime: Option<SystemTime> = None;
|
let mut last_downtime: Option<SystemTime> = None;
|
||||||
let mut last_uptime: Option<SystemTime> = None;
|
let mut last_uptime: Option<SystemTime> = None;
|
||||||
let mut status = UptimeStatus::new(success_ratio_target, urls, timeout);
|
let mut status = UptimeStatus::new(success_ratio_target, urls, timeout);
|
||||||
// we assume that the last status was up, so the binary shows the first status if its a
|
let mut last_was_up: bool = false;
|
||||||
// failure.
|
|
||||||
let mut last_was_up: bool = true;
|
|
||||||
let mut last_ratio: u8 = status.success_ratio;
|
let mut last_ratio: u8 = status.success_ratio;
|
||||||
loop {
|
loop {
|
||||||
trace!(?status, ?last_was_up, "loop iteration for continuous uptime monitor");
|
|
||||||
if !status.success {
|
if !status.success {
|
||||||
if last_was_up {
|
if last_was_up {
|
||||||
trace!("displaying status");
|
|
||||||
display_uptime_status("fail", last_uptime, last_downtime, &status)
|
display_uptime_status("fail", last_uptime, last_downtime, &status)
|
||||||
}
|
}
|
||||||
last_downtime = Some(SystemTime::now());
|
last_downtime = Some(SystemTime::now());
|
||||||
|
@ -295,19 +293,19 @@ fn display_uptime_status(
|
||||||
) {
|
) {
|
||||||
// I know it's weird that this has two spaces too much, but somehow just the tabs is missing
|
// I know it's weird that this has two spaces too much, but somehow just the tabs is missing
|
||||||
// two spaces.
|
// two spaces.
|
||||||
info!("uptime check: {}", msg);
|
tracing::info!("uptime check: {}", msg);
|
||||||
info!("last uptime: {}", match_format_time(last_uptime));
|
tracing::info!("last uptime: {}", match_format_time(last_uptime));
|
||||||
info!("last downtime: {}", match_format_time(last_downtime));
|
tracing::info!("last downtime: {}", match_format_time(last_downtime));
|
||||||
info!(
|
tracing::info!(
|
||||||
"since downtime: {}",
|
"since downtime: {}",
|
||||||
match_format_duration_since(last_downtime)
|
match_format_duration_since(last_downtime)
|
||||||
);
|
);
|
||||||
info!(
|
tracing::info!(
|
||||||
"since uptime: {}",
|
"since uptime: {}",
|
||||||
match_format_duration_since(last_uptime)
|
match_format_duration_since(last_uptime)
|
||||||
);
|
);
|
||||||
debug!("\n{}", status);
|
tracing::debug!("\n{}", status);
|
||||||
info!("{}", divider!());
|
tracing::info!("{}", divider!());
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
Reference in a new issue