bash
top -d 5 # 5秒刷新一次
top -p PID # 监控指定进程
top -u USER # 监控指定用户进程
bash
sudo apt install htop # Debian/Ubuntu
sudo yum install htop # RHEL/CentOS
bash
sudo pip install glances
glances -w # 启动Web服务器
bash
vmstat 1 5 # 每秒1次,共5次
bash
sudo apt install sysstat
bash
mpstat -P ALL 1 # 监控所有CPU核心
bash
perf stat -a sleep 5 # 系统整体统计
perf top # 实时性能分析
perf record -g -p PID # 记录进程性能数据
perf report # 分析记录数据
bash
free -h # 人类可读格式
free -s 5 # 每5秒刷新
bash
pmap -x PID
bash
valgrind --tool=memcheck --leak-check=full ./program
bash
iostat -x 1 5 # 扩展统计,每秒1次共5次
bash
sudo apt install iotop
bash
dstat -cdngy 1 # CPU,磁盘,网络,内存,系统统计
bash
sudo apt install iftop
bash
iftop -i eth0
bash
nethogs eth0
bash
tcpdump -i eth0 -w capture.pcap
bash
netstat -tulnp # 传统netstat
ss -tulnp # 更快的替代方案
bash
ps aux
ps -ef
ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%cpu | head
bash
strace -p PID
strace -c ./program
bash
lsof -i :80 # 查看80端口使用
lsof -u username # 查看用户打开文件
bash
sudo apt install sysstat
bash
sar -u 1 5 # CPU使用率
sar -r 1 5 # 内存使用
sar -b 1 5 # I/O统计
bash
bpftrace -e 'tracepoint:syscalls:sys_enter_* { @[probe] = count(); }'
bash
stap -e 'probe vfs.read {printf("read performed\n"); exit()}'
bash
bash <(curl -Ss https://my-netdata.io/kickstart.sh)
bash
sysbench cpu --threads=4 run
bash
fio --name=randread --ioengine=libaio --rw=randread --bs=4k --numjobs=4 --size=1G --runtime=60 --time_based --group_reporting
问题定位流程:
top/htop
查看整体情况vmstat/iostat
确认瓶颈方向长期监控:
sysstat
收集历史数据性能分析黄金法则:
这些工具组合使用可以帮助您全面分析Linux系统的性能问题,从整体监控到特定组件深入分析,满足不同层次的性能调优需求。