乐闻世界logo
搜索文章和话题

What are the commonly used tools for Linux system performance monitoring, and how to analyze CPU, memory, disk, and network usage?

2月17日 23:36

Linux system performance monitoring is an important skill for operations engineers, requiring mastery of various tools to diagnose system bottlenecks.

CPU monitoring:

  • top/htop: real-time view of CPU usage and process information
  • vmstat: reports virtual memory statistics, e.g., vmstat 1 5 (update every second, 5 times total)
  • mpstat: displays usage of each CPU core, e.g., mpstat -P ALL 1
  • sar: system activity report, e.g., sar -u 1 10 (collect every second, 10 times total)

Memory monitoring:

  • free: displays memory usage, free -h shows in human-readable format
  • vmstat: view memory swap, cache and other information
  • ps aux: view process memory usage (VSZ, RSS)
  • pmap: view process memory mappings

Disk monitoring:

  • df: view disk space usage, df -h shows in human-readable format
  • du: view directory or file size, du -sh directory
  • iostat: view disk I/O statistics, e.g., iostat -x 1
  • iotop: real-time view of disk I/O usage (requires root privileges)

Network monitoring:

  • ifconfig/ip: view network interface configuration
  • netstat/ss: view network connections and port listening, e.g., netstat -tulnp or ss -tulnp
  • nethogs: view network bandwidth usage by process
  • tcpdump: capture and analyze network traffic, e.g., tcpdump -i eth0 port 80

Log analysis:

  • /var/log/messages: main system log
  • /var/log/syslog: system log (Debian/Ubuntu)
  • /var/log/dmesg: kernel boot log
  • journalctl: systemd log viewing tool, e.g., journalctl -f (real-time view)

Comprehensive monitoring tools:

  • dstat: integrates vmstat, iostat, netstat and other functions
  • glances: web-based system monitoring tool
  • prometheus + grafana: enterprise-level monitoring solution

Performance optimization recommendations:

  • CPU: optimize algorithms, reduce unnecessary calculations, use multi-process/multi-threading
  • Memory: reduce memory leaks, optimize data structures, use caching
  • Disk: use SSD, optimize file system, reduce I/O operations
  • Network: use CDN, optimize TCP parameters, reduce network requests
标签:Linux