包括,15分钟平均负载,cpu空闲率,内存剩余,开机时间,使用率最高的文件系统。及根据以上数据得到的状态判断。
#!/bin/bash
#load(15min) cpu_idle(%) mem_free(K) uptime(m) percent(%) filesystem warning
LC_ALL=C
LANG=C
W1=`w|head -1`
load15=`echo ${W1#*average:}|awk -F ',' '{print $3}'`
cpuidle=`vmstat 1 2 |tail -1|awk '{print $15}'`
memfree=`grep MemFree /proc/meminfo|awk '{print $2}'`
df=`df -l 2>/dev/null|grep -v 'Filesystem'|awk '{if (index($5,"%"))print $5,$6;else print $4,$5}'|sort -n|tail -1`
percent=`echo $df|awk '{print $1}'|sed 's/%//'`
fs=`echo $df|awk '{print $2}'`
uptime=`cat /proc/uptime|awk '{print int($1/60)}'`
loadgt10=`echo $load15|awk '{print int($1>10.0)}'`
if [ "$loadgt10" -eq 1 ] || [ "$cpuidle" -lt 50 ] || [ "$percent" -gt 95 ] || [ "$uptime" -lt 1440 ];then
warning="WARNING";
else
warning="ok";
fi
printf "%6.2f %3i%% %10iK %7im %3i%% %-20s %6s\n" $load15 $cpuidle $memfree $uptime $percent $fs $warning
plSSH 运行截图