centos性能监控系列二:Collectl初解


对于一个 Linux 系统管理员来说确保自己管理的系统处于一个良好的状态是其首要责任。

Linux 系统管理员可以找到有很多工具来帮助自己监控和显示系统中的进程,例如 top 和 htop 

今天介绍一款工具collectl,使用比较方便;




介绍:

collectl是一款非常优秀并且有着丰富的命令行功能的实用程序,你可以用它来采集描述当前系统状态的性能数据。不同于大多数其它的系统监控工具,collectl 并非仅局限于有限的系统度量,相反,它可以收集许多不同类型系统资源的相关信息,如 cpu 、disk、memory 、network 、sockets 、 tcp 、inodes 、infiniband 、 lustre 、memory、nfs、processes、quadrics、slabs和buddyinfo等。

使用 collectl 的另一个好处就是它可以替代那些特定用途的工具如: top、ps、iotop 等等其它工具。那么 collectl 有什么特性而使其成为一个有用的工具呢?


Collectl 特性

  • 可以交互式地运行或作为一个守护进程,或同时二者兼备地运行。

  • 可以以多种格式显示输出。

  • 可以监控几乎所有的子系统。

  • 可以替代许多工具如 ps、top、iotop、vmstat。

  • 可以记录并回放捕获的数据。

  • 可以将数据导出成多种数据格式。(这在你想用外部工具分析数据时非常有用)

  • 可以作为一个服务来监控远程机或者整个服务器集群。

  • 可以在终端显示数据,写入数据到文件或者一个套接字。


如何在Linux上安装collectl

collectl可以在所有的 Linux 发行版上运行,唯一需要的就是 perl 语言,所以在安装 collectl 之前,一定要确保你的电脑上已经安装了Perl

对于Debian/Ubuntu/Linux Mint

下面的命令可以用来在以 Debian 为基础的设备如 Ubuntu 上安装 collectl。

  1. $ sudo apt-get install collectl

对于RHEL/CentOS/Fedora

如果你正在使用基于红帽的发行版,你可以用 yum 命令轻松获取它。

  1. # yum install collectl


一些关于collectl的实例

collectl 工具安装完成之后,你可以轻松地在终端运行它,你甚至不需要指定任何选项。下面的命令将会以简短易读的格式显示cpu、硬盘和网络信息。

  1. # collectl
  2.  
  3. waiting for 1 second sample...
  4. #
  5. #cpu sys inter ctxsw KBRead Reads KBWrit Writes KBIn PktIn KBOut PktOut
  6. 13 5 790 1322 0 0 92 7 4 13 0 5
  7. 10 2 719 1186 0 0 0 0 3 9 0 4
  8. 12 0 753 1188 0 0 52 3 2 5 0 6
  9. 13 2 733 1063 0 0 0 0 1 1 0 1
  10. 25 2 834 1375 0 0 0 0 1 1 0 1
  11. 28 2 870 1424 0 0 36 7 1 1 0 1
  12. 19 3 949 2271 0 0 44 3 1 1 0 1
  13. 17 2 809 1384 0 0 0 0 1 6 0 6
  14. 16 2 732 1348 0 0 0 0 1 1 0 1
  15. 22 4 993 1615 0 0 56 3 1 2 0 3

正如上面终端上所显示的,我们很容易观察该命令输出的系统度量值,因为它每次以一行显示。

不加任何参数执行 collectl 会显示下面子系统的信息

  • cpu
  • 磁盘
  • 网络


但是,你如何用它来监控 cpu 的使用情况呢? ‘-s’ 选项可以用来控制哪个子系统的数据需要收集和回放。

例如下面的命令可以用来对cpu使用情况进行一个总结。

  1. # collectl -sc
  2.  
  3. waiting for 1 second sample...
  4. #
  5. #cpu sys inter ctxsw
  6. 15 2 749 1155
  7. 16 3 772 1445
  8. 14 2 793 1247
  9. 27 4 887 1292
  10. 24 1 796 1258
  11. 16 1 743 1113
  12. 15 1 743 1179
  13. 14 1 706 1078
  14. 15 1 764 1268



当你想要进一步了解内存使用信息、空闲的内存或者与你系统性能有关的重要资料时,上面的输出将是非常有用的。

如果想搜集一点儿 tcp 的数据呢?使用下面的命令来实现吧。

  1. # collectl -st
  2.  
  3. waiting for 1 second sample...
  4. #
  5. # IP Tcp Udp Icmp
  6. 0 0 0 0
  7. 0 0 0 0
  8. 0 0 0 0
  9. 0 0 0 0
  10. 0 0 0 0
  11. 0 0 0 0
  12. 0 0 0 0
  13. 0 0 0 0
  14. 0 0 0 0
  15. 0 0 0 0
  16. 0 0 0 0

当你熟练到一定程度时,你就可以很轻松地得到你想要的结果了。例如你可以将关于 tcp 的“t”选项和关于 cpu 的“c”选项组合到一起。下面的命令就是如此。

  1. # collectl -stc
  2.  
  3. waiting for 1 second sample...
  4. #
  5. #cpu sys inter ctxsw IP Tcp Udp Icmp
  6. 23 8 961 3136 0 0 0 0
  7. 24 5 916 3662 0 0 0 0
  8. 21 8 848 2408 0 0 0 0
  9. 30 10 916 2674 0 0 0 0
  10. 38 3 826 1752 0 0 0 0
  11. 31 3 820 1408 0 0 0 0
  12. 15 5 781 1335 0 0 0 0
  13. 17 3 802 1314 0 0 0 0
  14. 17 3 755 1218 0 0 0 0
  15. 14 2 788 1321 0 0 0 0

以上简单举几个例子;



对于我们普通大众来说记住这些选项很困难,所以在这里,我整理出了一个列表来总结这个工具支持的选项。

  • b – buddy info (内存碎片)
  • c – CPU
  • d – Disk
  • f – NFS V3 Data
  • i – Inode and File System
  • j – Interrupts
  • l – Lustre
  • m – Memory
  • n – Networks
  • s – Sockets
  • t – TCP
  • x – Interconnect
  • y – Slabs (系统对象缓存)

对于一个系统管理员或者一个 Linux 用户来说很重要的一种数据就是硬盘的使用情况。下面的命令可以帮你监控硬盘使用情况。

  1. # collectl -sd
  2.  
  3. waiting for 1 second sample...
  4. #
  5. #KBRead Reads KBWrit Writes
  6. 0 0 0 0
  7. 0 0 0 0
  8. 0 0 92 7
  9. 0 0 0 0
  10. 0 0 36 3
  11. 0 0 0 0
  12. 0 0 0 0
  13. 0 0 100 7
  14. 0 0 0 0

你也可以使用“-sD”选项来采集单个硬盘的数据,不过你必须知道这就不会显示全部硬盘的信息。

  1. # collectl -sD
  2.  
  3. waiting for 1 second sample...
  4.  
  5. # DISK STATISTICS (/sec)
  6. # Pct
  7. #Name KBytes Merged IOs Size KBytes Merged IOs Size RWSize QLen Wait SvcTim Util
  8. sda 0 0 0 0 52 11 2 26 26 1 8 8 1
  9. sda 0 0 0 0 0 0 0 0 0 0 0 0 0
  10. sda 0 0 0 0 24 0 2 12 12 0 0 0 0
  11. sda 0 0 0 0 152 0 4 38 38 0 0 0 0
  12. sda 0 0 0 0 192 45 3 64 64 1 20 20 5
  13. sda 0 0 0 0 204 0 2 102 102 0 0 0 0
  14. sda 0 0 0 0 0 0 0 0 0 0 0 0 0
  15. sda 0 0 0 0 116 26 3 39 38 1 16 16 4
  16. sda 0 0 0 0 0 0 0 0 0 0 0 0 0
  17. sda 0 0 0 0 0 0 0 0 0 0 0 0 0
  18. sda 0 0 0 0 32 5 3 11 10 1 16 16 4
  19. sda 0 0 0 0 0 0 0 0 0 0 0 0 0

你也可以使用其它详细的子系统来采集详细的数据。下面是详细子系统的一个列表。

  • C – CPU
  • D – Disk
  • E – Environmental data (fan, power, temp), via ipmitool
  • F – NFS Data
  • J – Interrupts
  • L – Lustre OST detail OR client Filesystem detail
  • N – Networks
  • T – 65 TCP counters only available in plot format
  • X – Interconnect
  • Y – Slabs (system object caches)
  • Z – Processes


collectl 工具中有许多选项,但是仅用一篇文章来介绍肯定是介绍不过来的。然而如果将它当作 top 和 ps 工具来使用还是值得一提的。

很容易将 collectl 当作 top 来使用,只要在 Linux 系统的终端运行下面的命令你就会看到和 top 工具类似的输出。

  1. # collectl --top
  2.  
  3. # TOP PROCESSES sorted by time (counters are /sec) 13:11:02
  4. # PID User PR PPID THRD S VSZ RSS CP SysT UsrT Pct AccuTime RKB WKB MajF MinF Command
  5. ^COuch!tecmint 20 1 40 R 1G 626M 0 0.01 0.14 15 28:48.24 0 0 0 109 /usr/lib/firefox/firefox
  6. 3403 tecmint 20 1 40 R 1G 626M 1 0.00 0.20 20 28:48.44 0 0 0 600 /usr/lib/firefox/firefox
  7. 5851 tecmint 20 4666 0 R 17M 13M 0 0.02 0.06 8 00:01.28 0 0 0 0 /usr/bin/perl
  8. 1682 root 20 1666 2 R 211M 55M 1 0.02 0.01 3 03:10.24 0 0 0 95 /usr/bin/X
  9. 3454 tecmint 20 3403 8 S 216M 45M 1 0.01 0.02 3 01:23.32 0 0 0 0 /usr/lib/firefox/plugin-container
  10. 4658 tecmint 20 4657 3 S 207M 17M 1 0.00 0.02 2 00:08.23 0 0 0 142 gnome-terminal
  11. 2890 tecmint 20 2571 3 S 340M 68M 0 0.00 0.01 1 01:19.95 0 0 0 0 compiz
  12. 3521 tecmint 20 1 24 S 710M 148M 1 0.01 0.00 1 01:47.84 0 0 0 0 skype
  13. 1 root 20 0 0 S 3M 2M 0 0.00 0.00 0 00:02.57 0 0 0 0 /sbin/init
  14. 2 root 20 0 0 S 0 0 1 0.00 0.00 0 00:00.00 0 0 0 0 kthreadd
  15. 3 root 20 2 0 S 0 0 0 0.00 0.00 0 00:00.60 0 0 0 0 ksoftirqd/0
  16. 5 root 0 2 0 S 0 0 0 0.00 0.00 0 00:00.00 0 0 0 0 kworker/0:0H
  17. 7 root 0 2 0 S 0 0 0 0.00 0.00 0 00:00.00 0 0 0 0 kworker/u:0H
  18. 8 root RT 2 0 S 0 0 0 0.00 0.00 0 00:04.42 0 0 0 0 migration/0
  19. 9 root 20 2 0 S 0 0 0 0.00 0.00 0 00:00.00 0 0 0 0 rcu_bh
  20. 10 root 20 2 0 R 0 0 0 0.00 0.00 0 00:02.22 0 0 0 0 rcu_sched
  21. 11 root RT 2 0 S 0 0 0 0.00 0.00 0 00:00.05 0 0 0 0 watchdog/0
  22. 12 root RT 2 0 S 0 0 1 0.00 0.00 0 00:00.07 0 0 0 0 watchdog/1
  23. 13 root 20 2 0 S 0 0 1 0.00 0.00 0 00:00.73 0 0 0 0 ksoftirqd/1
  24. 14 root RT 2 0 S 0 0 1 0.00 0.00 0 00:01.96 0 0 0 0 migration/1
  25. 16 root 0 2 0 S 0 0 1 0.00 0.00 0 00:00.00 0 0 0 0 kworker/1:0H
  26. 17 root 0 2 0 S 0 0 1 0.00 0.00 0 00:00.00 0 0 0 0 cpuset


还有不了解的额,在你的终端键入下面的命令开始阅读吧。

  1. # man collectl
原文地址:https://www.cnblogs.com/idotest/p/5203860.html