From 7424a2654fb87fa5de8fb6f0a732afacfe364e6c Mon Sep 17 00:00:00 2001 From: Baldnerd Date: Sun, 9 Nov 2025 10:42:55 -0500 Subject: [PATCH] Add useful stats for NEMS Linux check --- installer | 100 ++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 78 insertions(+), 22 deletions(-) diff --git a/installer b/installer index 8390549..5618b59 100755 --- a/installer +++ b/installer @@ -677,7 +677,8 @@ EOF # AJAX status info cat > "$WWW_ROOT/status.php" <<'EOF' /dev/null'; -$out = shell_exec($cmd); -$info = $out ? json_decode($out, true) : null; +header('Content-Type: application/json'); -// service health (simple is-active check) +// ---- 1) bitcoin core info ---- +$btcInfo = null; +$out = shell_exec('/usr/local/bin/bitcoin-cli -conf=/etc/bitcoin/bitcoin.conf getblockchaininfo 2>/dev/null'); +if ($out) { + $btcInfo = json_decode($out, true); +} + +// ---- 2) service health ---- function svc($name) { $res = trim(shell_exec('systemctl is-active ' . escapeshellarg($name) . ' 2>/dev/null')); return $res === 'active' ? 'active' : $res; } - $services = [ 'bitcoind' => svc('bitcoind'), - 'ckpool' => svc('ckpool') + 'ckpool' => svc('ckpool'), ]; -header('Content-Type: application/json'); +// ---- 3) system info (non-sensitive) ---- -if (!$info) { - echo json_encode([ - 'error' => 'bitcoin-cli failed', - 'services' => $services - ]); - exit; +// uptime +$uptime_seconds = null; +if (is_readable('/proc/uptime')) { + $up = trim(file_get_contents('/proc/uptime')); + $parts = explode(' ', $up); + $uptime_seconds = (int)floatval($parts[0]); } +// load average +$load = function_exists('sys_getloadavg') ? sys_getloadavg() : null; + +// memory +$mem_total = null; +$mem_avail = null; +if (is_readable('/proc/meminfo')) { + $meminfo = file('/proc/meminfo', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); + foreach ($meminfo as $line) { + if (strpos($line, 'MemTotal:') === 0) { + $mem_total = (int)filter_var($line, FILTER_SANITIZE_NUMBER_INT) * 1024; + } elseif (strpos($line, 'MemAvailable:') === 0) { + $mem_avail = (int)filter_var($line, FILTER_SANITIZE_NUMBER_INT) * 1024; + } + } +} + +// disk (root) +$disk_root_total = @disk_total_space('/'); +$disk_root_free = @disk_free_space('/'); + +// disk (bitcoind datadir) +$btcDir = '/var/lib/bitcoind'; +$disk_btc_total = @disk_total_space($btcDir); +$disk_btc_free = @disk_free_space($btcDir); + +// bitcoind dir size +$btc_dir_size = null; +$du = shell_exec('du -sb ' . escapeshellarg($btcDir) . ' 2>/dev/null'); +if ($du) { + $parts = preg_split('/\s+/', trim($du)); + if (isset($parts[0]) && ctype_digit($parts[0])) { + $btc_dir_size = (int)$parts[0]; + } +} + +// ---- 4) output ---- echo json_encode([ - 'initialblockdownload' => $info['initialblockdownload'] ?? null, - 'blocks' => $info['blocks'] ?? null, - 'headers' => $info['headers'] ?? null, - 'verificationprogress' => $info['verificationprogress'] ?? null, - 'pruned' => $info['pruned'] ?? null, - 'services' => $services -]); + 'initialblockdownload' => $btcInfo['initialblockdownload'] ?? null, + 'blocks' => $btcInfo['blocks'] ?? null, + 'headers' => $btcInfo['headers'] ?? null, + 'verificationprogress' => $btcInfo['verificationprogress'] ?? null, + 'pruned' => $btcInfo['pruned'] ?? null, + 'services' => $services, + 'system' => [ + 'uptime_seconds' => $uptime_seconds, + 'loadavg' => $load, + 'mem_total_bytes' => $mem_total, + 'mem_available_bytes' => $mem_avail, + 'disk_root' => [ + 'total_bytes' => $disk_root_total, + 'free_bytes' => $disk_root_free, + ], + 'disk_bitcoind' => [ + 'total_bytes' => $disk_btc_total, + 'free_bytes' => $disk_btc_free, + 'used_bytes' => $btc_dir_size, + ], + ], +], JSON_UNESCAPED_SLASHES); EOF # activation page