Monitor system resources on Oracle Linux
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 vmstat command
- Explore the mpstat command
- Explore the top command
- Use vmstat and mpstat , and top
- Examine command output from vmstat , mpstat , and top
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 .
- The first two columns give information about processes:
- r is the number of processes that are in a wait state. These are processes that are idle and waiting to run.
- b is the number of processes that were in sleep mode, and were interrupted since the last update.
- swpd is the amount of used virtual memory.
- free is the amount of idle memory.
- buff is the amount of memory used as buffers.
- cache is the amount of memory used as cache.
Nonzero si and so numbers indicate that there is not enough physical memory, which causes the kernel to swap memory to disk.
- bi is the number of blocks per second received from a block device.
- bo is the number of blocks per second sent to a block device.
- in is the number of interrupts per second, including the clock.
- cs is the number of context switches per second.
- us is the percentage of CPU cycles spent on user processes.
- sy is the percentage of CPU cycles spent on system (kernel) processes.
- id is the percentage of CPU cycles spent idle.
- wa is the percentage of CPU cycles spent waiting for I/O.
- st is the percentage of CPU cycles stolen from a virtual machine.
The count option tells vmstat the number of reports to run (4), and the delay option (7) is the time interval between each report.
The -a option displays the amount of active and inactive ( inact ) memory in the memory section of the output.
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 .
- CPU is the processor designated by the number starting at 0 or the keyword all indicating that statistics are calculated as averages among all processors.
- %user is the percentage of CPU used while executing applications at the user level.
- %nice is the percentage of CPU used while executing at the user level with nice priority.
- %sys is the percentage of CPU used while executing at the system (kernel) level.
This output prints a single line of activity for all CPUs and for each CPU. Note: mpstat also prints the average CPU utilization for the specified period.
This output prints CPU utilization statistics for each CPU 5 times at an interval of 2 seconds. Note: that mpstat also prints the average CPU utilization for the specified period.
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 top command without any options for a point-in-time view of the CPU activity.
- Use the following to toggle the output displayed in the upper section on or off:
- Enter the lowercase letter l (Not numerical 1 ) to toggle load average and uptime off and on.
- Enter m to toggle memory and swap usage off and on.
- Enter t to 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:
- PID is the task’s unique process ID.
- USER is the effective username of the task’s owner.
- PR is the actual priority of the task.
- NI is 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.
- D Uninterruptible sleep
- R Running
- S Sleeping
- T Traced or stopped
- Z Zombie
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@ . Where is the IP address copied from the Oracle Cloud Console.
dnf repolist ol8_developer_EPEL
- If the status is enabled , proceed to installing the stress tool packages; otherwise, continue to “enabling” the repository.
- Enable the repository if the status is disabled by using the dnf conifg-manager command.
dnf config-manager --enable ol8_developer_EPEL