Eagle eye on CPU usage

How to monitor CPU usage and server load.

In shared hosting or cloud hosting monitoring CPU usage and high load is essential part.

What is server load and when it shall considered as overloaded ?

Server could get overload because of excessive usage of CPU / Disk and RAM. We will learn how to monitor and know there is high CPU usage on server. Generally server load upto 1 for a single CPU server indicates very stable server. Server load upto 5 means it is bit overload but still nothing to worry but above 5 there is something wrong and user need to watch server load closely.

Commands to check server load.

1: w

2:uptime

3: top -d2

If user have server with multiple CPUs then normal server load range would vary for him accordingly. Like for server with 4 CPUs very stable server load is 4 and upto 16 server bit overloaded and above 16 user need to take care of CPU usage. Another important factor should be considered while monitoring server load is CPU %idle.

 

Administrator shall check CPU %idle if it is more than 30% then it can sit and allow to run processes/applications on server without worrying about server load. If it is less than 30% then services/application running on server will become less responsive and that time he need find and fix processes causing high CPU usage.

How to check %idle CPU ?

use command sar -u 1 1 this will show you present status of idle CPU in following example it is 85% which means server is stable and all applications running on server and responding quickly.

To check historical CPU idle% use command sar -u . Below is script which you can add in cronjob to monitor idle CPU usage. This script will monitor average “idle CPU” for 3 mins. If it get less than 30% then it will send an email to you. I recommend to set cron job every after 10 mins.

——————-

sar -u 10 3 | grep Average | awk '{print $NF}' > idlecpu
idlecpu=`cat idlecpu | cut -d. -f1`
echo $idlecpu
critical=30
if test $idlecpu -lt $critical
then
echo "CPU usage is high"
echo "Idle CPU is $idlecpu, this is critical. Timestamp `date` " | mail -s "Idle CPU % is less than 30" admin@midnight-cafe.com
else
if test $idlecpu -gt $critical
then
echo "CPU usage is okay"
else
echo "CPU usage is high"
echo "Idle CPU is $idlecpu, this is critical. Timestamp `date` " | mail -s "Idle CPU % is less than 30" admin@midnight-cafe.com
fi
fi
rm -f /home/idlecpu

——————-

Leave a Reply

Your email address will not be published. Required fields are marked *