centos7下查看cpu,内存,根 占用率脚本

#!/bin/bash

cb=$(free -m | grep "Mem:" | awk '{print $6}')
kl=$( echo "scale=2; $cb / 1000 " | bc )
kl2=$( echo "scale=2; $kl * 100 " | bc )
echo "当前时间 `date +%H时%M分%S秒` 内存占用了 $kl2 %"
if [ $kl2 \> 50  ]
then
echo -e "\033[31m 当前内存占用率超过了50% \033[0m"
fi



cb1=$(sar -u 1 2 |grep "平均时间" | awk '{print $8}')
kl3=$( echo "scale=2; 100 - $cb1  " | bc )
echo "当前时间 `date +%H时%M分%S秒` cpu占用率为$kl3 %"
if [ $kl3 \>  50 ]
then
echo -e "\033[31m 当前cpu占用率超过了50% \033[0m"
fi



cb2=$(df -m |grep "/dev/mapper/centos-root" | awk '{print $5}' |awk -F % '{print $1}')
echo "当前根的占有率为 $cb2"
if [ $cb2 -ge 50  ]
then
echo -e "\033[31m 当前根占用率超过了50% \033[0m"
fi





 

你可能感兴趣的:(centos,linux,运维)