CPU Usage | Process   «Prev  Next»
Lesson 3Using vmstat to monitor CPU consumption
Objective Execute and interpret vmstat.

Monitor CPU Consumption using vmstat

In addition to the UNIX ps command, other OS utilities can be used to monitor CPU consumption. The most common UNIX utility is the vmstat utility. While the ps command shows the instantaneous CPU consumption of an individual process, vmstat shows the total CPU consumption for all of the CPUs on your database server.
Note: This course does not cover UNIX tools such as top and glance because they are not available on all UNIX platforms. These tools also can be used to monitor CPU consumption.
The vmstat command provides valuable information about the state of our database server. There are five columns in vmstat that are important for you to learn:

How can the vmstat utility be used to monitor CPU consumption?

The vmstat utility is a Unix-like system utility that provides information about system processes, memory, paging, block I/O, traps, and CPU activity. It can be used to monitor CPU consumption on a system.
When you run vmstat, you will see output that provides information about system activity in real-time. The first line of the output shows a summary of the CPU activity, including the following fields:
  1. r: the number of runnable processes waiting for CPU time
  2. b: the number of processes in uninterruptible sleep (i.e., waiting for disk I/O)
  3. us: the amount of CPU time spent executing user-level processes (in percent)
  4. sy: the amount of CPU time spent executing system-level processes (in percent)
  5. id: the amount of CPU time that was idle (in percent)

Here's an example of how to use the vmstat utility to monitor CPU consumption:
$ vmstat 1

The 1 argument specifies the interval in seconds at which the utility should update the display. In this example, the display will be updated every second, so you will see a real-time view of the CPU consumption on your system.
You can use the output from vmstat to get a sense of how much CPU time is being used by user-level processes (us), system-level processes (sy), and the amount of time that the CPU is idle (id). If the us and sy values are high, it may indicate that the CPU is under heavy load and may be a cause of performance issues on your system.

The vmstat output
The vmstat output

Identifying CPU bottlenecks

When you see 100% CPU usage in conjunction with run queue, (r) values greater than the number of CPUs, you have identified a CPU bottleneck.
A CPU (sy + us) at 100% does not necessarily mean you have a CPU problem. The OS is designed to make the CPUs perform at their top capacity and it is not uncommon to see busy CPUs that do not have a CPU bottleneck. Be sure to check this against the run queue values.

Remedying CPU problems

The only was to remedy an overloaded CPU is to:
  1. Reduce CPU consumption
  2. Add additional CPUs
  3. Upgrade the existing CPUs to faster processors

The next lesson demonstrates techniques for changing CPU dispatching priorities.

vmstat Output - Quiz

First, click the Quiz link below to try interpreting the output from a vmstat session.
vmstat Output - Quiz