How do I see the CPU load of a server?

4

What is the command to see CPU load of a RedHat Linux server?

alwbtc

Posted 2012-07-29T13:29:32.003

Reputation: 2 367

Answers

12

top - The classic approach

enter image description here

htop - The colorful approach

enter image description here

mpstat - The plain and simple

enter image description here

Notes

If you're wondering how to read the CPU load from the output of top or mpstat, please look at the idle values they print. The CPU load is the difference between 100% and the displayed value.

If you think that that's weird, please see our question: How is the percentage of CPU usage calculated?

Der Hochstapler

Posted 2012-07-29T13:29:32.003

Reputation: 77 228

Thanks, but it gives cpu load per process. I want to see total CPU load, for example 85% – alwbtc – 2012-07-29T13:55:22.530

If you look at the top line in the first image (program top). It has the line load average. The three values after that are the load average over time. – Hennes – 2012-07-29T14:06:14.047

1

@alwbtc: They all give you that in various forms. If you look at the output of mpstat you see an idle value of 99.24. This means I have a CPU load of 0.76%. As @Hennes notes, there is also the load average displayed, which is another indicator of CPU load. If you really only want a command that returns a single percent value, you'll probably want to post-process the output of mpstat.

– Der Hochstapler – 2012-07-29T14:17:44.547

4

Personally I think looking at the average load of a period is best. Otherwise you might get quite different values depending on the timing. (e.g. enter a command and press [Enter] might yield a different result than if you pressed [Enter] a fraction of a second later.)

Some ways of checking the load average are:

  1. cat /proc/loadavg

    beetle:/proc>cat loadavg
    0.45 0.19 0.13 1/263 17588

  2. uptime also shows the load.

    toad:/home/hennes>uptime
    4:03PM  up 155 days, 19:12, 38 users, load averages: 0.16, 0.17, 0.12

  3. Via top. Look at he line load averages: in the upper right corner.

  4. htop

  5. mpstat

  6. systat (e.g. systat -vmstat)


Most of these programs give you three numbers:

  • The load average during the last minute.
  • The load average during the last five minutes
  • The load average during the last fifteen minutes.

If you have one core then a load of 1 more or less indicates that core is busy 100% of the time. This number can exceed 1 (or 100%). If that happens there is on average more then one process in the run queue.

If you have multiple CPU's then 100% (or 1.00) means that one average one core is busy all the time. E.g. with 4 core this could mean 1 core running flat out and 3 cores being idle. Or 4 cores running ¼ of the time.

Hennes

Posted 2012-07-29T13:29:32.003

Reputation: 60 739

just for sake of explicity: if i have a 24 cpu machine and uptime says load average: 65.12, 64.98, 64.16 then this machine is heavily overloaded? – helt – 2017-05-18T08:15:33.093

No. It might mean that. But there are reasons why processses could be iin the run queue without actually using CPU time. (e.g. when waiting for an action). – Hennes – 2017-05-18T11:27:00.253

Thanks, load average 0.45 means: 45% of CPU power is used? – alwbtc – 2012-07-30T09:57:22.820

0.45 means that 45 of a single CPU core is used. 45% used, 55% idle. ---- If you have two core and get a load of 0.45 then 45% of a core is used and 155% is idle ; or both core are used 22.5% of the time and both core are idle 77.5% of the time. – Hennes – 2012-07-30T12:19:52.550