1

I am using vmstat on ubuntu linux to get cpu usage. My current cpu is very busy at almost 100%. If I run vmstat like below:

$ vmstat     
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 8  1      0 6383924 1287224 18123836    0    0     2    53    2   16  1  1 98  0  0

it shows the cpu idle is 98%. But if I run it with a delay and count like below:

$ vmstat 2 2
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 5  1      0 6491296 1287268 18128956    0    0     2    53    3   17  1  1 98  0  0
 4  1      0 6491992 1287268 18129080    0    0     0  2264 11142 17980 98  2  0  0  0

it shows the correct cpu usage starting from the second time. My question is why it can't output the correct value for the first time run.

1
  • why is it a normal behaviour? If it is true, that means I can't run vmstat without any parameters because it always returns wrong output. Jan 24, 2018 at 1:01

1 Answer 1

2

From man vmstat (bold emphasis added by me):

SYNOPSIS

vmstat [options] [delay [count]]

DESCRIPTION

vmstat reports information about processes, memory, paging, block IO, traps, disks and cpu activity.

The first report produced gives averages since the last reboot.

Additional reports give information on a sampling period of length delay. The process and memory reports are instantaneous in either case.

OPTIONS

delay The delay between updates in seconds. If no delay is specified, only one report is printed with the average values since boot.

count Number of updates. In absence of count, when delay is defined, default is infinite.

[...]

1
  • man to the rescue. I remembered something on that line, but could not put my finger to it. Jan 24, 2018 at 1:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .