温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Linux系统监控工具Collectl怎么用

发布时间:2022-01-24 11:34:06 来源:亿速云 阅读:116 作者:柒染 栏目:开发技术

这篇文章跟大家分析一下“Linux系统监控工具Collectl怎么用”。内容详细易懂,对“Linux系统监控工具Collectl怎么用”感兴趣的朋友可以跟着小编的思路慢慢深入来阅读一下,希望阅读后能够对大家有所帮助。下面跟着小编一起深入学习“Linux系统监控工具Collectl怎么用”的知识吧。

Linux系统管理员为了使系统良好的运转通常会使用otop,top,free,htop,sar等丰富的常规工具来监测cpu,内存,磁盘,网络等系统信息,下面和大家一款集测试/监控/分析系统性能为一体的Linux工具-collectl。

安装collectl工具

对Ubuntu/Debian用户来说Collectl是默认资源,所以使用apt命令便可获取。

  1. $ sudo apt-get install collectl

Fedora/CentOS用户使用yum命令便可获取。

  1. $ yum install collectl

使用

必要的了解 – Collectl子系统

子系统是可检测到的不同系统资源类型。像CPU,内存,带宽等等都可构成一个子系统。只运行collectl命令将以批处理模式输出CPU,磁盘和网络子系统信息,我们在上文已看到相关内容。

从操作说明可以看到,Collectl可以识别以下子系统。

  1. 总计子系统

  2.  

  3. b – buddy info (内存片段)

  4. c – CPU

  5. d – Disk

  6. f – NFS V3 Data

  7. i – Inode and File System

  8. j – Interrupts

  9. l – Lustre

  10. m – Memory

  11. n – Networks

  12. s – Sockets

  13. t – TCP

  14. x – Interconnect

  15. y – Slabs (system object caches)

  16.  

  17. 细节子系统

  18.  

  19. 这是一系列的详细信息,大部分情况下都会由相应的总计数据衍生出来。目前“环境变量”和“进程”2类没有相应的总计数据。如果有3个磁盘,选择-sd,将只会看到3个磁盘组合出的单一信息。如果选择-sD,将会分别显示各磁盘信息。

  20.  

  21. C – CPU

  22. D – Disk

  23. E – Environmental data (fan, power, temp), via ipmitool

  24. F – NFS Data

  25. J – Interrupts

  26. L – Lustre OST detail OR client Filesystem detail

  27. M – Memory node data, which is also known as numa data

  28. N – Networks

  29. T – 65 TCP counters only available in plot format

  30. X – Interconnect

  31. Y – Slabs (system object caches)

  32. Z – Processes

使用“-s”来监测特定的子系统并向其添加子系统的识别项。现在让我们举几个例子。

1. 监测cpu使用率

用“-sc”实现CPU总使用率的监测

  1. $ collectl –sc

  2. waiting for 1 second sample…

  3. #CPU——–>

  4. #cpu sys inter ctxsw

  5. 3 0 1800 3729

  6. 3 0 1767 3599

使用“-C”观察各个单独的CPU使用情况。结果将会输出多行,分别对应一个CPU。

  1. $ collectl –sC

  2. waiting for 1 second sample…

  3.  

  4. # SINGLE CPU STATISTICS

  5.  

  6. # Cpu User Nice Sys Wait IRQ Soft Steal Idle

  7. 0 3 0 0 0 0 0 0 96

  8. 1 3 0 0 0 0 0 0 96

  9. 2 2 0 0 0 0 0 0 97

  10. 3 1 0 0 0 0 0 0 98

  11. 0 2 0 0 0 0 0 0 97

  12. 1 2 0 2 0 0 0 0 95

  13. 2 1 0 0 0 0 0 0 98

  14. 3 4 0 1 0 0 0 0 95

如果需要,可以同时使用C和c来获取单项CPU监测数据和汇总数据。

2. 内存监测

使用m子系统查看内存。

  1. $ collectl –sm

  2. waiting for 1 second sample…

  3. #Memory———–>

  4. #Free Buff Cach Inac Slab Map

  5. 2G 220M 1G 1G 210M 3G

  6. 2G 220M 1G 1G 210M 3G

  7. 2G 220M 1G 1G 210M 3G

不难解释。 M用来查看更多内存的详细信息。

  1. $ collectl –sM

  2. waiting for 1 second sample…

  3.  

  4. # MEMORY STATISTICS

  5.  

  6. # Node Total Used Free Slab Mapped Anon Locked Inact Hit%

  7. 0 7975M 5939M 2036M 215720K 372184K 0 6652K 1434M 0

  8. 0 7975M 5939M 2036M 215720K 372072K 0 6652K 1433M 0

这类似于免费报告吗?

3. 查看磁盘使用情况

d和D可以查看磁盘使用的概况和详细情况。

  1. $ collectl –sd

  2. waiting for 1 second sample…

  3. #Disks———–>

  4. #KBRead Reads KBWrit Writes

  5. 4 1 136 24

  6. 0 0 80 13

  7.  

  8. $ collectl –sD

  9. waiting for 1 second sample…

  10.  

  11. # DISK STATISTICS (/sec)

  12. # reads———>writes———>averages——–> Pct

  13. #Name KBytes Merged IOs Size KBytes Merged IOs Size RWSize QLen Wait SvcTim Util

  14. sda 0 0 0 0 0 0 0 0 0 0 0 0 0

  15. sda 0 0 0 0 0 0 0 0 0 0 0 0 0

  16. sda 1 0 2 1 17 1 5 3 2 2 6 2 1

  17. sda 0 0 0 0 92 11 5 18 18 1 12 12 5

“–verbose”命令可以用来查看附加信息。和D命令不同,它将概况扩展,包含了更多信息。

  1. $ collectl –sd —verbose

4. 同时报告多系统情况

如果想要同时得到CPU,内存和磁盘报告,那么同时使用子命令组合来实现。

  1. $ collectl –scmd

  2. waiting for 1 second sample…

  3. #CPU——–>Memory———–>Disks———–>

  4. #cpu sys inter ctxsw Free Buff Cach Inac Slab Map KBRead Reads KBWrit Writes

  5. 4 0 2187 4334 1G 221M 1G 1G 210M 3G 0 0 0 0

  6. 3 0 1896 4065 1G 221M 1G 1G 210M 3G 0 0 20 5

5. 显示统计时间

若要将每行的监测信息和时间一同显示,使用T选项。通过在“-o”参数来指定。

  1. $ collectl –scmd –oT

  2. waiting for 1 second sample…

  3. # CPU——–>Memory———–>Disks———–>

  4. #Time cpu sys inter ctxsw Free Buff Cach Inac Slab Map KBRead Reads KBWrit Writes

  5. 12:03:05 3 0 1961 4013 1G 225M 1G 1G 212M 3G 0 0 0 0

  6. 12:03:06 3 0 1884 3810 1G 225M 1G 1G 212M 3G 0 0 0 0

  7. 12:03:07 3 0 2011 4060 1G 225M 1G 1G 212M 3G 0 0 0 0

使用“-oTm”可将时间换成毫秒显示。

6. 改变样本计数

collectl报告的每行都是一份快照或样本,它通常设定定期间隔如1秒来取样。i可用来设置时间间隔,c用来设置样本计数。

  1. $ collectl –c1 –sm

  2. waiting for 1 second sample…

  3. #Memory———–>

  4. #Free Buff Cach Inac Slab Map

  5. 1G 261M 1G 1G 228M 3G

使用i命令可改变更新时间间隔。

  1. $ collectl –sm –i2

  2. waiting for 2 second sample…

  3. #Memory———–>

  4. #Free Buff Cach Inac Slab Map

  5. 1G 261M 1G 1G 229M 3G

上面的命令设定每2秒收集一次内存信息。

7. 像iotop一样使用collectl

top命令将collectl像iostat/top工具一样进行智能统计。列表会持续更新,且可以使用不同字段实现排序。

  1. $ collectl —top iokb

输出如下

  1. # TOP PROCESSES sorted by iokb (counters are /sec) 09:44:57

  2. # PID User PR PPID THRD S VSZ RSS CP SysT UsrT Pct AccuTime RKB WKB MajF MinF Command

  3. 3104 enlighte 20 2683 3 S 938M 33M 0 0.00 0.00 0 00:09.16 0 4 0 0 /usr/bin/ktorrent

  4. 1 root 20 0 0 S 26M 3M 2 0.00 0.00 0 00:01.30 0 0 0 0 /sbin/init

  5. 2 root 20 0 0 S 0 0 3 0.00 0.00 0 00:00.00 0 0 0 0 kthreadd

  6. 3 root 20 2 0 S 0 0 0 0.00 0.00 0 00:00.02 0 0 0 0 ksoftirqd/0

  7. 4 root 20 2 0 S 0 0 0 0.00 0.00 0 00:00.00 0 0 0 0 kworker/0:0

  8. 5 root 0 2 0 S 0 0 0 0.00 0.00 0 00:00.00 0 0 0 0 kworker/0:0H

  9. 7 root RT 2 0 S 0 0 0 0.00 0.00 0 00:00.08 0 0 0 0 migration/0

  10. 8 root 20 2 0 S 0 0 2 0.00 0.00 0 00:00.00 0 0 0 0 rcu_bh

  11. 9 root 20 2 0 S 0 0 0 0.00 0.00 0 00:00.00 0 0 0 0 rcuob/0

上面的输出很像top命令,并且它以磁盘数量降序排列进程。

若只想显示上面的5项进程,可用以下命令实现

  1. $ collectl —top iokb,5

若想学习上面的列表里哪些字段可以排序,使用如下命令

  1. $ collectl —showtopopts

  2.  

  3. 下面是应用于进程或数据的最高排序类型列表。某些情况下你可能会使用某一字段进行排序,但它并非显示的一部分。

  4.  

  5. TOP PROCESS SORT FIELDS

  6. 进程排序字段

  7.  

  8. Memory

  9. vsz virtual memory

  10. rss resident (physical) memory

  11.  

  12. Time

  13. syst system time

  14. usrt user time

  15. time total time

  16. accum accumulated time

  17.  

  18. I/O

  19. rkb KB read

  20. wkb KB written

  21. iokb total I/O KB

  22.  

  23. rkbc KB read from pagecache

  24. wkbc KB written to pagecache

  25. iokbc total pagecacge I/O

  26. ioall total I/O KB (iokb+iokbc)

  27.  

  28. rsys read system calls

  29. wsys write system calls

  30. iosys total system calls

  31.  

  32. iocncl Cancelled write bytes

  33.  

  34. Page Faults

  35. majf major page faults

  36. minf minor page faults

  37. flt total page faults

  38.  

  39. Context Switches

  40. vctx volunary context switches

  41. nctx non–voluntary context switches

  42.  

  43. Miscellaneous (best when used with —procfilt)

  44. cpu cpu number

  45. pid process pid

  46. thread total process threads (not counting main)

  47.  

  48. TOP SLAB SORT FIELDS

  49.  

  50. numobj total number of slab objects

  51. actobj active slab objects

  52. objsize sizes of slab objects

  53. numslab number of slabs

  54. objslab number of objects in a slab

  55. totsize total memory sizes taken by slabs

  56. totchg change in memory sizes

  57. totpct percent change in memory sizes

  58. name slab names

8. 像top一样使用collectl

为使collectl像top,我们只需以CPU使用率排序输出进程。

  1. $ collectl —top

输出如下

  1. # TOP PROCESSES sorted by time (counters are /sec) 14:08:46

  2. # PID User PR PPID THRD S VSZ RSS CP SysT UsrT Pct AccuTime RKB WKB MajF MinF Command

  3. 9471 enlighte 20 9102 0 R 63M 22M 3 0.03 0.10 13 00:00.81 0 0 0 3 /usr/bin/perl

  4. 3076 enlighte 20 2683 2 S 521M 40M 2 0.00 0.03 3 00:55.14 0 0 0 2 /usr/bin/yakuake

  5. 3877 enlighte 20 3356 41 S 1G 218M 1 0.00 0.03 3 10:10.50 0 0 0 0 /opt/google/chrome/chrome

  6. 4625 enlighte 20 2895 36 S 1G 241M 2 0.00 0.02 2 08:24.39 0 0 0 12 /usr/lib/firefox/firefox

  7. 5638 enlighte 20 3356 3 S 1G 265M 1 0.00 0.02 2 09:55.04 0 0 0 2 /opt/google/chrome/chrome

  8. 1186 root 20 1152 4 S 502M 76M 0 0.00 0.01 1 03:02.96 0 0 0 0 /usr/bin/X

  9. 1334 www–data 20 1329 0 S 87M 1M 2 0.00 0.01 1 00:00.85 0 0 0 0 nginx:

上面的命令也可用于显示子系统信息。

  1. $ collectl —top –scm

9. 像ps一样列出进程

为像ps命令一样列出所有进程且没有后续更新,用“c”命令让其计数至1. $ collectl -c1 -sZ -i:1

上面的命令将会列出类似“ps -e”命令的所有进程。“procfilt”用于从所有进程中过滤出特定的进程信息。“procopts”用于指定另一组微调进程列表显示的命令。

10. 像vmstat一样使用collectl

Collectl有内置命令来完成像vmstat一样的功能。

  1. $ collectl —vmstat

  2. waiting for 1 second sample…

  3. #procs —————memory (KB)————— —swaps— —–io—- —system— —-cpu—–

  4. # r b swpd free buff cache inact active si so bi bo in cs us sy id wa

  5. 1 0 0 1733M 242M 1922M 1137M 710M 0 0 0 108 1982 3918 2 0 95 1

  6. 1 0 0 1733M 242M 1922M 1137M 710M 0 0 0 0 1906 3886 1 0 98 0

  7. 1 0 0 1733M 242M 1922M 1137M 710M 0 0 0 0 1739 3480 3 0 96 0

11. 子系统的详细信息

下面的命令以一秒为间隔,统计5次CPU信息并和时间一起显示出详细信息(冗长)。

  1. $ collectl –sc –c5 –i1 —verbose –oT

  2. waiting for 1 second sample…

  3.  

  4. # CPU SUMMARY (INTR, CTXSW & PROC /sec)

  5. #Time User Nice Sys Wait IRQ Soft Steal Idle CPUs Intr Ctxsw Proc RunQ Run Avg1 Avg5 Avg15 RunT BlkT

  6. 14:22:10 11 0 0 0 0 0 0 87 4 1312 2691 0 866 1 0.78 0.86 0.78 1 0

  7. 14:22:11 15 0 0 0 0 0 0 84 4 1283 2496 0 866 1 0.78 0.86 0.78 1 0

  8. 14:22:12 17 0 0 0 0 0 0 82 4 1342 2658 0 866 0 0.78 0.86 0.78 0 0

  9. 14:22:13 15 0 0 0 0 0 0 84 4 1241 2429 0 866 1 0.78 0.86 0.78 1 0

  10. 14:22:14 11 0 0 0 0 0 0 88 4 1270 2488 0 866 0 0.80 0.87 0.78 0 0

改变”-s”变量查看不同的子系统。

关于Linux系统监控工具Collectl怎么用就分享到这里啦,希望上述内容能够让大家有所提升。如果想要学习更多知识,请大家多多留意小编的更新。谢谢大家关注一下亿速云网站!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI