Add useful stats for NEMS Linux check
This commit is contained in:
100
installer
100
installer
@ -677,7 +677,8 @@ EOF
|
||||
# AJAX status info
|
||||
cat > "$WWW_ROOT/status.php" <<'EOF'
|
||||
<?php
|
||||
// no session needed; this is polled often
|
||||
// lightweight JSON status for dashboard / monitoring
|
||||
|
||||
$flag = '/var/lib/btc-solo/.setup-complete';
|
||||
if (!file_exists($flag)) {
|
||||
http_response_code(403);
|
||||
@ -686,40 +687,95 @@ if (!file_exists($flag)) {
|
||||
exit;
|
||||
}
|
||||
|
||||
// Bitcoin Core status
|
||||
$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;
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user