System Performance Monitoring Commands (Memory, Disk I/O, CPU)
Memory Usage Monitoring
Virtual memory extends physical memory using disk space, where inactive memory pages are swapped out to disk to free up RAM for active processes. When needed again, these pages are read back into memory transparently to the user. On Linux systems, virtual memory typically refers to swap partitions, which are organized into 4KB pages.
Each process requests virtual memory upon startup. The kernel either grants or denies the request. Actual memory usage (RSS) reflects how much physical RAM a process currently occupies. The ps command displays both virtual size (VSZ) and resident set size (RSS).
The free command provides an overview of system memory consumption:
free -h
To examine memory usage per process:
pmap -d <PID>
Use ps to list processes with detailed memory metrics:
ps -eo pid,comm,args,pcpu,rsz,vsz,stime,user,uid
Filter results for specific users or processes:
ps -eo pid,comm,args,pcpu,rsz,vsz,stime,user,uid | grep root | sort -nrk5
To identify top memory-consuming processes:
ps -auxf | sort -nr -k 4 | head -10
Disk I/O and Network Monitoring
For I/O performance analysis, use iostat:
iostat -x
Key metrics to monitor include rkB/s and wkB/s, indicating read and write throughput in kilobytes per second respectively.
CPU Performance Diagnostics
Critical CPU metrics include load average and utilization percentage:
- CPU utilization above 50% warrants attention.
- Above 70%, immediate investigation is required.
- At 90% or higher, the system is under severe stress.
Load average exceeding the number of CPU cores indicates increasing workload. If it exceeds twice the core count, the system is heavily loaded.
Diagnostic approach:
- Identify processes with high CPU usage.
- Locate threads within those processes consuming most CPU.
- Capture thread stack traces.
- Analyze execution flow.
Example simulation of 100% CPU load:
stress --cpu 1 --timeout 600
Monitor with top and observe the process with highest CPU usage. Note its PID and analyze threads:
top -Hp <PID>
Capture thread dump using:
jstack -l <PID> > ./thread_dump.log
Additional utilities for CPU monitoring:
List top CPU-consuming processes:
ps -auxf | sort -nr -k 3 | head -10
Check system load:
watch -d uptime
Monitor individual CPU usage:
mpstat -P ALL 5