Linux – Top showing 64% idle on first screen or batch run, while there is no idle time at all

linuxtopUbuntuubuntu-12.04vmstat

I'm running a quite heavy number crunching thing on a few 4 core servers, all running Ubuntu Precise Pangolin LTS 64 bit, in the cloud (so I suppose in a virtualized environment).

To monitor the cpu usage, i wrote a .sh that uses "top -b -n 1" (that is a single run of top, only the first "frame") and merges it with some other data, to write a small report.

However, top always reported 64% idle on the cpus line, for each server, even if I was quite sure all four cores were 100% busy.

In fact, running top interactively, in the first frame it reports 64% idle time, but as soon as it refresh it reports correct (nearly 0% idle) data.

vmstat too, in the cpu column, always reports 64% idle time on the first line, and then starts reporting (supposedly) real data.

Why is it? Is it a bug in top/vmstat or in the kernel? Or is it a known side effect of how cpu % is measured? Why always 64%?

cpu load is instead always correct (around 4).

Best Answer

This is because top, vmstat, iostat all in their first run collect data since the last reboot time of the system.

And the successive iterations run on the sampling period that you specify. So, in the first run of top, you will see the %idle time because from the time of reboot to the time of running top, it was that much % idle. But in next iterations, since it is busy it doesn't show any %idle.

Exclude the first iteration and try sampling over the interval you want.

Related Topic