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:
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:
- r: the number of runnable processes waiting for CPU time
- b: the number of processes in uninterruptible sleep (i.e., waiting for disk I/O)
- us: the amount of CPU time spent executing user-level processes (in percent)
- sy: the amount of CPU time spent executing system-level processes (in percent)
- 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.
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.