本文最后更新于:June 30, 2023 pm
Shell编程之-常见性能指标获取
IP: hostname -I
Hostname: hostname -a
磁盘: df -Bm
root用量: df -Bm | awk 'NR==2 {print $1, $4 , $5}'
内存: cat /proc/meminfo
特定程序的内存:
CPU : awk '{u=$2+$4; t=$2+$4+$5; if (NR==1){u1=u; t1=t;} else print ($2+$4-u1) * 100 / (t-t1) "%"; }' <(grep 'cpu ' /proc/stat) <(sleep 0.5;grep 'cpu ' /proc/stat)
RAM: free -m | awk 'NR==2{printf "%.2f%%\n", $3*100/$2 }'
磁盘 : df -h | awk '$NF=="/"{printf "%s\n", $5}'
CPU % used : top -bn1 | grep load | awk '{printf "%.2f%%\n", $(NF-2)}'
本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!