#!/bin/bash
#
#This is a monitor system CPU Memory process disk IO disk zone statistixs scripts.
#
#
##CPU usage rate
/bin/date>> /mnt/system_info.log
echo -e "\n" >> /mnt/system_info.log
##CPU usage rate
echo -e "\033[31mCPU usage rate:\033[0m" >> /mnt/system_info.log
/usr/bin/top -n 2 | grep "Cpu(s)" >> /mnt/system_info.log
echo -e "\n" >> /mnt/system_info.log
##memory usage rate
echo -e "\033[31mMemory usage rate:\033[0m" >> /mnt/system_info.log
total=`free -m | grep "Mem" | awk ‘{print $2}‘`
used=`free -m | grep "Mem" | awk ‘{print $3}‘`
usage_rate=`awk ‘BEGIN{printf "%.2f%\n",(‘$used‘/‘$total‘)*100}‘`
echo "memory usage rate is $usage_rate" >> /mnt/system_info.log
echo -e "\n" >> /mnt/system_info.log
##memory error(memory use exceed 80%)
echo -e "\033[31mMemory error state:\033[0m" >> /mnt/system_info.log
memory_rate=`echo "${usage_rate%.*}"`
if [ $memory_rate -gt 80 ];then
echo "Error,memory use rate is $usage_rate,Memory More than 80%,Please Handle" >> /mnt/system_info.log
else
echo "System Memory is Normal." >> /mnt/system_info.log
fi
echo -e "\n" >> /mnt/system_info.log
##process statistics
echo -e "\033[31mProcess statistics: \033[0m" >> /mnt/system_info.log
process=`/bin/ps aux | wc -l`
echo "System process numbers is $process" >> /mnt/system_info.log
echo -e "\n" >> /mnt/system_info.log
##disk IO statistics
echo -e "\033[31mIO statistics: \033[0m" >> /mnt/system_info.log
/usr/bin/iostat -d -k 1 4 >> /mnt/system_info.log
echo -e "\n" >> /mnt/system_info.log
##disk space use
echo -e "\033[31mDisk space use: \033[0m" >> /mnt/system_info.log
/bin/df -h >> /mnt/system_info.log
echo -e "\n" >> /mnt/system_info.log
##disk partition statistics
echo -e "\033[31mDisk partition rate: \033[0m" >> /mnt/system_info.log
partition_rate=`df -k | grep -v Filesystem | awk ‘{print int($5)}‘`
for number_rate in $partition_rate
do
if [ $number_rate -ge 80 ];then
echo "Error,disk partition zone More than 80%,Please Handle" >> /mnt/system_info.log
else
echo "Disk partition zone Normal" >> /mnt/system_info.log
fi
done
牛掰的大神可以随便评论