feat: add timestamp to console ouput XvB

fix: move code for output on console to a single function.
This commit is contained in:
Louis-Marie Baer 2024-03-19 15:31:13 +01:00
parent a120a8a2b7
commit 2f4816cd27
4 changed files with 118 additions and 165 deletions

5
Cargo.lock generated
View file

@ -901,9 +901,9 @@ dependencies = [
[[package]] [[package]]
name = "chrono" name = "chrono"
version = "0.4.34" version = "0.4.35"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5bc015644b92d5890fab7489e49d21f879d5c990186827d42ec511919404f38b" checksum = "8eaf5903dcbc0a39312feb77df2ff4c76387d591b9fc7b04a238dcf8bb62639a"
dependencies = [ dependencies = [
"android-tzdata", "android-tzdata",
"iana-time-zone", "iana-time-zone",
@ -2373,6 +2373,7 @@ dependencies = [
"arti-hyper", "arti-hyper",
"benri", "benri",
"bytes", "bytes",
"chrono",
"derive_more", "derive_more",
"dirs", "dirs",
"eframe", "eframe",

View file

@ -77,6 +77,7 @@ strip-ansi-escapes = "0.2.0"
derive_more = {version="0.99.17", default-features=false, features=["display"]} derive_more = {version="0.99.17", default-features=false, features=["display"]}
serde-this-or-that = "0.4.2" serde-this-or-that = "0.4.2"
readable = "0.16" readable = "0.16"
chrono = {version="0.4.35", default-features=false, features=["clock", "std"]}
# Unix dependencies # Unix dependencies
[target.'cfg(unix)'.dependencies] [target.'cfg(unix)'.dependencies]
tar = "0.4.40" tar = "0.4.40"

View file

@ -16,6 +16,7 @@
- [x] state of XvB process - [x] state of XvB process
- [x] selected XvB node - [x] selected XvB node
- [x] algorithm decisions info - [x] algorithm decisions info
- [x] timestamp
- [x] private stats - [x] private stats
- [x] from XvB API (fails, average 1h and 24h) - [x] from XvB API (fails, average 1h and 24h)
- [x] round type in - [x] round type in

View file

@ -146,28 +146,17 @@ impl Helper {
{ {
// send to console: token non existent for address on XvB server // send to console: token non existent for address on XvB server
warn!("Xvb | Start ... Partially failed because token and associated address are not existent on XvB server: {}\n", err); warn!("Xvb | Start ... Partially failed because token and associated address are not existent on XvB server: {}\n", err);
// output the error to console output_console(&gui_api, &format!("Token and associated address are not valid on XvB API.\nCheck if you are registered.\nError: {}", err));
if let Err(e) = writeln!(
lock!(gui_api).output,
"Token and associated address are not valid on XvB API.\nCheck if you are registered.\nError: {}\n",
err,
) {
error!("XvB Watchdog | GUI status write failed: {}", e);
}
lock!(process).state = ProcessState::NotMining; lock!(process).state = ProcessState::NotMining;
} }
info!("XvB | verify p2pool node"); info!("XvB | verify p2pool node");
if !lock!(process_p2pool).is_alive() { if !lock!(process_p2pool).is_alive() {
// send to console: p2pool process is not running // send to console: p2pool process is not running
warn!("Xvb | Start ... Partially failed because P2pool instance is not running."); warn!("Xvb | Start ... Partially failed because P2pool instance is not running.");
// output the error to console output_console(
if let Err(e) = writeln!( &gui_api,
lock!(gui_api).output, "P2pool process is not running.\nCheck the P2pool Tab",
"P2pool process is not running.\nCheck the P2pool Tab\n", );
) {
error!("XvB Watchdog | GUI status write failed: {}", e);
}
lock!(process).state = ProcessState::Syncing; lock!(process).state = ProcessState::Syncing;
} }
@ -175,24 +164,18 @@ impl Helper {
// send to console: p2pool process is not running // send to console: p2pool process is not running
warn!("Xvb | Start ... Partially failed because Xmrig instance is not running."); warn!("Xvb | Start ... Partially failed because Xmrig instance is not running.");
// output the error to console // output the error to console
if let Err(e) = writeln!( output_console(
lock!(gui_api).output, &gui_api,
"XMRig process is not running.\nCheck the Xmrig Tab.\n", "XMRig process is not running.\nCheck the Xmrig Tab.",
) { );
error!("XvB Watchdog | GUI status write failed: {}", e);
}
lock!(process).state = ProcessState::Syncing; lock!(process).state = ProcessState::Syncing;
} }
info!("XvB | print to console state"); info!("XvB | print to console state");
if lock!(process).state != ProcessState::Middle { if lock!(process).state != ProcessState::Middle {
if let Err(e) = writeln!( output_console(
lock!(gui_api).output, &gui_api,
"XvB partially started.\n{}\n", &["XvB partially started.\n", XVB_PUBLIC_ONLY].concat(),
XVB_PUBLIC_ONLY, );
) {
error!("XvB Watchdog | GUI status write failed: {}", e);
}
} else { } else {
info!("XvB Fully started"); info!("XvB Fully started");
lock!(process).state = ProcessState::Alive; lock!(process).state = ProcessState::Alive;
@ -206,12 +189,10 @@ impl Helper {
XvbNode::update_fastest_node(&client_http_c, &pub_api_c, &gui_api_c, &process_c) XvbNode::update_fastest_node(&client_http_c, &pub_api_c, &gui_api_c, &process_c)
.await; .await;
}); });
if let Err(e) = writeln!( output_console(
lock!(gui_api).output, &gui_api,
"Algorithm of distribution of HR will wait 15 minutes for Xmrig average HR data.\n" "Algorithm of distribution of HR will wait 15 minutes for Xmrig average HR data.",
) { );
error!("XvB Watchdog | GUI status write failed: {}", e);
}
} }
// see how many shares are found at p2pool node only if XvB is started successfully. If it wasn't, maybe P2pool is node not running. // see how many shares are found at p2pool node only if XvB is started successfully. If it wasn't, maybe P2pool is node not running.
let mut old_shares = if lock!(process).state == ProcessState::Alive { let mut old_shares = if lock!(process).state == ProcessState::Alive {
@ -243,12 +224,10 @@ impl Helper {
*lock!(pub_api) = PubXvbApi::new(); *lock!(pub_api) = PubXvbApi::new();
*lock!(gui_api) = PubXvbApi::new(); *lock!(gui_api) = PubXvbApi::new();
lock!(process).state = ProcessState::Alive; lock!(process).state = ProcessState::Alive;
if let Err(e) = writeln!( output_console(
lock!(gui_api).output, &gui_api,
"XvB is now started because p2pool and xmrig came online.\n", "XvB is now started because p2pool and xmrig came online.",
) { );
error!("XvB Watchdog | GUI status write failed: {}", e);
}
} }
} else { } else {
// verify if the state is changing because p2pool is not alive anymore. // verify if the state is changing because p2pool is not alive anymore.
@ -257,12 +236,10 @@ impl Helper {
*lock!(pub_api) = PubXvbApi::new(); *lock!(pub_api) = PubXvbApi::new();
*lock!(gui_api) = PubXvbApi::new(); *lock!(gui_api) = PubXvbApi::new();
lock!(process).state = ProcessState::Syncing; lock!(process).state = ProcessState::Syncing;
if let Err(e) = writeln!( output_console(
lock!(gui_api).output, &gui_api,
"XvB is now partially stopped because p2pool node or xmrig came offline.\nCheck P2pool and Xmrig Tabs", "XvB is now partially stopped because p2pool node or xmrig came offline.\nCheck P2pool and Xmrig Tabs",
) { );
error!("XvB Watchdog | GUI status write failed: {}", e);
}
} }
} }
} }
@ -300,13 +277,13 @@ impl Helper {
XVB_URL_PUBLIC_API, err XVB_URL_PUBLIC_API, err
); );
// output the error to console // output the error to console
if let Err(e) = writeln!( output_console(
lock!(gui_api).output, &gui_api,
&format!(
"Failure to retrieve public stats from {}", "Failure to retrieve public stats from {}",
XVB_URL_PUBLIC_API XVB_URL_PUBLIC_API
) { ),
error!("XvB Watchdog | GUI status write failed: {}", e); );
}
lock!(process).state = ProcessState::Failed; lock!(process).state = ProcessState::Failed;
break; break;
} }
@ -328,13 +305,7 @@ impl Helper {
Ok(data) => data, Ok(data) => data,
Err(e) => { Err(e) => {
warn!("XvB Watchdog | Data provided from private API is not deserializ-able.Error: {}", e); warn!("XvB Watchdog | Data provided from private API is not deserializ-able.Error: {}", e);
// output the error to console output_console(&gui_api, &format!("XvB Watchdog | Data provided from private API is not deserializ-able.Error: {}", e));
if let Err(e) = writeln!(
lock!(gui_api).output,
"XvB Watchdog | Data provided from private API is not deserializ-able.Error: {}", e
) {
error!("XvB Watchdog | GUI status write failed: {}", e);
}
break; break;
} }
}; };
@ -345,14 +316,10 @@ impl Helper {
"XvB Watchdog | Could not send HTTP private API request to: {}\n:{}", "XvB Watchdog | Could not send HTTP private API request to: {}\n:{}",
XVB_URL, err XVB_URL, err
); );
// output the error to console output_console(
if let Err(e) = writeln!( &gui_api,
lock!(gui_api).output, &format!("Failure to retrieve private stats from {}", XVB_URL),
"Failure to retrieve private stats from {}", );
XVB_URL
) {
error!("XvB Watchdog | GUI status write failed: {}", e);
}
lock!(process).state = ProcessState::Failed; lock!(process).state = ProcessState::Failed;
break; break;
} }
@ -436,21 +403,15 @@ impl Helper {
) )
.await .await
{ {
// show to console error about updating xmrig config output_console(
if let Err(e) = writeln!( &gui_api_c,
lock!(gui_api_c).output, &format!(
"Failure to update xmrig config with HTTP API.\nError: {}", "Failure to update xmrig config with HTTP API.\nError: {}",
err err
) { ),
error!("XvB Watchdog | GUI status write failed: {}", e); );
}
} else { } else {
if let Err(e) = writeln!( output_console(&gui_api_c, "Algorithm of distribution HR started for the next ten minutes.\nMining on local p2pool node.");
lock!(gui_api_c).output,
"Algorithm of distribution HR started for the next ten minutes.\nMining on local p2pool node.",
) {
error!("XvB Watchdog | GUI status write failed: {}", e);
}
} }
}); });
@ -459,24 +420,20 @@ impl Helper {
info!("Xvb Process | Algorithm share is in current window"); info!("Xvb Process | Algorithm share is in current window");
// calcul minimum HR // calcul minimum HR
if let Err(e) = writeln!( output_console(
lock!(gui_api).output, &gui_api,
"At least one share is in current PPLNS window.", "At least one share is in current PPLNS window.",
) { );
error!("XvB Watchdog | GUI status write failed: {}", e);
}
let hr = lock!(gui_api_xmrig).hashrate_raw_15m; let hr = lock!(gui_api_xmrig).hashrate_raw_15m;
let min_hr = Helper::minimum_hashrate_share( let min_hr = Helper::minimum_hashrate_share(
lock!(gui_api_p2pool).p2pool_difficulty_u64, lock!(gui_api_p2pool).p2pool_difficulty_u64,
state_p2pool.mini, state_p2pool.mini,
); );
info!("Xvb Process | hr {}, min_hr: {} ", hr, min_hr); info!("Xvb Process | hr {}, min_hr: {} ", hr, min_hr);
if let Err(e) = writeln!( output_console(
lock!(gui_api).output, &gui_api,
"You'r HR from Xmrig is {}, minimum required HR to keep a share in PPLNS window is {}", hr, min_hr &format!("You'r HR from Xmrig is {}, minimum required HR to keep a share in PPLNS window is {}", hr, min_hr),
) { );
error!("XvB Watchdog | GUI status write failed: {}", e);
}
// calculate how much time can be spared // calculate how much time can be spared
let mut spared_time = Helper::time_that_could_be_spared(hr, min_hr); let mut spared_time = Helper::time_that_could_be_spared(hr, min_hr);
@ -490,13 +447,13 @@ impl Helper {
); );
} }
info!("Xvb Process | spared time {} ", spared_time); info!("Xvb Process | spared time {} ", spared_time);
if let Err(e) = writeln!( output_console(
lock!(gui_api).output, &gui_api,
"{} seconds of HR will be donated to the raffle.", &format!(
" {} seconds of HR will be donated to the raffle.",
spared_time spared_time
) { ),
error!("XvB Watchdog | GUI status write failed: {}", e); );
}
// sleep 10m less spared time then request XMrig to mine on XvB // sleep 10m less spared time then request XMrig to mine on XvB
let was_instant = start_algorithm; let was_instant = start_algorithm;
let gui_api_c = gui_api.clone(); let gui_api_c = gui_api.clone();
@ -517,12 +474,7 @@ impl Helper {
}); });
} }
} else { } else {
if let Err(e) = writeln!( output_console(&gui_api, "No share in the current PPLNS Window !");
lock!(gui_api).output,
"No share in the current PPLNS Window !",
) {
error!("XvB Watchdog | GUI status write failed: {}", e);
}
} }
} }
// instant saved for next check // instant saved for next check
@ -588,13 +540,13 @@ impl Helper {
let node = lock!(gui_api_xvb).stats_priv.node.clone(); let node = lock!(gui_api_xvb).stats_priv.node.clone();
info!("Xvb Process | for now mine on p2pol "); info!("Xvb Process | for now mine on p2pol ");
info!("Xvb Process | spared time {} ", spared_time); info!("Xvb Process | spared time {} ", spared_time);
if let Err(e) = writeln!( output_console(
lock!(gui_api_xvb).output, &gui_api_xvb,
&format!(
"Still mining on P2pool node for {} seconds", "Still mining on P2pool node for {} seconds",
XVB_TIME_ALGO - spared_time XVB_TIME_ALGO - spared_time
) { ),
error!("XvB Watchdog | GUI status write failed: {}", e); );
}
sleep_until(*was_instant + Duration::from_secs((XVB_TIME_ALGO - spared_time) as u64)).await; sleep_until(*was_instant + Duration::from_secs((XVB_TIME_ALGO - spared_time) as u64)).await;
if let Err(err) = PrivXmrigApi::update_xmrig_config( if let Err(err) = PrivXmrigApi::update_xmrig_config(
client, client,
@ -607,22 +559,22 @@ impl Helper {
.await .await
{ {
// show to console error about updating xmrig config // show to console error about updating xmrig config
if let Err(e) = writeln!( output_console(
lock!(gui_api_xvb).output, &gui_api_xvb,
&format!(
"Failure to update xmrig config with HTTP API.\nError: {}", "Failure to update xmrig config with HTTP API.\nError: {}",
err err
) { ),
error!("XvB Watchdog | GUI status write failed: {}", e); );
}
} else { } else {
info!("Xvb Process | mining on XvB pool"); info!("Xvb Process | mining on XvB pool");
if let Err(e) = writeln!( output_console(
lock!(gui_api_xvb).output, &gui_api_xvb,
&format!(
"Now donating to the XvB raffle for the rest of the {} minutes.", "Now donating to the XvB raffle for the rest of the {} minutes.",
XVB_TIME_ALGO / 60 XVB_TIME_ALGO / 60
) { ),
error!("XvB Watchdog | GUI status write failed: {}", e); );
}
} }
} }
} }
@ -833,23 +785,18 @@ impl XvbNode {
if node == XvbNode::P2pool { if node == XvbNode::P2pool {
// if both nodes are dead, then the state of the process must be NodesOffline // if both nodes are dead, then the state of the process must be NodesOffline
info!("XvB node ping, all offline or ping failed, switching back to local p2pool",); info!("XvB node ping, all offline or ping failed, switching back to local p2pool",);
if let Err(e) = writeln!( output_console(
lock!(&gui_api_xvb).output, &gui_api_xvb,
"XvB node ping, all offline or ping failed, switching back to local p2pool", "XvB node ping, all offline or ping failed, switching back to local p2pool",
) { );
error!("XvB Watchdog | GUI status write failed: {}", e);
}
lock!(process_xvb).state = ProcessState::OfflineNodesAll; lock!(process_xvb).state = ProcessState::OfflineNodesAll;
} else { } else {
// if node is up and because update_fastest is used only if token/address is valid, it means XvB process is Alive. // if node is up and because update_fastest is used only if token/address is valid, it means XvB process is Alive.
info!("XvB node ping, both online and best is {}", node.url()); info!("XvB node ping, both online and best is {}", node.url());
if let Err(e) = writeln!( output_console(
lock!(&gui_api_xvb).output, &gui_api_xvb,
"XvB node ping, {} is selected as the fastest.", &format!("XvB node ping, {} is selected as the fastest.", node),
node );
) {
error!("XvB Watchdog | GUI status write failed: {}", e);
}
lock!(process_xvb).state = ProcessState::Alive; lock!(process_xvb).state = ProcessState::Alive;
} }
lock!(pub_api_xvb).stats_priv.node = node; lock!(pub_api_xvb).stats_priv.node = node;
@ -939,15 +886,10 @@ fn signal_interrupt(
); );
// insert the signal into output of XvB // insert the signal into output of XvB
// This is written directly into the GUI API, because sometimes the 900ms event loop can't catch it. // This is written directly into the GUI API, because sometimes the 900ms event loop can't catch it.
if let Err(e) = writeln!( output_console(
lock!(gui_api).output, &gui_api,
"{}Xvb stopped | Uptime: [{}] | \n{}\n\n\n\n", &format!("{}XvB stopped\n{}\n", HORI_CONSOLE, HORI_CONSOLE),
HORI_CONSOLE, );
Uptime::from(uptime),
HORI_CONSOLE
) {
error!("XvB Watchdog | GUI Uptime/Exit status write failed: {}", e);
}
debug!("XvB Watchdog | Stop SIGNAL done, breaking"); debug!("XvB Watchdog | Stop SIGNAL done, breaking");
lock!(process).signal = ProcessSignal::None; lock!(process).signal = ProcessSignal::None;
lock!(process).state = ProcessState::Dead; lock!(process).state = ProcessState::Dead;
@ -991,21 +933,18 @@ fn signal_interrupt(
.await .await
{ {
// show to console error about updating xmrig config // show to console error about updating xmrig config
if let Err(e) = writeln!( output_console(
lock!(&gui_api_c).output, &gui_api_c,
&format!(
"Failure to update xmrig config with HTTP API.\nError: {}", "Failure to update xmrig config with HTTP API.\nError: {}",
err err
) { ),
error!("XvB Watchdog | GUI status write failed: {}", e); );
}
} else { } else {
if let Err(e) = writeln!( output_console(
lock!(&gui_api_c).output, &gui_api_c,
"XvB node failed, falling back to {}", &format!("XvB node failed, falling back to {}", node),
node );
) {
error!("XvB Watchdog | GUI status write failed: {}", e);
}
} }
}); });
lock!(process).signal = ProcessSignal::None; lock!(process).signal = ProcessSignal::None;
@ -1013,6 +952,17 @@ fn signal_interrupt(
} }
false false
} }
// print date time to console output in same format than xmrig
use chrono::Local;
fn datetime_console() -> String {
format!("[{}] ", Local::now().format("%Y-%m-%d %H:%M:%S%.3f"))
}
pub fn output_console(gui_api: &Arc<Mutex<PubXvbApi>>, msg: &str) {
if let Err(e) = writeln!(lock!(gui_api).output, "{}{msg}", datetime_console()) {
error!("XvB Watchdog | GUI status write failed: {}", e);
}
}
//---------------------------------------------------------------------------------------------------- TEST //---------------------------------------------------------------------------------------------------- TEST
#[cfg(test)] #[cfg(test)]
mod test { mod test {