2

I am running a laravel application on a Ubuntu 14.04 digital ocean vps and I am using New Relic to monitor the server.

I got an email alert that my CPU usage was above 80%. I logged in to New Relic and now it's showing my CPU usage at 99% for 18 hours now. But when I log into my shell and run 'top' the CPU usage of the processes don't even sum up to 10%.

What could be wrong? Which are other commands I could run to check the real usage and what is using it so much? (Perhaps an infinite loop on the application?)

This is my htop result:

enter image description here

And this is htop after shift+K

enter image description here

Any links or help would be greatly appreciated.

4
  • 2
    My first question is: What properly written PHP process has a run-duration of 1h24 minutes? – Otheus Nov 6 '15 at 19:31
  • Maybe Otheus's attitude would make sense if we were in the 90's, but 'Why are you using PHP for that' this is totally not the way to respond to a unix system admin question – karimkorun Jul 16 '18 at 13:44
  • 1
    that htop seems to be showing 100% cpu use... – rogerdpack Sep 29 '19 at 4:19
  • Malware hides its own processes. Out of curiosity, do you have a /etc/ld.so.preload file? If so, is there anything suspicious in it. – kbulgrien Oct 8 '20 at 2:01
0

I had a similar problem and I did run TOP command in background and redirect it to a txt file

top > top.txt &

Thank you can see which process waste your CPU

0

There are a few options. My preference is the program htop which isn't generally installed by default but is available for almost all distros. It gives you the same info as top but with a MUCH richer feature set. It's great for interactively finding the problem process but it's not great for scripting. If you want to incorporate something into a monitoring script the command ps -eo pid,pcpu,comm will be your friend. It prints all of the current processes along with their PID and CPU usage in a fairly easy-to-parse format.

9
  • htop shows the same as top, the sum of all usage is about 9%. the other command ps... shows everything at 0.0, some at 0.2 – sigmawf Nov 6 '15 at 17:41
  • What is the load average on the server (it's shown in the top right corner of htop)? – David King Nov 6 '15 at 17:54
  • 1.22, 1.30, 1.31 – sigmawf Nov 6 '15 at 18:10
  • and CPU that show on top of htop, shows 100% – sigmawf Nov 6 '15 at 18:10
  • edited the question with more information – sigmawf Nov 6 '15 at 18:22
0

I'm not sure what's going on, but my guess is that the individual process's %CPU column isn't telling you what you think it tells you. From top's manpage:

  k: %CPU  --  CPU usage
  The task’s share of the elapsed CPU time since the last screen update,
  expressed as a percentage of total CPU time. 

Let's say you're refreshing every 4 seconds. The total CPU time it consumed in those 2 seconds is 6% over those 4 seconds. But let's say in one of those seconds, it spurted and used 24% of CPU time. I'm not saying this is happening, but it could be.

I am happy with top here. I can see CPU usage broken down by CPU and further by user, sys, nice, idle, wait (on I/O), servicing hardware and software interrupts (hi, si). You can probably get this in htop as well. As long as you have 1 CPU that is at least 20% idle, there's little to actually worry about, unless your fan is bothering you. But if you're worried, maybe what's happening is %wait and %hi/%si are very high, in which case no individual process is having a high CPU usage, but rather, the kernel is very very busy for some reason.

1
  • You can get detailed cpu time in htop via the setup menu but idle is never included in cpu usage stats. If the cpu was 20% idle that would show up in htop even without detailed stats – David King Nov 6 '15 at 21:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.