From 696fbf28275295479cdf4c3687119d82527f9637 Mon Sep 17 00:00:00 2001 From: cfdaily Date: Fri, 22 May 2026 18:32:30 +0800 Subject: [PATCH] auto-sync: 2026-05-22 18:32:30 --- scripts/status.sh | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/scripts/status.sh b/scripts/status.sh index 52c8fc4..7d282ce 100755 --- a/scripts/status.sh +++ b/scripts/status.sh @@ -39,13 +39,11 @@ fi # ── PM2 状态 ── echo "" if pm2 describe "$PM2_NAME" >/dev/null 2>&1; then - PM2_STATUS=$(pm2 describe "$PM2_NAME" 2>/dev/null) - STATUS=$(echo "$PM2_STATUS" | grep "status" | head -1 | awk '{print $NF}') - PID=$(echo "$PM2_STATUS" | grep "pid" | head -1 | awk '{print $NF}') - UPTIME=$(echo "$PM2_STATUS" | grep "uptime" | head -1 | awk '{for(i=4;i<=NF;i++) printf $i" "; print ""}') - RESTARTS=$(echo "$PM2_STATUS" | grep "restart time" | awk '{print $NF}') - MEM=$(echo "$PM2_STATUS" | grep "heap size" | head -1 | awk '{print $NF}') - CPU=$(echo "$PM2_STATUS" | grep "cpu" | head -1 | awk '{print $NF}') + PM2_DESC=$(pm2 describe "$PM2_NAME" 2>/dev/null) + STATUS=$(echo "$PM2_DESC" | grep "status" | head -1 | awk '{print $NF}') + PID=$(echo "$PM2_DESC" | grep -E "^\\│ pid " | head -1 | awk '{print $NF}') + UPTIME=$(echo "$PM2_DESC" | grep "uptime" | head -1 | sed 's/.*│ //' | sed 's/ *│.*//') + RESTARTS=$(echo "$PM2_DESC" | grep "restarts" | head -1 | awk '{print $NF}') if [ "$STATUS" = "online" ]; then echo " PM2: online ✅" @@ -55,8 +53,20 @@ if pm2 describe "$PM2_NAME" >/dev/null 2>&1; then echo " PID: ${PID:-?}" echo " Uptime: ${UPTIME:-?}" echo " Restarts: ${RESTARTS:-0}" - echo " Memory: ${MEM:-?}" - echo " CPU: ${CPU:-?}%" + + # Memory/CPU from pm2 list + PM2_MEM_CPU=$(pm2 jlist 2>/dev/null | python3 -c " +import sys, json +for p in json.load(sys.stdin): + if p['name'] == '$PM2_NAME': + m = round(p['monit']['memory'] / 1024 / 1024, 1) + c = p['monit']['cpu'] + print(f'{m}|{c}') + break +" 2>/dev/null || echo "?|?") + IFS='|' read -r MEM CPU <<< "$PM2_MEM_CPU" + echo " Memory: ${MEM}MB" + echo " CPU: ${CPU}%" else echo " PM2: not found ❌" fi