Home > Enterprise >  Abrruptly CPU usage goes to 99% in ec2
Abrruptly CPU usage goes to 99% in ec2

Time:11-03

I have an EC2 in aws. after every few hours I see the CPU usage goes to 99%. I am unable to find the process causing this issue.

Is there any flag which i can set to see the culprit process when I restart the ec2 instance? I am running ubuntu 20 in the EC2 and the instance type is t2 micro. Below are processes that I am running

  1. Mysql
  2. Mongo
  3. A spring boot service

I think if these process is causing the issue then it should happen after few minutes of when I start these services but it is happening in absurd way after few hours

CodePudding user response:

You can use the top program to see what's consuming the most CPU.

This program is normally used from a terminal window, as it refreshes the display every few seconds (by default, 10, but you can change this). If you consistently see this performance issue, then simply log in, run top, and look at what it says are the top CPU consumers.

You can also use it in the case where CPU consumption spikes and then reduces: if that consistently happens with one program, then its total CPU will reflect that fact. Change the sort order to select the TIME field.

Finally, if you don't want to keep a terminal window open, you can run top in "batch" mode and write the output to a file. Here's how to invoke it every second, and only capture the top 10 CPU consumers:

while true ; do top -b -n 1 | head -17 >> /tmp/top.log ; sleep 1 ; done
  • Related