CPU 实用监控工具盘点
01. top
1.1 /proc/loadavg
9.53 9.12 8.37 3/889 28165
1.2 top使用
us:user,统计nice小于等于0的用户空间进程,也即优先级为100~120。ni:nice,统计nice大于0的用户空间进程,也即优先级为121~139。sys:system,统计内核态运行时间,不包括中断。id:idle,几系统处于空闲态。wa:iowait,统计io等待时间。hi:hardware interrupt,统计硬件中断时间。si:software interrupt,统计软中断时间。st:steal

02. perf

03. sar和ksar
# 将 ENABLED=“false“ 改为ENABLED=“true“$ sudo gedit /etc/default/sysstat# 修改sar的周期等配置$ sudo gedit /etc/cron.d/sysstat# 重启sar服务$ sudo /etc/init.d/sysstat restart# sar log存放目录$ ls -l /var/log/sysstat/
LC_ALL=C sar -A > sar.txt

sar 1 100-----------------所有cpu合一的统计信息sar -P ALL 1 100--------包括cpu合一以及单个cpu的统计信息sar -B 1 100---------------paging统计信息sar -b 1 100---------------块设备IO统计信息sar -d 1 100---------------块设备活动统计信息sar -F 1 100----------------挂载的文件系统统计信息sar -r ALL------------------ 显示详细的内存使用统计信息sar -S ------------------------显示swap空间使用情况统计信息sar -w----------------------- 显示进程创建以及进程切换统计信息sar -W-----------------------显示swap换入换出统计信息。
04. mpstat
$ mpstat -P ALL 10 20

05. uptime
11:15:41 up 82 days, 20:34, 8 users, load average: 0.28, 0.40, 0.43
06. vmstat
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----r b swpd free buff cache si so bi bo in cs us sy id wa st1 0 472576 228688 559092 1061756 0 0 9 39 1 0 8 4 87 0 01 0 472576 228184 559100 1061756 0 0 0 13 1532 3395 10 6 84 0 01 0 472576 229308 559100 1061616 0 0 0 0 1446 3449 10 5 85 0 00 0 472576 229592 559108 1061616 0 0 0 6 1419 3474 10 5 85 0 01 0 472576 229804 559108 1061616 0 0 0 0 1446 3439 10 5 85 0 0


07. pidstat
7.1 查看CPU使用情况
# 显示所有的进程统计信息,包括idle进程。pidstat -p ALL# 更加详细的显示了线程统计信息。pidstat -p ALL -t# 周期采样和采样次数pidstat [option] interval [count]
7.2 查看内存使用情况
15时18分21秒 UID PID minflt/s majflt/s VSZ RSS %MEM Command15时18分21秒 0 1 0.02 0.00 185316 3028 0.08 systemd15时18分21秒 0 2 0.00 0.00 0 0 0.00 kthreadd15时18分21秒 0 4 0.00 0.00 0 0 0.00 kworker/0:0H15时18分21秒 0 6 0.00 0.00 0 0 0.00 mm_percpu_wq15时18分21秒 0 7 0.00 0.00 0 0 0.00 ksoftirqd/015时18分21秒 0 8 0.00 0.00 0 0 0.00 rcu_sched
7.3 查看磁盘使用情况
15时20分40秒 UID PID kB_rd/s kB_wr/s kB_ccwr/s iodelay Command15时20分40秒 0 1 -1.00 -1.00 -1.00 243523129 systemd15时20分40秒 0 2 -1.00 -1.00 -1.00 0 kthreadd15时20分40秒 0 4 -1.00 -1.00 -1.00 0 kworker/0:0H15时20分40秒 0 6 -1.00 -1.00 -1.00 0 mm_percpu_wq15时20分40秒 0 7 -1.00 -1.00 -1.00 714512328679 ksoftirqd/015时20分40秒 0 8 -1.00 -1.00 -1.00 417757303594 rcu_sched
08. time
2401940638 32606752 nomachine_6.0.80_1.exe# 整个操作总耗时,0.263-0.094-0.011=0.158是IO等待耗时。real 0m0.263s# 用户态耗时user 0m0.094s# 内核态耗时sys 0m0.011s2401940638 32606752 nomachine_6.0.80_1.exe# 第二次执行就可以看出等待IO操作的时间基本上没有了。real 0m0.098suser 0m0.097ssys 0m0.000s
09. cpustat
# 显示Load Avg信息和平均频率等Load Avg 0.66 0.54 0.49, Freq Avg. 1.46 GHz, 4 CPUs online# 进程切换次数、硬中断、软中断等等统计信息。# CPU占用率、用户空间和内核空间占用率等。3791.1 Ctxt/s, 1709.9 IRQ/s, 1800.0 softIRQ/s, 0.0 new tasks/s, 1 running, 0 blocked%CPU %USR %SYS PID S CPU Time Task25.74 25.74 0.00 11435 R 3 2.29w /usr/bin/python315.84 15.84 0.00 9445 S 0 1.49w /usr/lib/xorg/Xorg10.89 9.90 0.99 2722 S 1 1.05w compiz7.92 0.00 7.92 32352 S 2 16.60s [kworker/2:1]0.99 0.00 0.99 32397 R 1 0.01s cpustat0.99 0.99 0.00 11046 S 2 16.20h compiz0.99 0.99 0.00 1317 S 0 8.76h /usr/NX/bin/nxnode.bin0.99 0.00 0.99 10293 S 1 1.24m [kworker/1:2]64.36 53.47 10.89 TotalLoad Avg 0.66 0.54 0.49, Freq Avg. 1.75 GHz, 4 CPUs online2834.8 Ctxt/s, 1190.9 IRQ/s, 1183.3 softIRQ/s, 0.0 new tasks/s, 4 running, 0 blocked%CPU %USR %SYS PID S CPU Time Task25.76 25.76 0.00 11435 R 3 2.29w /usr/bin/python318.18 18.18 0.00 9445 S 0 1.49w /usr/lib/xorg/Xorg7.58 7.58 0.00 2722 S 1 1.05w compiz6.06 0.00 6.06 32352 S 2 16.64s [kworker/2:1]1.52 0.00 1.52 32397 R 1 0.02s cpustat1.52 0.00 1.52 8 S 0 3.00h [rcu_sched]1.52 0.00 1.52 18409 S 0 1.16m update-notifier62.12 51.52 10.61 TotalDistribution of CPU utilisation (per Task):% CPU Utilisation Count (%)0.00 - 1.97 706 98.881.97 - 3.94 0 0.003.94 - 5.91 0 0.005.91 - 7.88 2 0.287.88 - 9.85 0 0.009.85 - 11.82 0 0.0011.82 - 13.79 1 0.1413.79 - 15.76 0 0.0015.76 - 17.73 1 0.1417.73 - 19.70 1 0.1419.70 - 21.67 0 0.0021.67 - 23.64 0 0.0023.64 - 25.61 2 0.2825.61 - 27.57 0 0.0027.58 - 29.54 0 0.0029.55 - 31.51 0 0.0031.52 - 33.48 0 0.0033.48 - 35.45 0 0.0035.45 - 37.42 0 0.0037.42 - 39.39 1 0.14Distribution of CPU utilisation (per CPU):----------------------------------------------各CPU占用率,分用户空间和内核空间。CPU# USR% SYS%0 17.37 1.201 8.98 2.402 0.60 7.193 25.75 0.00
10. htop

11. atop

12. glances

13. nmon

13. pcp-gui
$ sudo apt install pcp pcp-gui

14. collectl和colplot
14.1 collectl使用
sudo apt-get install collectl

b – buddy info (内存碎片)c – 所有CPU的合一统计信息;C - 单个CPU的统计信息。d – 整个文件系统Disk合一统计信息;C - 单个磁盘的统计信息。f – NFS V3 Datai – Inode and File Systemj – 显示每个CPU的Interrupts触发情况;J - 显示每个中断详细触发情况。l – Lustrem – 显示整个系统Memory使用情况;M - 按node显示内存使用情况。n – 显示整个系统的Networks使用情况;N - 分网卡显示网络使用情况。s – Socketst – TCPx – Interconnecty – 对系统所有Slabs (系统对象缓存)使用统计信息;Y - 每个slab使用的详细信息。



14.2 colplot使用
$suod systemctl reload apache2$ sudo systemctl restart apache2


References
[1] /proc/stat: https://www.cnblogs.com/arnoldlu/p/9187775.html#system_proc_stat[2] /proc//stat: https://www.cnblogs.com/arnoldlu/p/9187775.html#process_proc_stat[3] 系统级性能分析工具perf的介绍与使用: https://www.cnblogs.com/arnoldlu/p/6241297.html[4] ksar: https://sourceforge.net/projects/ksar/[5] How To Create sar Graphs With kSar To Identifying Linux Bottlenecks: https://www.cyberciti.biz/tips/identifying-linux-bottlenecks-sar-graphs-with-ksar.html[6] Collect and report Linux System Activity Information with sar: https://www.thomas-krenn.com/en/wiki/Collect_and_report_Linux_System_Activity_Information_with_sar[7] Linux Performance Measurements using vmstat: https://www.thomas-krenn.com/en/wiki/Linux_Performance_Measurements_using_vmstat[8] Collectl: Linux 性能监控的全能冠军: https://linux.cn/article-3154-1.html[9] Collectl Documentation: http://collectl.sourceforge.net/Documentation.html[10] Collectl Examples - An Awesome Performance Analysis Tool in Linux: https://linoxide.com/monitoring-2/collectl-tool-install-examples/评论
