title: High CPU usage caused ec2 to go down but cloudwatch shows CPU usage within limits
body: <p>Recently, we faced downtime for our website. The two ec2 instances on which the website is hosted are behind ELB. We received 2 alerts from ELB that the latency is high and both the nodes are unhealthy. Luckily, I was able to ssh the ec2.</p>
  
  <p>Command "ps aux --sort=-%cpu" on the ec2 showed that one of the process had taken up 97% of the CPU. I killed that process and the server passed the health check of the ELB and the website was up.</p>
  
  <p>The major concern here is AWS Cloudwatch showed that the maximum CPU usage was around 70%. As a result, it did not trigger my alarm which was set for 80%.</p>
  
  <p>I understand that the CPU metrics shown by ps and top commands will always be different from that of cloudwatch due to virtualization. Reading other posts about it, all the posts have discussed about top command showing less CPU usage than cloudwatch. However, in my case it has been the reverse. I need some help understanding the reason behind it.</p>
  
  <p>Also, I checked and found that there were no memory/network issues.</p>
  
  <p>Can anyone help me here. What can I do here so that I am alerted before things go wrong.</p>
  
  <p>EDIT :
  Below are the CPU credit usage and balance charts</p>
  
  <p><a href="https://i.stack.imgur.com/tjZNX.png" rel="nofollow noreferrer">CPU Credit usage</a></p>
  
  <p><a href="https://i.stack.imgur.com/9CFgr.png" rel="nofollow noreferrer">CPU credit balance</a></p>