在 Ubuntu 18.04 LTS 上安装和使用 collectl 性能监控工具
本教程适用于这些操作系统版本
- Ubuntu 20.04(Focal Fossa)
- Ubuntu 18.04(仿生海狸)
在此页
- 要求
- 开始
- 安装 Collectl
- 与 Collectl 合作
- 监控 CPU、内存和磁盘使用情况
- 同时监控 CPU、内存和磁盘
- 结论
监控系统资源和性能分析是任何系统管理员的一项重要任务。 Linux 有很多工具可以用来监控系统性能,包括 top、htop、free 等。Collectl 是一个免费、开源、轻量级的性能监控工具,可以用来收集系统资源的信息,比如 cpu、磁盘、内存、网络、Infiniband、lustre、内存、nfs、slab 等等。与其他监控工具不同,collectl 专注于一小组统计数据。 Collectl 能够同时监控不同的参数,并以合适的方式报告它们。 Collectl 带有大量选项,可帮助您识别任何类型的系统性能问题。使用 collectl,您可以生成与 mpstat、netstat、nfsstat、sar、ps、top 和 iostat 相同的输出。
特征
- 能够以多种格式显示输出。
- 以各种文件格式导出数据。
- 能够作为服务运行以监控远程机器。
- 监控几乎所有子系统。
在本教程中,我们将学习如何在 Ubuntu 18.04 服务器上安装和使用 Collectl。
要求
- 一台运行 Ubuntu 18.04 的服务器。
- 已为您的服务器设置根密码。
入门
在开始之前,您需要使用最新版本更新您的系统。您可以通过运行以下命令来执行此操作:
apt-get update -y
apt-get upgrade -y
服务器更新后,重新启动服务器以应用更改。
安装 Collectl
默认情况下,Collectl 在 Ubuntu 18.04 默认存储库中可用。您可以通过运行以下命令来安装它:
apt-get install collectl -y
安装完成后,您可以运行以下命令列出 collectl 可用的所有选项:
collectl --h
您应该看到以下输出:
This is a subset of the most common switches and even the descriptions are
abbreviated. To see all type 'collectl -x', to get started just type 'collectl'
usage: collectl [switches]
-c, --count count collect this number of samples and exit
-f, --filename file name of directory/file to write to
-i, --interval int collection interval in seconds [default=1]
-o, --options options misc formatting options, --showoptions for all
d|D - include date in output
T - include time in output
z - turn off compression of plot files
-p, --playback file playback results from 'file' (be sure to quote
if wild carded) or the shell might mess it up
-P, --plot generate output in 'plot' format
-s, --subsys subsys specify one or more subsystems [default=cdn]
--verbose display output in verbose format (automatically
selected when brief doesn't make sense)
Various types of help
-h, --help print this text
-v, --version print version
-V, --showdefs print operational defaults
-x, --helpextend extended help, more details descriptions too
-X, --helpall shows all help concatenated together
--showoptions show all the options
--showsubsys show all the subsystems
--showsubopts show all subsystem specific options
--showtopopts show --top options
--showheader show file header that 'would be' generated
--showcolheaders show column headers that 'would be' generated
--showslabaliases for SLUB allocator, show non-root aliases
--showrootslabs same as --showslabaliases but use 'root' names
Copyright 2003-2016 Hewlett-Packard Development Company, L.P.
collectl may be copied only under the terms of either the Artistic License
or the GNU General Public License, which may be found in the source kit
使用 Collectl
现在,不带任何选项运行 collectl 将以非常简短且易于阅读的格式显示有关 cpu、磁盘和网络统计信息的信息。
collectl
您应该看到以下输出:
waiting for 1 second sample...
#<--------cpu--------><----------disks-----------><----------network---------->
#cpu sys inter ctxsw KBRead Reads KBWrit Writes KBIn PktIn KBOut PktOut
17 11 503 320 4 1 20 3 0 0 0 0
2 1 565 165 0 0 0 0 0 2 0 2
6 3 545 83 0 0 0 0 0 2 0 2
0 0 508 39 0 0 0 0 0 2 0 2
1 1 517 42 0 0 0 0 0 2 0 2
1 1 442 37 0 0 0 0 0 2 0 2
1 1 538 65 0 0 20 2 0 2 0 2
1 1 443 39 0 0 0 0 0 2 0 2
1 1 409 39 0 0 0 0 0 2 0 2
1 1 381 38 0 0 0 0 0 2 0 2
1 1 451 44 0 0 0 0 0 2 0 2
3 2 482 42 0 0 0 0 0 2 0 2
9 2 528 101 0 0 0 0 0 2 0 2
1 1 428 39 0 0 0 0 0 2 0 2
您还可以使用以下命令列出所有子系统的统计信息:
collectl --all
输出:
waiting for 1 second sample...
#<--------cpu--------><-----------------memory-----------------><----------disks-----------><----------network----------><-------tcp--------><------sockets-----><----files---><------nfs totals------="">
#cpu sys inter ctxsw Cpu0 Free Buff Cach Inac Slab Map Fragments KBRead Reads KBWrit Writes KBIn PktIn KBOut PktOut IP Tcp Udp Icmp Tcp Udp Raw Frag Handle Inodes Reads Writes Meta Comm
3 0 459 48 459 139M 63M 573M 413M 93M 136M jibaa4a59ab 0 0 0 0 0 0 0 0 0 0 0 0 144 0 0 0 1088 44711 0 0 0 0
12 7 528 142 530 139M 63M 573M 413M 93M 136M jhbaa5959ab 0 0 0 0 0 2 1 2 0 0 0 0 144 0 0 0 1088 44711 0 0 0 0
3 1 477 57 477 139M 63M 573M 413M 93M 136M jhbaa5959ab 0 0 0 0 0 2 0 2 0 0 0 0 144 0 0 0 1088 44711 0 0 0 0
5 2 437 55 435 139M 63M 573M 413M 93M 136M jhbaa5959ab 0 0 0 0 0 2 0 2 0 0 0 0 144 0 0 0 1088 44711 0 0 0 0
1 0 426 43 426 139M 63M 573M 413M 93M 136M jhbaa5959ab 0 0 0 0 0 2 0 2 0 0 0 0 144 0 0 0 1088 44711 0 0 0 0
4 1 435 54 435 139M 63M 573M 413M 93M 136M jhbaa5959ab 0 0 0 0 0 2 0 2 0 0 0 0 144 0 0 0 1088 44711 0 0 0 0
4 2 471 49 472 139M 63M 573M 413M 93M 136M jhbaa5959ab 0 0 0 0 0 2 0 2 0 0 0 0 144 0 0 0 1088 44712 0 0 0 0
您还可以使用带有 --top 选项的 collectl 命令,如下所示:
collectl --top
输出:
# TOP PROCESSES sorted by time (counters are /sec) 14:14:24
# PID User PR PPID THRD S VSZ RSS CP SysT UsrT Pct AccuTime RKB WKB MajF MinF Command
5194 root 20 1233 0 R 66M 27M 0 0.06 0.13 19 00:02.79 0 0 0 0 /usr/bin/perl
8 root 20 2 0 I 0 0 0 0.01 0.00 1 00:01.86 0 0 0 0 rcu_sched
1165 root 20 866 0 S 103M 7M 0 0.01 0.00 1 00:05.00 0 0 0 0 sshd:
3593 root 20 2 0 I 0 0 0 0.01 0.00 1 00:01.45 0 0 0 0 kworker/0:0
1 root 20 0 0 S 76M 9M 0 0.00 0.00 0 00:10.28 0 0 0 0 /sbin/init
2 root 20 0 0 S 0 0 0 0.00 0.00 0 00:00.02 0 0 0 0 kthreadd
4 root 0 2 0 I 0 0 0 0.00 0.00 0 00:00.00 0 0 0 0 kworker/0:0H
6 root 0 2 0 I 0 0 0 0.00 0.00 0 00:00.00 0 0 0 0 mm_percpu_wq
7 root 20 2 0 S 0 0 0 0.00 0.00 0 00:02.75 0 0 0 0 ksoftirqd/0
9 root 20 2 0 I 0 0 0 0.00 0.00 0 00:00.00 0 0 0 0 rcu_bh
10 root RT 2 0 S 0 0 0 0.00 0.00 0 00:00.00 0 0 0 0 migration/0
11 root RT 2 0 S 0 0 0 0.00 0.00 0 00:00.03 0 0 0 0 watchdog/0
12 root 20 2 0 S 0 0 0 0.00 0.00 0 00:00.00 0 0 0 0 cpuhp/0
13 root 20 2 0 S 0 0 0 0.00 0.00 0 00:00.00 0 0 0 0 kdevtmpfs
14 root 0 2 0 I 0 0 0 0.00 0.00 0 00:00.00 0 0 0 0 netns
15 root 20 2 0 S 0 0 0 0.00 0.00 0 00:00.00 0 0 0 0 rcu_tasks_kthre
16 root 20 2 0 S 0 0 0 0.00 0.00 0 00:00.00 0 0 0 0 kauditd
监控 CPU、内存和磁盘使用情况
您可以通过运行带有 -sc 选项的 collectl 来监控 CPU 使用情况:
collectl -sc
输出:
waiting for 1 second sample...
#<--------cpu-------->
#cpu sys inter ctxsw
1 1 461 35
2 2 631 71
11 0 472 109
1 1 552 48
1 1 457 39
0 0 566 46
5 3 572 101
0 0 543 38
1 1 445 40
1 1 591 43
1 1 441 36
0 0 565 51
您还可以使用以下命令查看 CPU 使用率的详细信息:
collectl -sC
输出:
waiting for 1 second sample...
# SINGLE CPU STATISTICS
# Cpu User Nice Sys Wait IRQ Soft Steal Guest NiceG Idle
0 2 0 3 0 0 0 0 0 0 94
0 0 0 1 0 0 0 0 0 0 98
0 0 0 1 0 0 0 0 0 0 98
0 0 0 0 0 0 1 0 0 0 98
0 0 0 0 0 0 0 0 0 0 100
0 0 0 0 0 0 0 0 0 0 100
0 1 0 1 0 0 0 0 0 0 97
0 0 0 0 0 0 0 0 0 0 100
0 0 0 1 1 0 1 0 0 0 96
0 0 0 0 0 0 0 0 0 0 100
0 0 0 1 0 0 0 0 0 0 98
要监控系统的内存使用情况,请运行以下命令:
collectl -sm
输出:
waiting for 1 second sample...
#<-----------memory----------->
#Free Buff Cach Inac Slab Map
139M 63M 573M 413M 93M 136M
139M 63M 573M 413M 93M 136M
139M 63M 573M 413M 93M 136M
139M 63M 573M 413M 93M 136M
139M 63M 573M 413M 93M 136M
139M 63M 573M 413M 93M 136M
139M 63M 573M 413M 93M 136M
139M 63M 573M 413M 93M 136M
139M 63M 573M 413M 93M 136M
使用以下命令使用详细信息监视内存使用情况:
collectl -sM
输出:
waiting for 1 second sample...
# MEMORY STATISTICS
# Node Total Used Free Slab Mapped Anon AnonH Locked Inact HitPct
0 985M 866844K 142800K 95928K 46160K 93416K 0 5408K 423952K 100.00
0 985M 866844K 142800K 95928K 46160K 93416K 0 5408K 423952K 100.00
0 985M 866844K 142800K 95928K 46160K 93416K 0 5408K 423952K 100.00
0 985M 866844K 142800K 95928K 46160K 93416K 0 5408K 423952K 100.00
0 985M 866844K 142800K 95928K 46160K 93416K 0 5408K 423952K 100.00
0 985M 866844K 142800K 95928K 46160K 93416K 0 5408K 423952K 100.00
0 985M 866968K 142676K 95928K 46160K 93416K 0 5408K 423952K 100.00
您可以使用以下命令监控磁盘使用情况:
collectl -sd
输出:
waiting for 1 second sample...
#<----------disks----------->
#KBRead Reads KBWrit Writes
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 8 0
0 0 0 2
使用以下命令使用详细信息监视磁盘使用情况:
collectl -sD
输出:
waiting for 1 second sample...
# DISK STATISTICS (/sec)
# <---------reads---------------><---------writes--------------><--------averages--------> Pct
#Name KBytes Merged IOs Size Wait KBytes Merged IOs Size Wait RWSize QLen Wait SvcTim Util
sda 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
sda 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
sda 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
sda 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
sda 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
sda 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
sda 0 0 0 0 0 20 1 1 20 0 20 0 0 0 0
sda 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
同时监控 CPU、内存和磁盘
您可以通过运行单个命令来监控 CPU、内存和磁盘使用情况:
collectl -scmd
输出:
waiting for 1 second sample...
#<--------cpu--------><-----------memory-----------><----------disks----------->
#cpu sys inter ctxsw Free Buff Cach Inac Slab Map KBRead Reads KBWrit Writes
1 0 518 43 140M 63M 573M 413M 93M 135M 0 0 0 0
7 2 509 104 140M 63M 573M 413M 93M 135M 0 0 20 1
3 1 518 52 140M 63M 573M 413M 93M 135M 0 0 0 0
1 1 445 43 140M 63M 573M 413M 93M 135M 0 0 0 0
2 1 482 51 140M 63M 573M 413M 93M 135M 0 0 0 0
1 1 535 56 140M 63M 573M 413M 93M 135M 0 0 0 0
3 1 499 48 140M 63M 573M 413M 93M 135M 0 0 0 0
2 1 482 53 140M 63M 573M 413M 93M 135M 0 0 20 2
结论
在上面的文章中,我简要概述了 collectl。 Collectl 带有许多选项,可以轻松监控您的 Linux 系统。