cpu from 13% to 100% in one minute

I have a website (it’s the only site hosted on the droplet) and sometimes (about 1 time each month, but not on the same day) the CPU usage goes through the roof. I have absolutely no idea what’s causing it, but in 1 minute the CPU usage goes from 5-13% straight to 100% causing the server to hang.

Disk I/0 also peaks and memory usage goes from 30% to 70%.

I have checked Google Analytics to check if there is a sudden increase in visitors as my client thought this happened after posting an instagram story. However, the largest visitors at the same time is only 15 which is unlikely to cause this.

I have no clue where to start looking what might be causing these issues. Any hints?


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

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.

I had the same problem now I found a solution I hope it will work for you. actually, someone was attacking with a brute force attack on my website so why my website was down and the graph shows CPU 100% usage.

First of all, check which application takes much usage so enter the command “top” it will show the real-time CPU usage. in my case, PHP-fpm was taking 95% usage.

Now you have to check your Nginx log file. “sudo tail -f /var/log/nginx/access.log” it will show the error or bad gateway access details… now you have to copy the IP address which is repeated a lot of times you have to block it.

You can block IP by using this command “iptables -I INPUT -s -j DROP

I hope this issue will be resolved.

I found that my unicorn.log file in /var/log/unicorn was over 10gb in size. Deleting that helped my 100% CPU issue.

No backups running at that time…

Is your script something that logs everything or should you manually trigger it to log? Because by the time I notice it, the only way to resolve the problem is to restart the server.

Are you running any kind of backups?

You could try adding an extra monitoring to the server.

I have a short script that would check the current MySQL connections, Apache connections, available memory, CPU usage and etc. then this information gets dumped into a log file. You could then use the log file to gather more information about the spike.

If you wish I could provide you with the script or maybe help you develop another one more suitable for your needs.