From ffba838d8a72a781e63a0848836948c6b415234b Mon Sep 17 00:00:00 2001 From: sat-3 <144347307+j34g@users.noreply.github.com> Date: Tue, 5 Nov 2024 08:50:10 +0000 Subject: [PATCH] Update to properties for more details (make knots better than core on startos) Mempool Statistics in Properties section: I added a section in the sidecar function to retrieve and format: - Max Mempool Size in MB - Current Mempool Usage in MB and as a percentage - Mempool Transaction Count I have also made and tested this to ensure it works flawlessly. --- manager/src/main.rs | 62 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/manager/src/main.rs b/manager/src/main.rs index dc1323af..589bfc91 100644 --- a/manager/src/main.rs +++ b/manager/src/main.rs @@ -168,6 +168,68 @@ fn sidecar(config: &Mapping, addr: &str) -> Result<(), Box> { }, ); } + + // New section to fetch mempool statistics + let mempool_info = std::process::Command::new("bitcoin-cli") + .arg("-conf=/root/.bitcoin/bitcoin.conf") + .arg("getmempoolinfo") + .output()?; + + if mempool_info.status.success() { + let mempool_data: serde_json::Value = serde_json::from_slice(&mempool_info.stdout)?; + + let max_mempool = mempool_data["maxmempool"].as_u64().unwrap_or(0) as f64 / 1024_f64.powf(2.0); // Convert bytes to MB + let mempool_usage = mempool_data["usage"].as_u64().unwrap_or(0) as f64 / 1024_f64.powf(2.0); // Convert bytes to MB + let mempool_percent = if max_mempool > 0.0 { + (mempool_usage / max_mempool) * 100.0 + } else { + 0.0 + }; + let tx_count = mempool_data["size"].as_u64().unwrap_or(0); // Number of transactions + + stats.insert( + Cow::from("Max Mempool Size"), + Stat { + value_type: "string", + value: format!("{:.2} MB", max_mempool), + description: Some(Cow::from("Maximum memory pool size")), + copyable: false, + qr: false, + masked: false, + }, + ); + + stats.insert( + Cow::from("Current Mempool Usage"), + Stat { + value_type: "string", + value: format!("{:.2} MB ({:.2}%)", mempool_usage, mempool_percent), + description: Some(Cow::from("Current memory pool usage as a percentage of max size")), + copyable: false, + qr: false, + masked: false, + }, + ); + + stats.insert( + Cow::from("Mempool Transaction Count"), + Stat { + value_type: "string", + value: format!("{}", tx_count), + description: Some(Cow::from("Current number of transactions in the mempool")), + copyable: false, + qr: false, + masked: false, + }, + ); + } else { + eprintln!( + "Error retrieving mempool info: {}", + std::str::from_utf8(&mempool_info.stderr).unwrap_or("UNKNOWN ERROR") + ); + } + + // Existing code for blockchain and network info retrieval continues here... let info_res = std::process::Command::new("bitcoin-cli") .arg("-conf=/root/.bitcoin/bitcoin.conf") .arg("getblockchaininfo")