Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Commit

Permalink
Report duration of last alarm in the All Clear message (#9766) (#9771)
Browse files Browse the repository at this point in the history
automerge

(cherry picked from commit 6e42989)

Co-authored-by: Michael Vines <mvines@gmail.com>
  • Loading branch information
mergify[bot] and mvines authored Apr 28, 2020
1 parent 109bfc3 commit 1f6a7c1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions watchtower/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ homepage = "https://solana.com/"
[dependencies]
clap = "2.33.0"
log = "0.4.8"
humantime = "2.0.0"
reqwest = { version = "0.10.4", default-features = false, features = ["blocking", "rustls-tls", "json"] }
serde_json = "1.0"
solana-clap-utils = { path = "../clap-utils", version = "1.1.8" }
Expand Down
20 changes: 17 additions & 3 deletions watchtower/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ use solana_client::{
};
use solana_metrics::{datapoint_error, datapoint_info};
use solana_sdk::{hash::Hash, native_token::lamports_to_sol, pubkey::Pubkey};
use std::{error, str::FromStr, thread::sleep, time::Duration};
use std::{
error,
str::FromStr,
thread::sleep,
time::{Duration, Instant},
};

struct Config {
interval: Duration,
Expand Down Expand Up @@ -136,6 +141,7 @@ fn main() -> Result<(), Box<dyn error::Error>> {
let mut last_transaction_count = 0;
let mut last_recent_blockhash = Hash::default();
let mut last_notification_msg = "".into();
let mut last_success = Instant::now();

loop {
let failure = match get_cluster_info(&rpc_client) {
Expand Down Expand Up @@ -269,10 +275,18 @@ fn main() -> Result<(), Box<dyn error::Error>> {
last_notification_msg = notification_msg;
} else {
if !last_notification_msg.is_empty() {
info!("All clear");
notifier.send("solana-watchtower: All clear");
let alarm_duration = Instant::now().duration_since(last_success);
let alarm_duration = Duration::from_secs(alarm_duration.as_secs()); // Drop milliseconds in message

let all_clear_msg = format!(
"All clear after {}",
humantime::format_duration(alarm_duration)
);
info!("{}", all_clear_msg);
notifier.send(&format!("solana-watchtower: {}", all_clear_msg));
}
last_notification_msg = "".into();
last_success = Instant::now();
}
sleep(config.interval);
}
Expand Down

0 comments on commit 1f6a7c1

Please sign in to comment.