Sar命令是一个分析系统性能的工具,这里简单介绍以下sar命令如何使用
23时03分27秒 CPU %user %nice %system %iowait %steal %idle 23时03分28秒 all 2.76 0.00 2.01 0.00 0.00 95.23 %user 在用户模式下的百分比 %nice 如果通过renice调整了nice值,那么调整过的程序cpu占用的百分比 %system 在内核运行的百分比 %iowait 在io上阻塞时间的百分比,如果明显高,说明io压力很大 %steal 虚拟cpu等待实际cpu的时间百分比。说明虚拟机性能有问题 %idle 空闲的cpu百分比
23时15分26秒 pgpgin/s pgpgout/s fault/s majflt/s pgfree/s pgscank/s pgscand/s pgsteal/s %vmeff 23时15分27秒 0.00 0.00 77.00 0.00 1126.00 0.00 0.00 0.00 0.00 pgpgin 页面换入计数 pgpgout 页面换出到磁盘的计数 fault 页面错误计数(major + minor) majflt major fault 的计数 pgfree 空闲链表的页面数 pgscank kswapd扫描的页数 pgscand 直接扫描的页数 pgsteal 扫描的页中每秒被回收的数 vmeff pgsteal / pgscan ,也就是回收效率,一直接近0%说明系统内存压力很大
3时26分34秒 kbmemfree kbavail kbmemused %memused kbbuffers kbcached kbcommit %commit kbactive kbinact kbdirty 23时26分35秒 10114900 12329400 2527920 15.80 115168 2967592 9403528 55.63 1030508 4108996 124 kbmemfree 剩余内存,meminfo 的 MemFree kbavail 可用内存,meminfo的MemAvailable kbmemused 已用内存,free命令里面的used %memused 物理内存百分比 kbbuffers buffer使用,meminfo的Buffers kbcached cached使用,meminfo的Cached kbcommit 保证当前系统所需要的内存 %commit kbcommit/MemTotal kbactive 活跃内存数,meminfo的Active kbinact 非活跃内存数,meminfo的Inactive kbdirty 脏页数,meminfo的Dirty
平均时间: DEV tps rkB/s wkB/s dkB/s areq-sz aqu-sz await %util 平均时间: dev7-0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 tps 从物理磁盘读取IO的次数 rkB/s 读扇区的次数 wkB/s 写扇区的次数 dkB/s 丢弃IO的次数 areq-sz I/O 请求的平均大小 aqu-sz I/O请求的平均队列长度 await 每次请求IO的消耗时间,平均的 %util IO请求占用的cpu百分比
17时36分27秒 tps rtps wtps dtps bread/s bwrtn/s bdscd/s 17时36分28秒 0.00 0.00 0.00 0.00 0.00 0.00 0.00 tps 从物理磁盘读取IO的总次数 rtps 读IO请求的次数 wtps 写IO请求的次数 dtps 丢弃IO请求的次数 bread/s 读取的数量 bwrtn/s 写入的数量 bdscd/s 丢弃的数量
17时39分50秒 runq-sz plist-sz ldavg-1 ldavg-5 ldavg-15 blocked 17时39分51秒 0 697 0.10 0.18 0.10 0 runq-sz 等待运行队列长度 plist-sz 任务列表的任务数 ldavg-1 最近一分钟内的平均负载 ldavg-5 最近5分钟内的平均负载 ldavg-15 最近15分钟内的平均负载 blocked 因为IO原因在等待状态的任务数
17时41分09秒 dentunusd file-nr inode-nr pty-nr 17时41分10秒 78017 10304 97509 2 dentunusd 目录缓存中的未使用的缓存数 file-nr 系统文件句柄使用数量 inode-nr 索引节点句柄的使用数量 pty-nr pty终端的使用数量
17时41分39秒 proc/s cswch/s 17时41分40秒 0.00 431.00 proc/s 每秒创建的任务总数 cswch/s 每秒上下文切换的总数
18时13分11秒 INTR intr/s 18时13分12秒 190 28.00 INTR 中断号 intr/s cpu对中断响应的时间
sar -m USB 1 总计: BUS idvendor idprod maxpower manufact product 总计: 3 24ae 4012 200 Rapoo V500RGB Gaming Keyboard BUS USB挂的总线号 idvendor USB的vendor ID idprod USB的product ID maxpower USB设置的最大电流值 manufact 制造商 product USB类型
18时26分54秒 CPU MHz 18时26分55秒 all 2223.78 CPU CPU号 MHz 频率
平均时间: TEMP degC %temp DEVICE 平均时间: 1 29.00 29.00 coretemp-isa-0000 degC 当前摄氏度 %temp 相对设备温度,最大是temp_max
18时32分28秒 IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s %ifutil 18时32分29秒 lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 IFACE 网卡接口 rxpck/s 接收包数量 txpck/s 发送包数量 rxkB/s 接收包数据 txkB/s 发送包数据 rxcmp/s 接收压缩包数量 txcmp/s 发送压缩包数量 rxmcst/s 接收多播包数量 %ifutil 网卡利用率
平均时间: IFACE rxerr/s txerr/s coll/s rxdrop/s txdrop/s txcarr/s rxfram/s rxfifo/s txfifo/s 平均时间: lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 rxerr/s 接收到的损坏包 txerr/s 发送包的损坏数 coll/s 当发送数据包时候,每秒钟发生的冲撞(collisions)数,这个是在半双工模式下才有 rxdrop/s 因为网络缓冲区满,接收时丢弃的包数量 txdrop/s 因为网络缓冲区满,发送时丢弃的包数量 txcarr/s carrier-errors发生的次数 rxfram/s 接收包时发生帧对齐错误的次数 rxfifo/s 接收包发生缓冲区溢出的次数 txfifo/s 发送包发生缓冲区溢出的次数
18时46分51秒 imsg/s omsg/s iech/s iechr/s oech/s oechr/s itm/s itmr/s otm/s otmr/s iadrmk/s iadrmkr/s oadrmk/s oadrmkr/s 18时46分52秒 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 imsg/s 接收到的ICMP包数量 icmpInMsgs omsg/s 发送的ICMP包数量 icmpOutMsgs iech/s icmpInEchos的数量 iechr/s icmpInEchoReps的消息数 oech/s icmpOutEchos消息数 oechr/s icmpOutEchoReps消息数 itm/s icmpInTimestamps的数量 itmr/s icmpInTimestampReps的数量 otm/s icmpInTimestampReps的数量 otmr/s icmpOutTimestampReps的数量 iadrmk/s ICMP 地址掩码请求消息的数量 iadrmkr/s ICMP 地址掩码回复消息的数量 oadrmk/s ICMP 地址掩码请求消息的数量 oadrmkr/s 发送的 ICMP 地址掩码回复消息的数量
19时11分13秒 irec/s fwddgm/s idel/s orq/s asmrq/s asmok/s fragok/s fragcrt/s irec/s 接收到的报文数 fwddgm/s 转发的报文数 idel/s 成功发送的报文数 orq/s 向IP层提供的报文数 asmrq/s 接收的IP分片数 asmok/s 成功重组的IP报文数 fragok/s 成功分片的报文数 fragcrt/s 产生的分片数
19时12分15秒 totsck tcpsck udpsck rawsck ip-frag tcp-tw totsck 被使用的socket数 tcpsck TCP的socket数 udpsck UDP的socket数 rawsck RAW的socket数 if-frag IP分片的数 tcp-tw 处于TIME-WAIT状态的连接数量
19时12分38秒 CPU total/s dropd/s squeezd/s rx_rps/s flw_lim/s total/s 网络帧数 dropd/s 溢出丢弃的网络帧数 squeezd/s 软中断的次数 rx_rps/s 唤醒cpu的次数 flw_lim/s 达到流量限制的次数
19时14分45秒 active/s passive/s iseg/s oseg/s active/s:主动连接数 passive/s:被动连接数 iseg/s:每秒接收的段总数 oseg/s:每秒发送的段总数
19时20分22秒 atmptf/s estres/s retrans/s isegerr/s orsts/s atmptf/s 重试失败数 estres/s 断开连接数 retrans/s 重传数 isegerr/s 错误数 orsts/s 包含RST flag的tcp段数
19时16分14秒 idgm/s odgm/s noport/s idgmerr/s idgm/s 每次接收的 UDP 数据报总数 odgm/s 每秒发送的 UDP 数据报总数 noport/s 接收到但是却没有应用程序在指定目的端口的数据个数 idgmerr/s 本机接收到但却无法派发的数据个数
七七八八总算整理完了sar命令的这些用法,但实际上工作中用不到这么多。或者sar的一些监控命令也可以通过其他命令实现。 不过需要留一个印象的是,如果想监控内存,缓存,CPU,IO,网络,中断这些通常需要监控的信息,可以尝试一下sar命令。