Add useful stats for NEMS Linux check

This commit is contained in:
2025-11-09 10:42:55 -05:00
parent e19549a3a4
commit 7424a2654f

100
installer
View File

@ -677,7 +677,8 @@ EOF
# AJAX status info # AJAX status info
cat > "$WWW_ROOT/status.php" <<'EOF' cat > "$WWW_ROOT/status.php" <<'EOF'
<?php <?php
// no session needed; this is polled often // lightweight JSON status for dashboard / monitoring
$flag = '/var/lib/btc-solo/.setup-complete'; $flag = '/var/lib/btc-solo/.setup-complete';
if (!file_exists($flag)) { if (!file_exists($flag)) {
http_response_code(403); http_response_code(403);
@ -686,40 +687,95 @@ if (!file_exists($flag)) {
exit; exit;
} }
// Bitcoin Core status header('Content-Type: application/json');
$cmd = '/usr/local/bin/bitcoin-cli -conf=/etc/bitcoin/bitcoin.conf getblockchaininfo 2>/dev/null';
$out = shell_exec($cmd);
$info = $out ? json_decode($out, true) : null;
// 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) { function svc($name) {
$res = trim(shell_exec('systemctl is-active ' . escapeshellarg($name) . ' 2>/dev/null')); $res = trim(shell_exec('systemctl is-active ' . escapeshellarg($name) . ' 2>/dev/null'));
return $res === 'active' ? 'active' : $res; return $res === 'active' ? 'active' : $res;
} }
$services = [ $services = [
'bitcoind' => svc('bitcoind'), 'bitcoind' => svc('bitcoind'),
'ckpool' => svc('ckpool') 'ckpool' => svc('ckpool'),
]; ];
header('Content-Type: application/json'); // ---- 3) system info (non-sensitive) ----
if (!$info) { // uptime
echo json_encode([ $uptime_seconds = null;
'error' => 'bitcoin-cli failed', if (is_readable('/proc/uptime')) {
'services' => $services $up = trim(file_get_contents('/proc/uptime'));
]); $parts = explode(' ', $up);
exit; $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([ echo json_encode([
'initialblockdownload' => $info['initialblockdownload'] ?? null, 'initialblockdownload' => $btcInfo['initialblockdownload'] ?? null,
'blocks' => $info['blocks'] ?? null, 'blocks' => $btcInfo['blocks'] ?? null,
'headers' => $info['headers'] ?? null, 'headers' => $btcInfo['headers'] ?? null,
'verificationprogress' => $info['verificationprogress'] ?? null, 'verificationprogress' => $btcInfo['verificationprogress'] ?? null,
'pruned' => $info['pruned'] ?? null, 'pruned' => $btcInfo['pruned'] ?? null,
'services' => $services '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 EOF
# activation page # activation page