一、w和uptime

[root@VBTestA ~]# w
 20:29:01 up 28 min,  1 user,  load average: 0.00, 0.00, 0.00
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
mylinux  pts/0    192.168.1.105    20:12    0.00s  0.32s  0.26s sshd: mylinux [

    load average 平均负载,1分钟的,5分钟的,15分钟的

    ab  apache的压力测试工具 可以进行单独安装,执行 yum install httpd-tools -y 即可

[root@VBTestA ~]#  ab -n 1000 -c 100 'http://www.ypl.cc/forum.php'

    uptime

[root@VBTestA ~]# uptime
 20:50:22 up 49 min,  1 user,  load average: 0.00, 0.00, 0.00


二、top

   

    示例 :每3秒刷新一次,系统状态

top - 21:05:18 up  1:04,  1 user,  load average: 0.00, 0.00, 0.00
Tasks:  71 total,   1 running,  70 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.0%us,  0.3%sy,  0.0%ni, 99.7%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:   1030548k total,   201192k used,   829356k free,    10868k buffers
Swap:  2097148k total,        0k used,  2097148k free,   130048k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
    1 root      20   0  2900 1412 1204 S  0.0  0.1   0:01.27 init
    2 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kthreadd
    3 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 migration/0
    4 root      20   0     0    0    0 S  0.0  0.0   0:00.01 ksoftirqd/0
    5 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 stopper/0
    6 root      RT   0     0    0    0 S  0.0  0.0   0:00.04 watchdog/0
    7 root      20   0     0    0    0 S  0.0  0.0   0:00.72 events/0
    8 root      20   0     0    0    0 S  0.0  0.0   0:00.00 cgroup
    9 root      20   0     0    0    0 S  0.0  0.0   0:00.00 khelper
   10 root      20   0     0    0    0 S  0.0  0.0   0:00.00 netns
   ............................以下省略..............................

     top -bn1 一次性打印出


三、vmstat :侦测系统资源变化

    示例 :系统状态每2秒打一次,共打印3次

[root@test ~]# vmstat 2 3     
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      0 807880  16732 139676    0    0     5     3   71   25  1  1 98  0  0
 0  0      0 807872  16732 139676    0    0     0     0   14    8  0  0 100  0  0
 0  0      0 807872  16732 139676    0    0     0     0   10    7  0  0 100  0  0


四、ps 查看系统进程

[root@test ~]# ps aux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.1   3792  1412 ?        Ss   09:17   0:02 /sbin/init
root         2  0.0  0.0      0     0 ?        S    09:17   0:00 [kthreadd]
root         3  0.0  0.0      0     0 ?        S    09:17   0:00 [migration/0]
root         4  0.0  0.0      0     0 ?        S    09:17   0:00 [ksoftirqd/0]
root         5  0.0  0.0      0     0 ?        S    09:17   0:00 [stopper/0]
............................下面省略.........................

    pstree 进程树

[root@test ~]# pstree
init─┬─auditd───{auditd}
     ├─console-kit-dae───63*[{console-kit-da}]
     ├─crond
     ├─dbus-daemon───{dbus-daemon}
     ├─dhclient
     ├─login───bash
     ├─master─┬─pickup
     │        └─qmgr
     ├─5*[mingetty]
     ├─rsyslogd───3*[{rsyslogd}]
     ├─sshd─┬─sshd───bash───pstree
     │      └─2*[sshd───bash]
     └─udevd───2*[udevd]



五、free :观察内存使用情况

[root@test ~]# free -m
             total       used       free     shared    buffers     cached
Mem:          1006        216        789          0         15        136
-/+ buffers/cache:         64        941
Swap:         2047          0       2047

     选项与参数:
     -b  :直接输入 free 时,显示的单位是 Kbytes,我们可以使用 b(bytes), m(Mbytes)
           k(Kbytes), 及 g(Gbytes) 来显示单位喔!
     -t  :在输出的最终结果,显示实体内存与 swap 的总量。


六、netstat

    选项与参数:
    与路由 (route) 有关的参数说明:
    -r  :列出路由表(route table),功能如同 route 这个指令;
    -n  :不使用主机名与服务名称,使用 IP 与 port number ,如同 route -n
    与网络接口有关的参数:
    -a  :列出所有的联机状态,包括 tcp/udp/unix socket 等;
    -t  :仅列出 TCP 封包的联机;
    -u  :仅列出 UDP 封包的联机;
    -l  :仅列出有在 Listen (监听) 的服务之网络状态;
    -p  :列出 PID 与 Program 的檔名;
    -c  :可以设定几秒钟后自动更新一次,例如 -c 5 每五秒更新一次网络状态的显示;

    示例 :

    1、列出目前的路由表状态,且以 IP 及 port number 显示:

[root@test ~]# netstat -rn
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
192.168.0.0     0.0.0.0         255.255.255.0   U         0 0          0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U         0 0          0 eth0
0.0.0.0         192.168.0.1     0.0.0.0         UG        0 0          0 eth0

    2、列出所有监听状态的IP及端口

[root@test ~]# netstat -alnp
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      813/sshd       
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      890/master     
tcp        0      0 192.168.0.120:22            192.168.0.116:49782         ESTABLISHED 1406/sshd      
tcp        0      0 192.168.0.120:22            192.168.0.116:51059         ESTABLISHED 1636/sshd      
tcp        0      0 192.168.0.120:22            192.168.0.116:50577         ESTABLISHED 1540/sshd      
tcp        0      0 :::22                       :::*                        LISTEN      813/sshd       
tcp        0      0 ::1:25                      :::*                        LISTEN      890/master     
udp        0      0 0.0.0.0:68                  0.0.0.0:*                               1064/dhclient  
Active UNIX domain sockets (servers and established)
Proto RefCnt Flags       Type       State         I-Node PID/Program name    Path
unix  2      [ ACC ]     STREAM     LISTENING     10484  890/master          public/cleanup
unix  2      [ ACC ]     STREAM     LISTENING     10171  775/dbus-daemon     /var/run/dbus/system_bus_socket
unix  10     [ ]         DGRAM                    10071  728/rsyslogd        /dev/log
unix  2      [ ACC ]     STREAM     LISTENING     8309   1/init              @/com/ubuntu/upstart
...........................下面省略............................

    3、列出目前已经启动的网络服务

[root@test ~]# netstat -tulnp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      813/sshd       
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      890/master     
tcp        0      0 :::22                       :::*                        LISTEN      813/sshd       
tcp        0      0 ::1:25                      :::*                        LISTEN      890/master     
udp        0      0 0.0.0.0:68                  0.0.0.0:*                               1064/dhclient


七、sar

    网络性能监控,网卡的吞吐量是否过载以及网络是否稳定,是否出现丢包情况

    对于没有安装sar工具的,需要安装sysstat这个包。

[root@test ~]# sar -n DEV 3 2      # 每3秒扫描一次网络设备,共打印2次
Linux 2.6.32-504.el6.i686 (test)        2015年04月16日  _i686_  (1 CPU)

09时55分36秒     IFACE   rxpck/s   txpck/s    rxkB/s    txkB/s   rxcmp/s   txcmp/s  rxmcst/s
09时55分39秒        lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00
09时55分39秒      eth0    203.08    217.12    100.94     15.03      0.00      0.00      0.00

09时55分39秒     IFACE   rxpck/s   txpck/s    rxkB/s    txkB/s   rxcmp/s   txcmp/s  rxmcst/s
09时55分42秒        lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00
09时55分42秒      eth0    216.49    214.78    108.86     15.00      0.00      0.00      0.00

平均时间:     IFACE   rxpck/s   txpck/s    rxkB/s    txkB/s   rxcmp/s   txcmp/s  rxmcst/s
平均时间:        lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00
平均时间:      eth0    209.78    215.95    104.89     15.01      0.00      0.00      0.00

    IFACE :网络接口的名字

    rxpck/s :每秒接收的数据包

    txpck/s :每秒发送的数据包

    rxkB/s :每秒接收的字节数

    txkB/s :每秒发送的字节数

    rxcmp/s :每秒接收的压缩数据包

    txcmp/s :每秒发送的压缩数据包

    rxmcst/s :每秒接收的多播数据包