6. 改变样本计数
collectl报告的每行都是一份快照或样本,它通常设定定期间隔如1秒来取样。i可用来设置时间间隔,c用来设置样本计数。
- $ collectl -c1 -sm
- waiting for1 second sample...
- #<-----------Memory----------->
- #Free Buff Cach Inac Slab Map
- 1G261M1G1G228M3G
使用i命令可改变更新时间间隔。
- $ collectl -sm -i2
- waiting for2 second sample...
- #<-----------Memory----------->
- #Free Buff Cach Inac Slab Map
- 1G261M1G1G229M3G
上面的命令设定每2秒收集一次内存信息。
7. 像iotop一样使用collectl
top命令将collectl像iostat/top工具一样进行智能统计。列表会持续更新,且可以使用不同字段实现排序。
- $ collectl --top iokb
输出如下
- # TOP PROCESSES sorted by iokb (counters are /sec) 09:44:57
- # PID User PR PPID THRD S VSZ RSS CP SysT UsrT Pct AccuTime RKB WKB MajF MinF Command
- 3104 enlighte 2026833 S 938M33M00.000.00000:09.160400/usr/bin/ktorrent
- 1 root 2000 S 26M3M20.000.00000:01.300000/sbin/init
- 2 root 2000 S 0030.000.00000:00.000000 kthreadd
- 3 root 2020 S 0000.000.00000:00.020000 ksoftirqd/0
- 4 root 2020 S 0000.000.00000:00.000000 kworker/0:0
- 5 root 020 S 0000.000.00000:00.000000 kworker/0:0H
- 7 root RT 20 S 0000.000.00000:00.080000 migration/0
- 8 root 2020 S 0020.000.00000:00.000000 rcu_bh
- 9 root 2020 S 0000.000.00000:00.000000 rcuob/0
上面的输出很像top命令,并且它以磁盘数量降序排列进程。
若只想显示上面的5项进程,可用以下命令实现
- $ collectl --top iokb,5
若想学习上面的列表里哪些字段可以排序,使用如下命令
- $ collectl --showtopopts
- 下面是应用于进程或数据的最高排序类型列表。某些情况下你可能会使用某一字段进行排序,但它并非显示的一部分。
- TOP PROCESS SORT FIELDS
- 进程排序字段
- Memory
- vsz virtual memory
- rss resident (physical) memory
- Time
- syst system time
- usrt user time
- time total time
- accum accumulated time
- I/O
- rkb KB read
- wkb KB written
- iokb total I/O KB
- rkbc KB read from pagecache
- wkbc KB written to pagecache
- iokbc total pagecacge I/O
- ioall total I/O KB (iokb+iokbc)
- rsys read system calls
- wsys write system calls
- iosys total system calls
- iocncl Cancelled write bytes
- PageFaults
- majf major page faults
- minf minor page faults
- flt total page faults
- ContextSwitches
- vctx volunary context switches
- nctx non-voluntary context switches
- Miscellaneous(best when used with--procfilt)
- cpu cpu number
- pid process pid
- thread total process threads (not counting main)
- TOP SLAB SORT FIELDS
- numobj total number of slab objects
- actobj active slab objects
- objsize sizes of slab objects
- numslab number of slabs
- objslab number of objects in a slab
- totsize total memory sizes taken by slabs
- totchg change in memory sizes
- totpct percent change in memory sizes
- name slab names
8. 像top一样使用collectl
为使collectl像top,我们只需以CPU使用率排序输出进程。
- $ collectl --top
输出如下
- # TOP PROCESSES sorted by time (counters are /sec) 14:08:46
- # PID User PR PPID THRD S VSZ RSS CP SysT UsrT Pct AccuTime RKB WKB MajF MinF Command
- 9471 enlighte 2091020 R 63M22M30.030.101300:00.810003/usr/bin/perl
- 3076 enlighte 2026832 S 521M40M20.000.03300:55.140002/usr/bin/yakuake
- 3877 enlighte 20335641 S 1G218M10.000.03310:10.500000/opt/google/chrome/chrome
- 4625 enlighte 20289536 S 1G241M20.000.02208:24.3900012/usr/lib/firefox/firefox
- 5638 enlighte 2033563 S 1G265M10.000.02209:55.040002/opt/google/chrome/chrome
- 1186 root 2011524 S 502M76M00.000.01103:02.960000/usr/bin/X
- 1334 www-data 2013290 S 87M1M20.000.01100:00.850000 nginx:
上面的命令也可用于显示子系统信息。
- $ collectl --top -scm
9. 像ps一样列出进程
为像ps命令一样列出所有进程且没有后续更新,用“c”命令让其计数至1. $ collectl -c1 -sZ -i:1
上面的命令将会列出类似“ps -e”命令的所有进程。“procfilt”用于从所有进程中过滤出特定的进程信息。“procopts”用于指定另一组微调进程列表显示的命令。
10. 像vmstat一样使用collectl
Collectl有内置命令来完成像vmstat一样的功能。
- $ collectl --vmstat
- waiting for1 second sample...
- #procs ---------------memory (KB)--------------- --swaps-- -----io---- --system-- ----cpu-----
- # r b swpd free buff cache inact active si so bi bo in cs us sy id wa
- 1001733M242M1922M1137M710M0001081982391820951
- 1001733M242M1922M1137M710M00001906388610980
- 1001733M242M1922M1137M710M00001739348030960
11. 子系统的详细信息
下面的命令以一秒为间隔,统计5次CPU信息并和时间一起显示出详细信息(冗长)。
- $ collectl -sc -c5 -i1 --verbose -oT
- waiting for1 second sample...
- # CPU SUMMARY (INTR, CTXSW & PROC /sec)
- #Time User Nice Sys Wait IRQ Soft Steal Idle CPUs Intr Ctxsw Proc RunQ Run Avg1 Avg5 Avg15 RunT BlkT
- 14:22:101100000087413122691086610.780.860.7810
- 14:22:111500000084412832496086610.780.860.7810
- 14:22:121700000082413422658086600.780.860.7800
- 14:22:131500000084412412429086610.780.860.7810
- 14:22:141100000088412702488086600.800.870.7800
改变"-s"变量查看不同的子系统。
总结
本文的介绍不过是对collectl这个强大工具的一些浅见。本文本希望展示它有多灵活,其实通过以上的讨论让我们了解了包括记录及回寻捕获的数据,以多种文件格式导出数据并将数据转换为可被广泛的工具分析的格式等等功能的实现。
collectl提供的另一大功能便是像服务一样运行,对远程Linux机器或完整的服务器集群提供远程监控,其表现堪称完美。
Collectl同另一批可用于处理分析收集数据的名为Collectl实用工具 (colmux, colgui, colplot)的功能相契合。如果有机会,我们在之后的文章中会介绍它们。
为更详细的了解Collectl工具,请登录它的主页来学习更多的功能。笔者建议查看FAQs来快速了解collectl,读取collectl文档获取深层次的例子。等价命令表也可定位至更多的像sar,iostat,netstat,top等和collectl功能部分等价的常用工具。
