Skip to content

Instantly share code, notes, and snippets.

@githubhjs
Last active September 18, 2025 02:19
Show Gist options
  • Select an option

  • Save githubhjs/3baa6f91dea8a5da4f999ba53fb1fe15 to your computer and use it in GitHub Desktop.

Select an option

Save githubhjs/3baa6f91dea8a5da4f999ba53fb1fe15 to your computer and use it in GitHub Desktop.
② 低權限「一鍵巡檢」面板 把下面存成 nfs-watch.sh(單檔自畫面迴圈),一般使用者可直接跑:
#!/usr/bin/env bash
# nfs-watch.sh -- user-mode NFS watch panel (no sudo)
INT=${1:-2} # 重新整理秒數,預設 2s
have_nfsiostat=0
command -v nfsiostat >/dev/null 2>&1 && have_nfsiostat=1
while true; do
clear
echo "NFS Watch | host=$(hostname) time=$(date '+%F %T') refresh=${INT}s"
echo "--------------------------------------------------------------------------"
echo "[Mounts]"
grep -E ' nfs[34]? ' /proc/mounts | sed 's/^/ /'; echo
echo "[Client RPC (retrans/timeout)]"
nfsstat -c -o net,rpc 2>/dev/null | sed 's/^/ /' || echo " (nfsstat 不可用)"
echo
if [ "$have_nfsiostat" -eq 1 ]; then
echo "[nfsiostat snapshot]"
nfsiostat -h 1 1 2>/dev/null | awk '
/^\/|^[A-Za-z0-9\.\-]+:\/.* mounted on /{gsub(" mounted on "," -> ");print " " $0}
/avg RTT|avg exe|rpc bklog|read:|write:/{gsub(/^[ \t]+/,"",$0);print " " $0}
'
echo
else
echo "[nfsiostat 不可用;改顯示 mountstats 標記行]"
grep -A4 -E '^device .+ nfs' /proc/self/mountstats | egrep -n 'device|READ|WRITE|rpc|rtt|exe' | sed 's/^/ /'
echo
fi
echo "[Top I/O PIDs (pidstat -d)]"
pidstat -d 1 1 2>/dev/null | tail -n +4 | sort -k7,7nr | head -n 8 | sed 's/^/ /'
echo
echo "[NFS TCP Connections (:2049)]"
ss -tan 2>/dev/null | awk '/:2049/ && /ESTAB/ {print $5}' | sed "s/:.*//" | sort | uniq -c | sort -nr | sed 's/^/ /' || echo " (ss 不可用)"
echo
echo "判讀提示:exe≫rtt→伺服器/磁碟忙;rtt高+retrans/timeout升→網路;bklog升+連線少→並行度不足。"
sleep "$INT"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment