Tech Tutorial: 200.1 Measure and Troubleshoot Resource Usage #
Introduction #
In system administration, it’s crucial to understand how resources such as CPU, memory, disk, and network are utilized and how they can be monitored effectively. A deep understanding of resource usage helps in optimizing performance and troubleshooting issues that may arise in a Linux environment. This tutorial aims to equip candidates with the knowledge and tools to measure hardware resource and network bandwidth, and identify and troubleshoot resource problems.
Key Knowledge Areas #
- Understanding of system resources
- Tools to monitor system resources
- Identifying high resource usage
- Troubleshooting resource issues
Utilities #
top
vmstat
iostat
iotop
free
uptime
ps
mpstat
pidstat
tload
netstat
ifstat
Step-by-Step Guide #
In this section, we will explore each utility, providing detailed examples and explanations of their use in monitoring and troubleshooting.
1. Monitoring with top
#
The top
command provides a dynamic real-time view of a running system. It can display system summary information and a list of processes or threads currently being managed by the Linux kernel.
top
Key Metrics: #
- PID: Process ID.
- USER: User name of the process owner.
- PR: Priority of the task.
- NI: The nice value of the task.
- VIRT: Virtual memory used by the process.
- RES: Resident memory used by the process.
- SHR: Shared memory of the process.
- S: Status of the process (sleeping, running, stopped, etc).
- %CPU: The percentage of the CPU used by the process.
- %MEM: The percentage of RAM used by the process.
2. Using vmstat
#
vmstat
reports information about processes, memory, paging, block IO, traps, and cpu activity.
vmstat 1 5
This command will display system information every 1 second for 5 intervals.
Key Outputs: #
- procs.r: Number of processes waiting for run time.
- procs.b: Number of processes in uninterruptible sleep.
- memory.swpd: Used virtual memory.
- memory.free: Idle memory.
- cpu.us: Time spent running non-kernel code.
3. Disk I/O with iostat
#
iostat
is used for monitoring system input/output device loading by observing the time the devices are active in relation to their average transfer rates.
iostat -xz 1 5
This will provide detailed disk statistics every second, repeated five times.
Key Outputs: #
- %util: Percentage of CPU time during which I/O requests were issued to the device.
- r/s: Read requests per second.
- w/s: Write requests per second.
4. Real-time I/O with iotop
#
iotop
monitors disk I/O usage information output by the kernel and displays a table of current I/O usage by processes.
sudo iotop -o
5. Checking Memory with free
#
free
displays the total amount of free and used physical and swap memory in the system.
free -h
6. System Uptime with uptime
#
uptime
shows how long the system has been running.
uptime
7. Process Details with ps
#
ps
provides a snapshot of the current processes.
ps aux
8. CPU Performance with mpstat
#
mpstat
displays CPU statistics.
mpstat -P ALL 1 5
9. Detailed Process Statistics with pidstat
#
pidstat
is used for monitoring individual tasks in real-time.
pidstat 1 5
10. Terminal Load Average with tload
#
tload
prints a graphical representation of system load average to the terminal.
tload
11. Network Connections with netstat
#
netstat
prints network connections, routing tables, interface statistics, masquerade connections, and multicast memberships.
netstat -tulnp
12. Interface Statistics with ifstat
#
ifstat
reports network interface statistics.
ifstat 1 5
Conclusion #
Monitoring and troubleshooting are integral parts of managing a Linux system effectively. By mastering the utilities discussed, candidates can ensure systems run efficiently and are able to quickly identify and resolve issues related to resource usage. Regular practice with these tools will help in developing a deeper understanding of system behaviors and performance management.