Question

DigitalOcean monitoring triggered: CPU is running high

I have been getting email alerts on one of my droplets: DigitalOcean monitoring triggered: CPU is running high CPU Utilization Percent is currently at 99.83%, above setting of 70.00% for the last 5m then I get CPU Utilization Percent has returned to an acceptable level about twenty minutes later. These are at about 3 am. I have gotten these email alerts twice. Are they cause for concern? Is there something I can do about this?


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Hello,

In addition to what has already been mentioned, I’ve seen a similar problem here:

https://www.digitalocean.com/community/questions/how-to-find-the-processes-that-are-consuming-the-most-server-resources?comment=92511

I created a small Bash script that might be helpful in your case.

#!/bin/bash

timeNow=$(date "+%F_%H:%M")

filename="/root/processes_logs/log_${timeNow}.log"

if [ ! -d "/root/processes_logs" ]; then
    mkdir /root/processes_logs
fi

touch ${filename}

printf " ### Time of scan: $(date +%F_%H:%M) ### \n\n" >> ${filename}

###
printf "\n ################## RAM ################## \n" >> ${filename}

printf "\n ### Current Memory Usage: ### \n\n" >> ${filename}
free -tm >> ${filename}

printf "\n ### Top 10 processes by RAM usage: ### \n\n" >> ${filename}
ps aux | awk '{print $2, $4, $11}' | sort -k2rn | head -n 10 >> ${filename}

printf "\n ### RAM usage history for the last hour ###: \n\n" >> ${filename}
sar -r -s $(date "+%H" -d "1 hour ago"):$(date "+%M"):00 -e $(date "+%H"):$(date "+%M"):00 >> ${filename}

printf "\n ### Swap usage history for the last hour: ### \n\n" >> ${filename}
sar -S -s $(date "+%H" -d "1 hour ago"):$(date "+%M"):00 -e $(date "+%H"):$(date "+%M"):00 >> ${filename}

###
printf "\n\n ################## CPU ################## \n" >> ${filename}

printf "\n ### Current load: ### \n\n" >> ${filename}
uptime | cut -d' ' -f10-16 >> ${filename}

printf "\n ### Sar history for last hour: ### \n\n" >> ${filename}
sar -s $(date "+%H" -d "1 hour ago"):$(date "+%M"):00 -e $(date "+%H"):$(date "+%M"):00 >> ${filename}

###
printf "\n\n ################## Disk: ################## \n" >> ${filename}
df -h >> ${filename}

###
printf "\n\n ################## Apache ################## \n" >> ${filename}

printf "\n ### IPs Connected to the server: ### \n\n" >> ${filename}
netstat -tn 2>/dev/null | grep :80 | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -nr | head >> ${filename}
echo >> ${filename}

###
printf "\n\n ################## MySQL ################## \n" >> ${filename}

printf "\n ### MySQL uptime: ### \n\n" >> ${filename}
mysqladmin ver | grep Uptime >> ${filename}

printf "\n ### MySQL connections: ### \n\n" >> ${filename}
mysql -e "show status like '%onn%';" >> ${filename}

printf "\n ### MySQL processlist: ### \n\n" >> ${filename}
mysql -e "show full processlist;" >> ${filename}

You could try setting this up as a corn job to run every minute and it would record the processes on your server so later on you could analyze the results and determine what could be causing the spike.

Hope that this helps. Best, Bobby

Hey there!

Those alerts would mean that your droplet does have high CPU usage during the time they are sent. IF you have any scheduled jobs that run on your droplet those could be the cause of that increased load. I’d recommend you login when you get those alerts to verify what process on your droplet is using up the CPU. Using top and htop can give you a good idea of which process that is.

If you don’t want to wake up to check that you could run a script to log top CPU processes to a file.

Something like this may work: while true; do (echo "%CPU %MEM ARGS $(date)" && ps -e -o pcpu,pmem,args --sort=pcpu | cut -d" " -f1-5 | tail) >> ps.log; sleep 5; done

This will log the top 10 processes using CPU to a log file called ps.log every 5 seconds. You could modify that to not write so often as well by changing the sleep value.

Hope it helps! Nate