Linux System Monitoring
System monitoring is essential for maintaining optimal performance, identifying bottlenecks, and troubleshooting issues. Linux provides comprehensive command-line tools for monitoring CPU, memory, disk, network, and process activity.
Overview
Linux system monitoring involves tracking various system resources and performance metrics:
- CPU Usage - Processor utilization and load averages
- Memory Usage - RAM and swap space utilization
- Disk I/O - Read/write operations and throughput
- Network Activity - Network traffic and connections
- Process Activity - Running processes and resource consumption
- System Load - Overall system performance metrics
Essential Monitoring Tools
| Tool | Purpose | Key Features |
|---|---|---|
top |
Real-time process monitor | CPU, memory usage, process list |
htop |
Interactive process viewer | Color-coded, mouse support, tree view |
ps |
Process status snapshot | Detailed process information |
vmstat |
Virtual memory statistics | CPU, memory, I/O, system activity |
iostat |
I/O statistics | Disk utilization, throughput |
free |
Memory usage | RAM, swap, buffers, cache |
df |
Disk space usage | Filesystem utilization |
netstat |
Network connections | Active connections, listening ports |
Process Monitoring
Using top Command
Basic top usage
Real-time display of running processes
Sort by CPU usage
Sorts processes by CPU usage (highest first)
Sort by memory usage
Sorts processes by memory usage
Show specific user processes
Shows processes for specific user only
Using htop (Enhanced top)
Install and run htop
Interactive process viewer with color coding
Using ps Command
Show all processes
Detailed list of all running processes
Show process tree
Shows processes in tree format
Find specific processes
Finds all Apache-related processes
Show processes by CPU usage
Top 10 processes by CPU usage
Show processes by memory usage
Top 10 processes by memory usage
System Resource Monitoring
CPU Monitoring
Check load averages
Shows system uptime and load averages
Detailed load information
1, 5, and 15-minute load averages
CPU information
Detailed CPU specifications
Number of CPU cores
Shows number of available processing units
Memory Monitoring
Memory usage overview
Human-readable memory usage information
Detailed memory information
Comprehensive memory statistics
Memory usage by process
Top memory-consuming processes
Disk Space Monitoring
Filesystem usage
Human-readable disk space usage
Directory size
Size of specific directory
Largest directories
Top 10 largest directories in /var
Inode usage
Shows inode usage for filesystems
Performance Statistics
Using vmstat
System statistics overview
Virtual memory, CPU, and I/O statistics
Continuous monitoring
Updates every 2 seconds, 10 times
Memory statistics
Detailed memory statistics
Using iostat
I/O statistics
CPU and I/O statistics for devices
Extended I/O statistics
Extended stats, updated every 2 seconds, 5 times
Per-device statistics
Device-only statistics, updated every 2 seconds
Using sar (System Activity Reporter)
CPU utilization
CPU utilization every 2 seconds, 5 times
Memory utilization
Memory utilization statistics
I/O statistics
I/O transfer rate statistics
Network Monitoring
Connection Monitoring
Active connections
Shows TCP and UDP listening ports
Established connections
Shows active TCP and UDP connections
Connection statistics
Network protocol statistics
Network Interface Monitoring
Interface statistics
Network interface statistics
Real-time network usage
Updates network statistics every second
Bandwidth monitoring with iftop
Real-time bandwidth usage by connection
System Information
Hardware Information
System information
Kernel and system information
Hardware details
Hardware configuration summary
PCI devices
Lists PCI devices
USB devices
Lists USB devices
System Logs
System messages
Recent kernel messages
System log
Follow system log in real-time
Monitoring Scripts
System Health Check Script
Comprehensive system health check script
Resource Alert Script
Automated resource monitoring with alerts
Performance Analysis
Identifying Bottlenecks
CPU bottlenecks
Identifying CPU performance issues
Memory bottlenecks
Identifying memory performance issues
I/O bottlenecks
Identifying disk I/O performance issues
Continuous Monitoring
System monitoring dashboard
Real-time system monitoring dashboard
Best Practices
System Monitoring Best Practices
- Establish Baselines - Know normal system behavior patterns
- Monitor Continuously - Use automated monitoring tools
- Set Thresholds - Define alert levels for key metrics
- Document Issues - Keep records of performance problems
- Regular Reviews - Analyze trends and patterns over time
- Proactive Monitoring - Identify issues before they become critical
Key Performance Metrics
Critical Metrics to Monitor
- Load Average - Should be below number of CPU cores
- CPU Utilization - Sustained >80% indicates bottleneck
- Memory Usage - >90% usage may cause swapping
- Disk Usage - >85% full requires attention
- I/O Wait - High %iowait indicates disk bottleneck
- Network Utilization - Monitor bandwidth usage
Common Performance Issues
Typical Performance Problems
- High Load - Too many processes competing for CPU
- Memory Leaks - Applications consuming increasing memory
- Disk Full - Filesystems approaching capacity
- I/O Bottleneck - Slow disk operations affecting performance
- Network Congestion - Bandwidth limitations or packet loss
- Zombie Processes - Dead processes not cleaned up