Note:
- This tutorial is available in an Oracle-provided free lab environment.
- It uses example values for Oracle Cloud Infrastructure credentials, tenancy, and compartments. When completing your lab, substitute these values with ones specific to your cloud environment.
Monitor system resources on Oracle Linux
Introduction
In this tutorial you work with the Oracle Linux vmstat, mpstat, and top to monitor system resource usage.
Monitoring the usage of system resourses is useful for detecting issues which can adversely affect system performance.
Background
Oracle Linux provides tools for monitoring and analyzing system resource usage, as well as tracing tools for diagnosing performance issues in multiple processes and related threads.
Objectives
- Explore the
vmstatcommand - Explore the
mpstatcommand - Explore the
topcommand - Use
vmstatandmpstat, andtop - Examine command output from
vmstat,mpstat, andtop
What Do You Need?
A client system with Oracle Linux 8 or later installed.
Note: When using the free lab environment, see Oracle Linux Lab Basics for connection and other usage instructions.
Explore and Use vmstat Command Options
vmstat shows how much virtual memory there is and how much is free. The command also shows paging activity. You can observe page-ins and page-outs as they occur on the system.
You might consider maximizing your viewing area by using the Hide steps and the “Full screen” controls located in the task bar, as shown in the images.

Watch the video below for an overview on vmstat.
-
Run the
vmstatcommand without any options.vmstatThe command generates a single report. The output is broken into six sections:
procs,memory,swap,io,system, andcpu.-
The first two columns give information about processes:
-
ris the number of processes that are in a wait state. These are processes that are idle and waiting to run. -
bis the number of processes that were in sleep mode, and were interrupted since the last update.
-
-
The next four columns give information about memory:
-
swpdis the amount of used virtual memory. -
freeis the amount of idle memory. -
buffis the amount of memory used as buffers. -
cacheis the amount of memory used as cache.
-
-
The next two columns give information about swap:
-
siis the amount of memory swapped in from disk (per second). -
sois the amount of memory swapped out to disk (per second).Nonzero
siandsonumbers indicate that there is not enough physical memory, which causes the kernel to swap memory to disk.
-
-
The next two columns report Input/Output:
-
biis the number of blocks per second received from a block device. -
bois the number of blocks per second sent to a block device.
-
-
The next two columns give the following system information:
-
inis the number of interrupts per second, including the clock. -
csis the number of context switches per second.
-
-
The last five columns give the percentages of total CPU time:
-
usis the percentage of CPU cycles spent on user processes. -
syis the percentage of CPU cycles spent on system (kernel) processes. -
idis the percentage of CPU cycles spent idle. -
wais the percentage of CPU cycles spent waiting for I/O. -
stis the percentage of CPU cycles stolen from a virtual machine.
-
-
-
Run the command
vmstat 1(numerical one, and not the lowercase letterl) to view a continuous report for every second.vmstat 1- To terminate, press Ctrl+C.
-
Run the command
vmstat 7 4to run four reports seven seconds apart.vmstat 7 4The count option tells
vmstatthe number of reports to run (4), and the delay option (7) is the time interval between each report. -
Run the command
vmstat -sto display a table of various event counters and memory statistics.vmstat -s -
Run the command
vmstat -ato display active and inactive memory.vmstat -aThe
-aoption displays the amount ofactiveand inactive (inact) memory in thememorysection of the output. -
Run the command
vmstat -fto display the number of forks since the last boot.vmstat -f -
Run the command
vmstat -tto add a timestamp to the output.vmstat -t -
Run the command
vmstat -dto display disk usage statistics on the system.vmstat -d -
Run the command
vmstat -p sda1to create a report on a specific disk partition.vmstat -p sda1The output shows a summary for the partition, including the number or reads and writes.
Explore and Use mpstat Command Options
The mpstat command is used for collecting and displaying performance statistics for all logical CPUs in the system. When a CPU is occupied by a process, it is unavailable for processing other requests. These other processes must wait until the CPU is free.
Watch the video below for an overview on mpstat.
-
Run the command
mpstatwithout any options.mpstatThe first line displays the Linux kernel version, host name, current date, architecture, and number of CPUs on your system.
The first column in the next line provides a timestamp, with the remaining columns defined as follows:
-
CPUis the processor designated by the number starting at0or the keywordallindicating that statistics are calculated as averages among all processors. -
%useris the percentage of CPU used while executing applications at the user level. -
%niceis the percentage of CPU used while executing at the user level with nice priority. -
%sysis the percentage of CPU used while executing at the system (kernel) level.The
mpstatcommand does not include time spent servicing hardware and software interrupts. -
%iowaitis the percentage of time the CPUs were idle while the system had an outstanding disk I/O request. -
%irqis the percentage of time spent by the CPUs to service hardware interrupts. -
%softis the percentage of time spent by the CPUs to service software interrupts. -
%stealis the percentage of time spent in involuntary wait by the virtual CPU or CPUs while the hypervisor was servicing another virtual processor. -
%guestis the percentage of time spent by the CPUs to run a virtual processor. -
%gniceis the percentage of time spend by the CPUs to run a niced guest. -
%idleis the percentage of time that the CPU was (or the CPUs were) idle, and the system did not have an outstanding disk I/O request.
-
-
Run the command
mpstat 2 5to view CPU activity every two seconds for a total of five reports on all CPUs.mpstat 2 5The output prints one line of information a total of five times, and also prints an average.
-
Run the command
mpstat -P ALLto report CPU usage on each CPU.mpstat -P ALLThis output prints a single line of activity for all CPUs and for each CPU. Note:
mpstatalso prints the average CPU utilization for the specified period. -
Run the command
mpstat -P ALL 2 5to view CPU activity every two seconds on the CPUs.mpstat -P ALL 2 5This output prints CPU utilization statistics for each CPU 5 times at an interval of 2 seconds. Note: that
mpstatalso prints the average CPU utilization for the specified period. -
Run the command
mpstat -Ato print CPU utilization and interrupt statistics together in the same command output.mpstat -A
Explore the top Command
The top command provides an ongoing look at processor activity in real time. top displays a list of the most CPU-intensive processes or tasks on the system and provides a limited interactive interface for manipulating processes.
Watch the video below for an overview on top.
-
Run the
topcommand without any options for a point-in-time view of the CPU activity.topThe output refreshes every three seconds by default and divided into two main sections.
The upper section displays general information such as the load averages during the last 1, 5, and 15 minutes, the number of running and sleeping tasks, and overall CPU and memory usage.
-
Use the following to toggle the output displayed in the upper section on or off:
-
Enter the lowercase letter
l(Not numerical1) to toggle load average and uptime off and on. -
Enter
mto toggle memory and swap usage off and on. -
Enter
tto toggle memory and swap usage off and on.
-
The lower section displays a sorted list of processes, usually by CPU usage, along with their process ID numbers (PIDs), and the user who owns the process. In addition, the outputs displays running time and memory that the processes use.
The following describes the columns in the lower section:
-
PIDis the task’s unique process ID. -
USERis the effective username of the task’s owner. -
PRis the actual priority of the task. -
NIis the nice value of the task in the user-space.A negative value means a higher priority; and a positive value means a lower priority. The value of zero means a task’s priority does not effect when it executes.
-
VIRTis the total amount of virtual memory used by the task.This value includes all code, data, and shared libraries, plus pages that have been swapped out.
-
RESis the non-swapped physical memory or resident size a task is using. -
SHRis the amount of shared memory the task is using.This memory could potentially be shared with other processes.
-
Sis the status of the task. There are five states:-
DUninterruptible sleep -
RRunning -
SSleeping -
TTraced or stopped -
ZZombie
-
-
%CPUis the task’s share of the elapsed CPU time or CPU usage since the last screen update, expressed as a percentage of total CPU time. -
%MEMis the task’s currently used share of available physical memory or memory usage. -
TIME+is the total CPU time that the task has used since it started. -
COMMANDis the command-line or program name used to start a task.
-
-
Exit
topby entering Crtl+C.
Compare Command Output from vmstat, mpstat, and top
For this practice, you run various stress tests to emulate different loads on your lab system, and then use the vmstat, mpstat, and top commands to determine what they report for the different types of load.
Even though you run the tests as background processes, consider opening additional terminal windows for your comparisons.
Each additional window requires logging in to your lab instance using ssh to oracle@<IP_ADDRESS_OF_COMPUTE_INSTANCE>. Where <IP_ADDRESS_OF_COMPUTE_INSTANCE> is the IP address copied from the Oracle Cloud Console.
- After logging in, use the
sudo -icommand to switch to the root user.
-
Install the
stresstool.-
Use the
dnf repolistcommand to verify the status of theol8_developer_EPELrepository.dnf repolist ol8_developer_EPEL-
If the status is
enabled, proceed to installing thestresstool packages; otherwise, continue to “enabling” the repository. -
Enable the repository if the status is
disabledby using thednf conifg-managercommand.dnf config-manager --enable ol8_developer_EPEL
-
-
-
Run the
dnf installcommand to install thestresstool packages.dnf install stress -y -
Run the command
stress --dry-runto view an example of the command syntax. Take a moment and review the options in the example, along with the other command options listed.stress --dry-run -
Run the
vmstat 4 4, andmpstat 4 4commands to view a baseline of system activity. Specifically, notice the CPU percentages allocated to user and system (kernel) processes. These column should be close to zero0. Also note the amount of free memory.vmstat 4 4 mpstat 4 4 -
Run the command
stress --cputo emulate a compute-bound program, and run the command in the background. This command spawns eight compute-bound processes.stress --cpu 8 &-
Press return to return to the prompt.
-
Run the
ps -efcommand to view the runningstressprocesses. Pipe the output togrep stress.ps -ef | grep stress
-
-
Run the
vmstat 4 10command and note the values reported in the columns associated with CPU utilization.vmstat 4 10In a few moments, you should see the percentages under the
uscolumn reflect the load generated bystress. -
Run the command
mpstat 4 10to evaluate utilization of all the CPUs.mpstat 4 10 -
Run the command
mpstat -P ALL 4 10to evaluate utilization of each CPU.mpstat -P ALL 4 10 -
Run the
topcommand to examine CPU utilization by thestressprocesses.topAfter a few minutes, notice that the
stressprocesses are running at the highest priority. Exittopby entering a Ctrl+C. -
Run the
pkillcommand to terminate thestressprocesses.pkill stress -
Rerun the
vmstat 4 4, andmpstat 4 4commands to view a baseline of system activity. -
Run a new
stresscommand and add the--vmand--vm-bytesoptions to spawn memory activity on the system.stress --cpu 8 --vm 8 --vm-bytes 512M & -
Run
vmstat 4 10,mpstat -P ALL 4 10, andtopto evaluate the CPU and memory activity.vmstat 4 10 mpstat -P ALL 4 10 top- Exit
topby entering Crtl+C.
- Exit
-
Use the
pkillcommand to terminate thestressprocesses.pkill stress -
Rerun the
vmstat 4 4, andmpstat 4 4commands to view a baseline of system activity. -
Run a new
stresscommand and add the--iooption to spawn input/output activity on the system.stress --cpu 8 --vm 8 --vm-bytes 512M --io 8 & -
Run
vmstat 4 10,mpstat -P ALL 4 10, andtopto evaluate the CPU, memory, input/output activity.vmstat 4 10 mpstat -P ALL 4 10 top-
Exit
topby entering Crtl+C. -
Use
pkillto terminatestress.
-
More Learning Resources
Explore other labs on docs.oracle.com/learn or access more free learning content on the Oracle Learning YouTube channel. Additionally, visit education.oracle.com/learning-explorer to become an Oracle Learning Explorer.
For product documentation, visit Oracle Help Center.
Monitor system resources on Oracle Linux
F49121-07
May 2022
Copyright © 2021, Oracle and/or its affiliates.