Monitoring System Resources
1. Viewing Memory Usage
| Command | Description | Notes |
|---|---|---|
| free -h | Displays memory usage in a human-readable format | Shows total, used, and free memory including swap |
| cat /proc/meminfo | Displays detailed memory statistics from kernel | Provides extensive memory metrics like buffers, cache, and slab |
| top | Real-time view of system processes and memory usage | Press 'M' to sort by memory usage |
| htop | Enhanced version of top with better UI | Interactive process viewer with color-coded memory display |
Example: Using free -h to view memory usage
$ free -h
total used free shared buff/cache available
Mem: 15Gi 3.2Gi 6.1Gi 204Mi 6.2Gi 11Gi
Swap: 2.0Gi 0B 2.0Gi
Example: Using cat /proc/meminfo to view detailed memory info
$ cat /proc/meminfo | grep -E "(MemTotal|MemFree|Buffers|Cached)"
MemTotal: 16384000 kB
MemFree: 6456320 kB
Buffers: 123456 kB
Cached: 5432100 kB
2. Monitoring CPU Usage
| Command | Description | Notes |
|---|---|---|
| top | Real-time display of running processes and system resource usage | Press Shift+M to sort by memory usage, Shift+P to sort by CPU usage |
| htop | Enhanced version of top with better UI and features |
Requires installation; more user-friendly than top |
| ps aux | Report a snapshot of current processes | Use ps aux | grep <process> to filter results |
| vmstat | Report virtual memory statistics | Use vmstat 1 5 to show stats every second for 5 times |
| sar | System Activity Reporter from sysstat package |
Can log and analyze historical data; requires sysstat package |
3. Displaying Load Average
| Command | Description | Example Output |
|---|---|---|
| uptime | Displays system uptime, number of users, and load averages over 1, 5, and 15 minutes | 14:23:45 up 2 days, 3:15, 2 users, load average: 0.15, 0.20, 0.25 |
| w | Shows logged-in users and their processes, including load averages | |
| loadavg | Displays load average from /proc/loadavg file | 0.15 0.20 0.25 2/345 12345 |
Example: Interpreting Load Average
uptime
# Output:
# 14:23:45 up 2 days, 3:15, 2 users, load average: 0.15, 0.20, 0.25
# Interpretation:
# - Load average over last minute: 0.15 (low)
# - Load average over 5 minutes: 0.20 (low)
# - Load average over 15 minutes: 0.25 (low)
Note: Load average is the number of processes in the run queue (waiting for CPU or I/O) averaged over 1, 5, and 15 minutes. A load average of 1.0 means one process is running or waiting on a CPU.
4. Monitoring I/O Statistics
| Command | Description | Example |
|---|---|---|
| iostat | Reports CPU and I/O statistics for devices and partitions | iostat 1 5 - Reports stats every second for 5 times |
| iotop | Shows I/O usage by processes in real-time | iotop -a - Shows accumulated I/O by processes |
| vmstat | Reports virtual memory statistics including I/O | vmstat 2 5 - Reports every 2 seconds for 5 times |
| pidstat | Reports I/O statistics for specific processes | pidstat -d 1 3 - Reports I/O stats every second for 3 times |
Note:
iostat requires the sysstat package to be installed.
Warning:
iotop may not be available on all Linux distributions.
5. Viewing Real-Time Disk Activity
| Command | Description | Notes |
|---|---|---|
| iostat | Reports CPU and I/O statistics for devices and partitions | Part of sysstat package |
| iotop | Shows real-time I/O usage by processes | Requires root or CAP_SYS_ADMIN capability |
| vmstat | Reports virtual memory statistics including disk I/O | Part of sysstat package |
| dstat | Aggregates system statistics including disk I/O | More flexible than iostat, can combine multiple stats |
Note:
iostat and iotop require the sysstat package to be installed on most distributions.
Warning:
iotop may not show accurate data if the system is under heavy load or if processes are not actively I/O bound.
6. Checking System Temperature
| Command | Description | Notes |
|---|---|---|
| sensors | Display sensor readings from hardware monitors | Part of lm-sensors package |
| cat /sys/class/thermal/thermal_zone*/temp | Read raw temperature values from thermal zones | Provides Celsius temperature in millidegree units |
| watch -n 1 'cat /sys/class/thermal/thermal_zone*/temp' | Continuously monitor temperature changes | Useful for real-time monitoring |
Example: Using sensors command
sensors
Adapter: Virtual device
coretemp-isa-0000
Package id 0: +45.0°C (high = +80.0°C, critical = +100.0°C)
Core 0: +43.0°C (high = +80.0°C, critical = +100.0°C)
Core 1: +45.0°C (high = +80.0°C, critical = +100.0°C)
7. Monitoring Network Bandwidth
| Tool | Command | Description | Notes |
|---|---|---|---|
| iftop | iftop -i eth0 |
Real-time bandwidth usage per connection | Requires root or CAP_NET_ADMIN |
| nethogs | nethogs eth0 |
Shows bandwidth per process | Displays data in KB/s |
| vnstat | vnstat -d |
Daily network statistics | Needs database setup with vnstat -u |
| ss | ss -tuln |
Socket statistics including network usage | Can filter by protocol or state |
| netstat | netstat -i |
Network interface statistics | Shows packet counts and errors |
Example: Using iftop to monitor bandwidth
iftop -i eth0
# Displays real-time bandwidth usage per connection
# Shows total bandwidth and individual connections
Example: Using nethogs to view per-process bandwidth
nethogs eth0
# Shows bandwidth usage per process
# Displays KB/s for each process
Note:
iftop and nethogs require root privileges or specific capabilities to capture network traffic.
Key Features of Network Monitoring Tools
- iftop: Real-time view of bandwidth usage per connection
- nethogs: Shows bandwidth usage per process
- vnstat: Provides historical daily network statistics
- ss/netstat: Displays socket and interface statistics
8. Using System Activity Reporter
| Option | Description | Notes |
|---|---|---|
| sar -u | Reports CPU utilization | Shows %idle, %user, %system |
| sar -r | Reports memory utilization | Shows free, used, and cached memory |
| sar -d | Reports disk I/O activity | Shows device read/write stats |
| sar -w | Reports context switches and process activity | Shows system load and process creation rate |
Note: The
sar command requires the sysstat package to be installed.9. Viewing System Statistics
| Command | Description | Example Output |
|---|---|---|
| top | Real-time view of running processes and system statistics | |
| htop | Enhanced version of top with better UI and process management | |
| vmstat | Virtual memory statistics including CPU, memory, and I/O | |
| iostat | Input/output statistics for devices and partitions | |
| sar | System activity reporter from sysstat package | |
Note: The
top command updates in real-time. Use q to quit.
Warning:
iostat requires the sysstat package to be installed.
10. Analyzing System Performance
| Metric | Description | Command | Notes |
|---|---|---|---|
| CPU Usage | Percentage of CPU time used by processes | top |
Real-time view of system processes |
| Memory Usage | Amount of RAM used and available | free -h |
Human-readable format with units |
| Disk I/O | Input/output operations on storage devices | iostat |
Requires sysstat package |
| Network Traffic | Data transfer rates over network interfaces | iftop |
Real-time bandwidth monitoring |
| Load Average | Average system load over 1, 5, and 15 minutes | uptime |
Indicates system workload intensity |
Example: Using top to analyze CPU usage
# Run top command
top
# Sample output:
# PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
# 1234 user 20 0 256789 123456 45678 S 12.5 0.3 0:05.67 firefox
# 5678 root 20 0 12345 6789 1234 S 5.0 0.1 0:01.23 systemd
Example: Monitoring disk I/O with iostat
# Install sysstat if not present
sudo apt install sysstat
# Run iostat to monitor I/O stats every 2 seconds
iostat -x 2
# Sample output:
# Device: rrqm/s wrqm/s r/s w/s rMB/s wMB/s avgrq-sz avgqu-sz await svctm %util
# sda 0.00 0.00 2.00 1.00 0.01 0.02 1.50 0.00 1.00 0.50 0.30
Note: Use
htop for a more interactive and user-friendly version of top.
Warning:
iostat requires the sysstat package to be installed on some distributions.
11. Viewing Open Files and Processes
| Command | Description | Example |
|---|---|---|
| ps | Report or control processes | ps aux | grep firefox |
| top | Display and update sorted process information | top -p 1234 |
| htop | Enhanced version of top with better UI | htop |
| lsof | List open files and associated processes | lsof -i :80 |
| netstat | Display network connections, routing tables, interface statistics | netstat -tuln | grep :80 |
Note: The
ps command can be used with various options like aux, ef, or o to customize output format.
Warning: Using
sudo with commands like netstat or lsof may be required to view all network connections and file descriptors.