Chinaunix首页 | 论坛 | 博客
  • 博客访问: 8049601
  • 博文数量: 594
  • 博客积分: 13065
  • 博客等级: 上将
  • 技术积分: 10324
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-26 16:44
个人简介

推荐: blog.csdn.net/aquester https://github.com/eyjian https://www.cnblogs.com/aquester http://blog.chinaunix.net/uid/20682147.html

文章分类

全部博文(594)

分类: LINUX

2008-07-04 17:48:11

/**
 * sar man手册简译, 欢迎大家补充、指正
 * Author: cnscn
 * Time  : 2006-10-17 09:10
 *
 */

sar ---  收集、报告或保存系统活动信息 Collect, report, or save system activity information

Options:
  -A    列出保存的当天的所有活动的文件内容, 等同于-bBcdqrRuvwWy -I SUM -n FULL -P ALL

  -b    报告I/O和传送速率统计。这个参数仅用于2.5及以后内核。可显示以下字段
        tps        每秒从物理磁盘I/O的次数。多个逻辑请求会被合并为一个I/O磁盘请求。一次传输的大小是不确定的
         rtps      每秒的读请求数
         wtps      每秒的写请求数
         bread/s   每秒读磁盘的数据块数(in blocks  1 block = 512B, 2.4以后内核)
         bwrtn/s   每秒写磁盘的数据块数(in blocks  1 block = 512B, 2.4以后内核)

  -B     显示内核页统计。 可显示如下字段
         pgpgin/s
         pgpgout/s
         fault/s
         majflt/s

  -c     显示进程创建活动, 显示如下字段
         proc/s    每秒进程创建数

  -d m n  报告每个块设备的活动情况(2.4及以后内核)
         m 每m秒采样一次
         n 共采样n次
         sar -d 30 5
         Average:          DEV       tps  rd_sec/s  wr_sec/s  avgrq-sz  avgqu-sz     await     svctm     %util
                          dev8-0    2.39     16.37     35.99     21.88      0.00      0.85      0.66      0.16
         tps             显示指定设备的每秒I/O流量,多个逻辑请求可以合并为一个物理请求,流量为不确定大小
         rd_sec/s        从设备读取的扇区数,(1扇区=512B)
         wr_sec/s        写入设备的扇区数
         avgrq-sz        流出设备的扇区数
         avgqu-sz        流出设备的平均队列长度
         await           从设备流出的平均I/O请时间,包括请求在队列和服务时的时间
         svctm           平均I/O请求的服务时间
         %util           I/O请求的CPU时间百分比,当数字接近100%时,设备出现饱和

  -H
  -h
  -i interval     选取尽可能接近interval所标识的数量的记录数 (Select data records at  seconds as close as possible to the number specified by the interval parameter)

  -q    报告队列长度和平均负载,可列出下列字段
        runq-sz    执行中的队列长度(等待运行的进程数)
        plist-sz   进程列表中的进程数
        ldavg-1    最后一分钟的系统负载
        ldavg-5    最后5分钟的系统负载
        ldavg-15   最后15?种拥南低掣涸?

  -r    报告memory和swap使用统计,可列出如下字段
        kbmemfree  可用的内存数(kB)
        kbmemused  应用中的内存数,但不包括内核使用的内存(kB)
        %memused   内存的使用百分比
        kbcached   内核用于cache的内存数(kB)
        kbswpfree
        kbswpused
        %swpused
        kbswpcad   用于cache的swap内存数(kB)

  -R    报告内存活动,可列出如下字段
        frmpg/s    每秒空闲的内存页数,负值表示系统已经分配了的内存页数。注意:依据机器体系的不同,内存页的大小有4kB或8kB
        bufpg/s    每秒系统用于buffers的附加的内存页数。负值表示较少的页数用于系统buffers
        campg/s    每秒系统用于cached的附加的内存页数。负值表示较少的页数用于系统cached

  -t
  -u  列出cpu的使用情况,可列出下列字段
       %user      用户层
       %nice   用户层
       %system  系统层
       %iowait  系统有外部磁盘I/O请求时的cpu(s)的空闲时间百分不(Percentage of %time that the CPU or CPUs were idle during which the system had an outstanding disk I/O request)
       %idle      系统没有外部磁盘I/O请求时的cpu(s)的空闲时间百分不(Percentage of time that the CPU or CPUs were idle and the system did not have an outstanding disk I/O request)


  -v   报告文件或其它内核表的inode的状态,可列出如下字段
       dentunusd   Number of unused cache entries in the directory cache.
       file-sz     已经使用了的文件句柄数 Number of used file handles
       inode-sz    Number of allocated disk quota entries.
       super-sz    内核已经分配了的超级块的句柄 Number of super block handlers allocated by the kernel
       %super-sz   Percentage of allocated super block handlers with regard to the maximum  number  of  super block handlers that Linux can allocate.
       dquot-sz    已经分配了的磁盘限额入口数 Number of allocated disk quota entries.
       %dquot-sz   Percentage  of  allocated  disk  quota entries with regard to the maximum number of cached disk quota entries that can be allocated.
       rtsig-sz    队列中RT信号数 Number of queued RT signals.
       %rtsig-sz   Percentage of queued RT signals with regard to the maximum number of RT signals that can be queued.

  -V  列出版本号和用法
  -w  报告系统交换活动,列出如下字段
    cswch/s      系统每秒交换活动的次数 Total number of context switches per second

  -W 报告swapping活动信息,可列出如下字段
    pswpin/s     每秒系统带来的交换页数 Total number of swap pages the system brought in per second.
      pswpout/s    系统每秒带出、拿出的交换页数

  -y
  -n {DEV|EDEV|SOCK|FULL}
     报告网络活动统计
     DEV    指定列出所有网络设备的活动统计,可列出如下字段
            IFACE      网络接口卡设备名,如eth0
            rxpck/s    每秒收到的包数
            txpck/s    每秒传输的包数

            rxbyt/s    每秒收到的数据字节数
            txbyt/s    每秒传输的数据字节数

            rxcmp/s    每秒收到的压缩包数
            txcmp/s    每秒传输的压缩包数

            rxmcst/s   每秒收到的多播包数


     EDEV  指定列出所有网设备失败包的情况,可列出如下字段
           IFACE       网络接口卡设备名
           rxerr/s     每秒收到的总的失败包数
           txerr/s     每秒钟传输时的错误包数
           coll/s      每秒钟传输时的冲突包数
           rxdrop/s    每秒钟收到的包中由于Linux空间缺乏而丢弃的包数
           txdrop/s    每秒钟传输过程中由于Linux空间缺乏而丢弃的包数
           txcarr/s    每秒钟传输过程中的carrier-errors的数目
           rxfram/s    每秒钟收到的帧序列错误数
           rxfifo/s    每秒钟FIFO泛滥错误包数
           txfifo/s    每秒钟传输时FIFO泛滥的错误包数

     NFS   列出NFS客户端活动报告。 列出如下字段
           call/s      每秒成功的RPC请求数
           retrans/s   (由于server超时)每秒需重新传输的RPC请求数
           read/s      每秒成功的RPC的read请求数
           write/s     每秒成功的RPC的write请求数
           access/s    每秒成功的RPC的access请求数
           getatt/s    每秒成功的RPC的getattr请求数

     NFSD  列出NFS服务端活动报告。列出如下字段
           totsck      总的socktes数
           tcpsck      当前应用中的tcp sockets数
           udpsck      当前应用中的udp sockets数
           rawsck      当前应用中的RAW sockets数
           ip-frag     当前应用中的IP帧数

     FULL  等于指定-n选项的所有参数

  -x {pid|SELF|ALL}
  -X {pid|SELF|ALL}
  -I {irq|SUM|ALL|XALL}
     报告中断统计资料。
     irq    是中断号,指定多个-I irq参数可以观看到多个相关中断的情况
     SUM    指定显示每秒中接收到的所有中断情况
     ALL    指定显示所有中断的前16个中断情况
     XALL   指定显示所有中断包括潜在的APIC中断源


  -P {cpu|ALL}
     如果缺省-P则报告系统内的所有CPU的统计。如果参数为ALL,则报告每一个CPU和所有CPU的统计数据
     [root@localhost ~]# sar -P 0
     Linux 2.6.17-1.2187_FC5smp (localhost.localdomain)      2006年10月17日
     08时30分01秒       CPU     %user     %nice   %system   %iowait     %idle
     08时40分01秒         0      6.24      0.00      0.64      0.02     93.10

     [root@localhost ~]# sar -P 1
     Linux 2.6.17-1.2187_FC5smp (localhost.localdomain)      2006年10月17日
     08时30分01秒       CPU     %user     %nice   %system   %iowait     %idle
     08时40分01秒         1      7.66      0.00      0.60      0.03     91.71


  -o [filename]
     把报告输出到文件,否则显示到屏幕. 如果忽略filename,那么系统将把输出添加到/var/log/sa/sadd定时生成文件内(dd代表当前日期)

  -f [filename]
     从filename中提取预先保存在文件内的记录,并显示到屏幕上. 缺省filename则从/var/log/sa/sadd内提取

  -s [hh:mm:ss]
     设置报告的开始时间, Set  the starting time of the data, causing the sar command to extract records time-tagged at, or following, the time specified. The default starting time is  08:00.   Hours  must  be  given  in 24-hour format. This option can be used only when data are read from a file (option -f )

  -e [hh:mm:ss]
     设置报告的结束时间, The default ending time is 18:00:00.This  option  can  be  used  only when data are read from or written to a file (options -f or -o )


     [interval]    选择记录的时间间隔(秒)

     [count]       <默认为1>

     sar 向标准输出列出选择的活动的累积数量。在多帐户系?衬冢?ǜ嬉?ount(数量)和interval(时间间隔)参数,以指定秒数为时间间隔的指定的次数信息.
     如果interval参数指定为0,则sar显示系统启动以来的平均时间统计。
     如果count参数指定为0,则报告将不连续不断的进行。

     如果不指定参数,则仅显示CPU的活动,如果CPU使用率接近100% (user + nice + system), 则显示出CPU局限
     [root@localhost ~]# sar
     08时26分00秒       LINUX RESTART
     08时30分02秒       CPU     %user     %nice   %system   %iowait     %idle
     08时40分01秒       all      6.07      0.00     33.86      7.94     52.13
     08时50分01秒       all      2.26      0.00     28.32      0.77     68.66
     09时00分01秒       all      0.44      0.00     26.75      0.29     72.52
     09时10分01秒       all      0.97      0.00     26.87      0.05     72.12
     09时20分01秒       all      1.39      0.00     27.13      0.06     71.43
     Average:           all      2.22      0.00     28.58      1.82     67.38


    如果需要多个样本和报告,那么可以如下所做
    sar -o data.file interval count >/dev/null 2>&1 &

    [root@localhost ~]# sar -u 2 5 报告CPU的使用情况,每2秒钟一次共输出5行
    09时01分53秒       CPU     %user     %nice   %system   %iowait     %idle
    09时01分55秒       all     36.41      0.00      2.49     47.38     13.72
    09时01分57秒       all     38.40      0.00     18.20     36.91      6.48
    09时01分59秒       all     32.50      0.00      4.50     52.00     11.00
    09时02分01秒       all     44.00      0.00     48.50      7.25      0.25
    09时02分03秒       all     36.91      0.00     30.42     27.93      4.74
    Average:          all     37.64      0.00     20.82     34.30      7.24

    sar -I 14 -o int14.file 2 10
       每2秒报告一次14号中断的情况,共输出10行,并把结果保存到文件int14.file内
       Report  statistics  on  IRQ  14 for each 2 seconds. 10 lines are displayed.  Data are stored in a file called int14.file.

    sar -r -n DEV -f /var/log/sa/sa16
     列出每天保存在/var/log/sa/sa16内的内存、交换分区、网络活动情况
     Display memory, swap space and network statistics saved in daily data file ’sa16’.

    sar -A
      列出保存的当天的活动文件内容
      Display all the statistics saved in current daily data file.
阅读(2097) | 评论(3) | 转发(0) |
给主人留下些什么吧!~~

Aquester2008-07-04 17:53:27

在使用UNIX操作系统的过程中,我们常常会用到各种各样的问题,比如系统运行速度突然变慢,系统容易死机或者主机所带的终端常出现死机,这时我们常常猜测,是硬盘空间太小,还是内存不足?I/O出现瓶颈,或者是系统的核心参数出了问题?这时,我们应该考虑使用系统给我们提供的sar命令来对系统作一个了解,该命令是系统维护的重要工具,主要帮助我们掌握系统资源的使用情况,特别是内存和CPU 的使用情况,是UNIX系统使用者应该掌握的工具之一。sar 命令行的常用格式: sar [options] [-A] [-o file] t [n] 在命令行中,n 和t 两个参数组合起来定义采样间隔和次数,t为采样间隔,是必须有的参数,n为采样次数,是可选的,默认值是1,-o file表示将命令结果以二进制格式存放在文件中,file 在此处不是关键字,是文件名。options 为命令行选项,sar命令的选项很多,下面只列出常用选项:       -A:所有报告的总和。        -u:CPU利用率        -v:进程、I节点、文件和锁表状态。        -d:硬盘使用报告。  

Aquester2008-07-04 17:52:35

# sar -n DEV -u 1 10 看看当前网络流量 # iostat -t 1 10 看看当前硬盘读写速度

aquester2008-07-04 17:50:57

使用sar查看流量: sar -n DEV 1 5 每1秒查看一次,连接看5次。