sysstat

(0 comments)

对系统进行性能调试的工具有很多,这些可以两大类:一类是标准的分析工具,即所有的 UNIX 都会带的分析工具; 另一类是不同厂商的 UNIX 所特有或第三方的性能分析工具,比如 HP-UX 就有自己的增值性能分析工具。

标准的分析工具,即所有的 UNIX 都会带的分析工具有:

  • sar
  • iostat
  • vmstat
  • time
  • ps
  • bdf
  • top
  • ipcs
  • uptime

按性能分析工具的用途可以分为:

  • CPU 的使用情况:sar, time, top, ps, puma, xps
  • 内存的使用情况:vmstat, ipcs
  • 文件系统状态:dbf, iostat, sar, swapinfo, nfsstat
  • I/O 子系统状态:iostat
  • 网络性能:netstat

uptime

计算系统的平均负载值,这个值是在综合系统的很多参数后计算出来的,一般系统的平均负载不应该超过 2.00。

# uptime
11:22:17 up 1 day,  2:31,  7 users,  load average: 0.17, 0.14, 0.10

top

top 启动时可以指定一些选项:

  1. s time # 屏幕刷新的时间间隔,缺省为 5 秒
  2. d count # 屏幕刷新 count 次后自动退出
  • 通过 RSS 列可以知道每个进程占用内存的数量。
  • 通过 NICE 列可以知道系统是否使用 NICE 值来调节该进程的工作负载平衡。
top -p 1 -n 1

sar

对系统的当前状态进行取样,然后通过计算数据和比例来表达系统的当前运行状态。它可以连续对系统取样,获得大量的取样数据,并将取样数据和分析的结果都可以入文件,而采集数据所需的负载很小。

sar 可以从一个文件中读取性能数据,这个文件一般通过 sadc 命令生成。通常使用 crontab 运行 shell 脚本 sa1 和 sa2 来采集数据,因此你也可以根据需要修改脚本。

# /etc/cron.d/sysstat
# run system activity accounting tool every 10 minutes
*/10 * * * * root /usr/lib/sa/sa1 1 1
# generate a daily summary of process accounting at 23:53
53 23 * * * root /usr/lib/sa/sa2 -A

time

汇报出执行某条命令所花的时间。它的输出包括:实际时间,用户时间和系统时间。

# time find /etc -name "hosts"
/etc/hosts

real    0m1.663s
user    0m0.028s
sys     0m0.126s

vmstat

对系统的进程、内存、SWAP、I/O、CPU 活动进行监视,但是 不能对某个进程进行深入分析,它仅是对系统的整体情况进行分析。

内存状态平均值

# vmstat
procs -----------memory---------- ---swap-- -----io---- --system-- ----cpu----
r  b   swpd   free   buff  cache   si   so    bi    bo   in    cs us sy id wa
 1  0 524732  19008   1184 1731888    1    1     3    16    6     0 17  6 76  1

vmstat 还可以指定时间间隔采集多次的数据,例如每隔 1 秒钟执行一次,共运行 10 次。

vmstat 1 10

iostat

对系统的磁盘操作活动进行监视,汇报磁盘活动统计情况,同时也会汇报出终端和 CPU 使用情况。和 vmstat 一样,它也仅是对系统的整体情况进行分析。

I/O 状态平均值

# iostat
avg-cpu:  %user   %nice    %sys %iowait   %idle
17.46    0.01    5.50    0.90   76.13

Device:            tps   Blk_read/s   Blk_wrtn/s   Blk_read   Blk_wrtn
sda             103.10       156.58      1937.04  104161800 1288561146

mpstat

对 CPU 相关的活动进行统计。

CPU 状态平均值

# mpstat
12:35:19 PM  CPU   %user   %nice %system %iowait    %irq   %soft   %idle    intr/s
12:35:19 PM  all   17.49    0.01    5.13    0.91    0.05    0.34   76.09   1705.64

在多块 CPU 的系统中,如果想查看每块 CPU 的情况,可以加上 -P 参数。

mpstat -P ALL
Currently unrated

Comments

There are currently no comments

New Comment

required

required (not published)

optional

required