ITPub博客

首页 > Linux操作系统 > Linux操作系统 > linux系统查看系统资源分析性能情况

linux系统查看系统资源分析性能情况

原创 Linux操作系统 作者:datapeng 时间:2013-12-15 11:36:03 0 删除 编辑

1,top命令查看cpu,mem的使用情况

PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
21093 root      15   0 12700  736  524 S    2  0.0  80:01.36 cmahostd
 1 root      15   0 10324   84   52 S    0  0.0   1:10.26 init
 2 root      RT  -5     0    0    0 S    0  0.0   0:27.31 migration/0
%cpu           进程所占cpu时间的百分比
%mem           进程所占内存的百分比

2,top 后,在shift + p 所占进程的排序显示

3,top 后,在shift + m 所占内存的排序显示
从前面三行来年看,如果cpu比较空闲,比如大于50%,通常情况来说,比较正常的!

  PID USER      PR  NI  VIRT  RES  SHR S   %CPU %MEM  TIME+  COMMAND
 11981 root      34  19  276m  43m 1452 S    0  1.1  64:22.57 yum-updatesd
 2601 apacheus  15   0  413m  37m 5376 S    0  1.0   0:00.76 httpd
 18833 apacheus  15   0  415m  36m 5908 S    0  0.9   0:01.49 httpd
 18832 apacheus  15   0  415m  35m 5804 S    0  0.9   0:02.19 httpd
 22881 apacheus  15   0  415m  35m 5924 S    0  0.9   0:01.62 httpd4

vmstat 2 表示每隔2秒查看一下内存,交换分区,i/o,cpu的使用情况

[root@mytest ~]# vmstat 2
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu------
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 0  0 182164 187684 708508 1997704    0    0     1     5    0    0  0  0 100  0  0
 1  0 182164 187396 708508 1997708    0    0     0    36 1020 2203  0  0 99  0  0
 0  0 182164 187708 708508 1997712    0    0     0   114 1056 2367  1  0 99  0  0

memory下的参数说明:

swpd:                 已用的交换空间数量
free:                 空闲内存数量
buff:                 缓冲使用的内存数量
cache:             文件系统缓存使用的内存数量

swap交换分区下的参数说明:
si:                   从磁盘转换到内存的数量
so:                   从内存转换到磁盘的数量

i/o磁盘i/o下的参数说明:

bi:                   从块设备读的数量
bo:                   写块设备的数量

cpu下的一些参数说明:

us:                  用户方式下所占CPU工作时间的百分比
sy:                  内核进程所占cpu工作时间的百分比
id:                  cpu处在空闲状态下的时间百分比
wa:                  等待I/O所占用CPU工作时间的百分比

如果发现r所在的列显示的数据比较大,并且经常超过cpu的进程数量,说明cpu不够,等等的事务较多,cpu资源不足,这时候就要分析是哪些占用了较多资源


5,df 查看磁盘的使用情况

[root@mytest ~]# df

Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol01
                       31G  5.1G   25G  18% /
/dev/mapper/VolGroup00-LogVol02
                       39G   13G   25G  35% /u01
/dev/mapper/VolGroup00-LogVol04
                      126G   36G   84G  30% /backup
/dev/mapper/VolGroup00-LogVol03
                       39G  182M   37G   1% /archive
/dev/cciss/c0d0p1     190M   28M  153M  16% /boot
tmpfs                 7.7G     0  7.7G   0% /dev/shm
192.168.11.20:/archive/node1
                       39G  185M   37G   1% /archive/node1
used                          表示已使用了多少
available                     表示还有多少空间可用
use%                          磁盘的使用率
最后一行,表示使用了nfs,远程挂载

6,mpstat和sar查看cpu的运行情况,这二个差不多

[root@mytest ~]# mpstat

11:38:39 AM  CPU   %user   %nice    %sys %iowait    %irq   %soft  %steal   %idle    intr/s
11:38:39 AM  all    0.11    0.01    0.05    0.13    0.00    0.01    0.00   99.68     84.51
%user                            用户所占的CPU时间百分比
%nice                            nice值为负进程的CPU时间百分比
%sys                             系统内核所占cpu时间的百分比
%iowait                          i/o等待所占cpu时间的百分比
%idle                            cpu闲置时间的百分比
intr/s                           每秒cpu的中断次数

7,free -m来查看内存,交换分区使用情况,如果不加-m的话,最小单位是KB

[root@mytest ~]# free -m
              total       used       free     shared    buffers     cached
Mem:          3823       3647        175          0        703       1945
-/+ buffers/cache:        998       2825
Swap:        24003        177      23825
total                                 表时总量是多少
used                                  已经使用了多少
free                                  还有多少空闲
shared                                共享是多少
buffers                               缓冲是多少
cached                                缓存了多少

8,iostat查看磁盘i/o情况

[root@krlcgcms01 ~]# iostat -x 2
Linux 2.6.18-92.1.10.el5 (krlcgcms01)   12/10/2010

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
 0.11    0.01    0.06    0.13    0.00   99.68

Device:           rrqm/s   wrqm/s   r/s   w/s   rsec/s   wsec/s avgrq-sz avgqu-sz   await  svctm  %util
cciss/c0d0        0.21     7.78  0.44  3.00    12.13    86.31    28.63     0.03    7.68   3.39   1.17
rrqm/s:           每秒进行 merge 的读操作数目。即 delta(rmerge)/s
wrqm/s:           每秒进行 merge 的写操作数目。即 delta(wmerge)/s
r/s:              每秒完成的读 I/O 设备次数。即 delta(rio)/s
w/s:              每秒完成的写 I/O 设备次数。即 delta(wio)/s
rsec/s:           每秒读扇区数。即 delta(rsect)/s
wsec/s:           每秒写扇区数。即 delta(wsect)/s
rkB/s:            每秒读K字节数。是 rsect/s 的一半,因为每扇区大小为512字节。(需要计算)
wkB/s:            每秒写K字节数。是 wsect/s 的一半。(需要计算)
avgrq-sz:         平均每次设备I/O操作的数据大小 (扇区)。delta(rsect+wsect)/delta(rio+wio)
avgqu-sz:         平均I/O队列长度。即 delta(aveq)/s/1000 (因为aveq的单位为毫秒)。
await:            平均每次设备I/O操作的等待时间 (毫秒)。即 delta(ruse+wuse)/delta(rio+wio)
svctm:            平均每次设备I/O操作的服务时间 (毫秒)。即 delta(use)/delta(rio+wio)
%util:            一秒中有百分之多少的时间用于 I/O 操作,或者说一秒中有多少时间 I/O 队列是非空的。即 delta(use)/s/1000 (因

为use的单位为毫秒)

9,查看网络的情况

linux本身没带有查看网络连续情况的命令,可以从如下脚本中去查看,每秒网络的传输情况

#!/bin/bash

if [ -n "$1" ]; then
  eth_name=$1
else
  eth_name="eth0"
fi

i=0

send_o=`ifconfig $eth_name | grep bytes | awk '{print $6}' | awk -F : '{print $2}'`
 recv_o=`ifconfig $eth_name | grep bytes | awk '{print $2}' | awk -F : '{print $2}'`
 send_n=$send_o
recv_n=$recv_o

while [ $i -le 100000 ]; do
  send_l=$send_n
  recv_l=$recv_n
  sleep 1
  send_n=`ifconfig $eth_name | grep bytes | awk '{print $6}' | awk -F : '{print $2}'`
   recv_n=`ifconfig $eth_name | grep bytes | awk '{print $2}' | awk -F : '{print $2}'`
   i=`expr $i + 1`
  send_r=`expr $send_n - $send_l`
  recv_r=`expr $recv_n - $recv_l`
  total_r=`expr $send_r + $recv_r`
  send_ra=`expr /( $send_n - $send_o /) / $i`
  recv_ra=`expr /( $recv_n - $recv_o /) / $i`
  total_ra=`expr $send_ra + $recv_ra`
  sendn=`ifconfig $eth_name | grep bytes | awk -F /( '{print $3}' | awk -F /) '{print $1}'`
   recvn=`ifconfig $eth_name | grep bytes | awk -F /( '{print $2}' | awk -F /) '{print $1}'`
   clear
  echo  "Last second  :   Send rate: $send_r Bytes/sec  Recv rate: $recv_r Bytes/sec  Total rate: $total_r Bytes/sec"
   echo  "Average value:   Send rate: $send_ra Bytes/sec  Recv rate: $recv_ra Bytes/sec  Total rate: $total_ra Bytes/sec"
   echo  "Total traffic after startup:    Send traffic: $sendn  Recv traffic: $recvn"
done

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/29371470/viewspace-1063306/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2013-12-06

  • 博文量
    228
  • 访问量
    2684219