pub struct NetworkMonitor { /* private fields */ }Expand description
Network monitoring for Kaspa node
§Examples
#[tokio::main]
async fn main() {
let client = KaspaClient::new("");
let mut monitor_arc = Arc::new(NetworkMonitor::new(client));
tokio::spawn(async move {
monitor_arc.clone().start_monitoring().await.unwrap();
});
loop {
let report = monitor.generate_health_report();
println!("Network healthy: {}", report.is_healthy);
tokio::time::sleep(Duration::from_secs(60)).await;
}
}Implementations§
Source§impl NetworkMonitor
impl NetworkMonitor
Sourcepub fn new(client: KaspaClient) -> Self
pub fn new(client: KaspaClient) -> Self
create new network monitor
§Examples
let client = KaspaClient::new("http://localhost:16110");
let monitor = NetworkMonitor::new(client);Sourcepub async fn start_monitoring(&mut self) -> Result<()>
pub async fn start_monitoring(&mut self) -> Result<()>
start monitoring
§Examples
let mut monitor = NetworkMonitor::new(client);
tokio::spawn(async move {
monitor.start_monitoring().await.unwrap();
});Sourcepub fn generate_health_report(&self) -> NetworkHealthReport
pub fn generate_health_report(&self) -> NetworkHealthReport
Generate health health report
§Examples
let monitor = NetworkMonitor::new(client);
let report = monitor.generate_health_report();
if !report.is_healthy {
println!("ALERT: {}", report.recommendation);
// Send alert notification...
}
println!("Block rate: {:.2} B/s", report.metrics.block_rate);
println!("Peers: {}", report.metrics.peer_count);Auto Trait Implementations§
impl !Freeze for NetworkMonitor
impl !RefUnwindSafe for NetworkMonitor
impl !UnwindSafe for NetworkMonitor
impl Send for NetworkMonitor
impl Sync for NetworkMonitor
impl Unpin for NetworkMonitor
impl UnsafeUnpin for NetworkMonitor
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more