1. 程式人生 > >監控io性能,free,ps命令,查看網絡狀態以及抓包

監控io性能,free,ps命令,查看網絡狀態以及抓包

linux下抓包 lee 4.5 method cto ddr 數字 多線程 vpd

監控io性能

技術分享圖片
1.iostat命令:

[root@weix01 ~]# iostat
Linux 3.10.0-693.el7.x86_64 (weix01)    2018年01月23日     _x86_64_    (1 CPU)

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           0.49    0.00    1.15    1.28    0.00   97.09

Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
sda              12.86       179.87        10.70      98142       5839
sdb               0.16         3.81         0.00       2080          0
scd0              0.03         1.88         0.00       1028          0

2.磁盤使用:

[root@weix01 ~]# iostat -x 1        #  %util這一列表示占比
Linux 3.10.0-693.el7.x86_64 (weix01)    2018年01月23日     _x86_64_    (1 CPU)

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           0.35    0.00    0.84    0.88    0.00   97.93

Device:         rrqm/s   wrqm/s     r/s     w/s    rkB/s    wkB/s avgrq-sz avgqu-sz   await r_await w_await  svctm  %util
sda               0.00     0.03    6.09    2.86   124.27     8.16    29.62     0.11   11.85    4.98   26.50   5.13   4.59
sdb               0.00     0.00    0.11    0.00     2.63     0.00    47.27     0.00    0.50    0.50    0.00   0.50   0.01
scd0              0.00     0.00    0.02    0.00     1.30     0.00   114.22     0.00   10.06   10.06    0.00   8.83   0.02

3.安裝 iotop命令:

[root@weix01 ~]# yum install -y iotop
已加載插件:fastestmirror
base                                                                                | 3.6 kB  00:
epel/x86_64/metalink                                                                | 6.8 kB  00:
extras                                                                              | 3.4 kB  00:
updates                                                                             | 3.4 kB  00:
updates/7/x86_64/primary_db                                                         | 5.3 MB  00:
Loading mirror speeds from cached hostfile
 * epel: mirrors.sohu.com
正在解決依賴關系
--> 正在檢查事務
---> 軟件包 iotop.noarch.0.0.6-2.el7 將被 安裝
--> 解決依賴關系完成

4.使用iotop命令查看磁盤使用:

Total DISK READ :   0.00 B/s | Total DISK WRITE :       0.00 B/s
Actual DISK READ:   0.00 B/s | Actual DISK WRITE:       0.00 B/s
   TID  PRIO  USER     DISK READ  DISK WRITE  SWAPIN     IO>    COMMAND                         
   226 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.01 % [kworker/0:3]
     1 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % systemd --switche~ --deserialize 21
     2 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [kthreadd]
     3 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [ksoftirqd/0]
     5 be/0 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [kworker/0:0H]

free命令

1.free命令:

[root@weix01 ~]# free
              total        used        free      shared  buff/cache   available    #說明
Mem:         999700      129968      602740        6844      266992      689212      #內存使用情況
Swap:       2097148           0     2097148     #交換分區使用情況
[root@weix01 ~]# free -h               #單位更加適合查看
              total        used        free      shared  buff/cache   available
Mem:           976M        126M        588M        6.7M        260M        673M
Swap:          2.0G          0B        2.0G

2.各個參數意義:

total     總共多少
used    使用多少
free      空余多少
buff/cache   預分配多少
 磁盤-->內存(cache)-->cpu^C
cpu-->內存(buffer)-->磁盤^C

3.total=used+free+buff/cache
4.available=free+buff/cache剩余部分

ps命令

技術分享圖片
1.常用用法:

[root@weix01 ~]# ps aux             查看當前狀態
USER        PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root          1  0.0  0.6 128164  6828 ?        Ss   21:00   0:01 /usr/lib/systemd/systemd --swi
root          2  0.0  0.0      0     0 ?        S    21:00   0:00 [kthreadd]
root          3  0.0  0.0      0     0 ?        S    21:00   0:00 [ksoftirqd/0]
root          5  0.0  0.0      0     0 ?        S<   21:00   0:00 [kworker/0:0H]
root          6  0.0  0.0      0     0 ?        S    21:00   0:00 [kworker/u256:0]
root          7  0.0  0.0      0     0 ?        S    21:00   0:00 [migration/0]
root          8  0.0  0.0      0     0 ?        S    21:00   0:00 [rcu_bh]
root          9  0.0  0.0      0     0 ?        R    21:00   0:00 [rcu_sched]
[root@weix01 ~]# ps aux |grep nginx      #配合管道符查看是否在運行
root       1648  0.0  0.0 112676   984 pts/0    R+   21:42   0:00 grep --color=auto nginx

2.查看進程在哪啟動的:

[root@weix01 ~]# ls -l /proc/501                  #501為命令PID
總用量 0
dr-xr-xr-x. 2 root root 0 1月  23 21:00 attr
-rw-r--r--. 1 root root 0 1月  23 21:46 autogroup
-r--------. 1 root root 0 1月  23 21:46 auxv
-r--r--r--. 1 root root 0 1月  23 21:00 cgroup
--w-------. 1 root root 0 1月  23 21:46 clear_refs
-r--r--r--. 1 root root 0 1月  23 21:00 cmdline
-rw-r--r--. 1 root root 0 1月  23 21:00 comm
-rw-r--r--. 1 root root 0 1月  23 21:46 coredump_filter
-r--r--r--. 1 root root 0 1月  23 21:46 cpuset
lrwxrwxrwx. 1 root root 0 1月  23 21:46 cwd -> /
-r--------. 1 root root 0 1月  23 21:46 environ
lrwxrwxrwx. 1 root root 0 1月  23 21:00 exe -> /usr/sbin/auditd

3.STAT狀態說明:

D  不能中斷的進程
R  run狀態的進程
S  sleep狀態進程
T  暫停的進程
Z  僵屍進程
<  高優先級進程
N  低優先級進程
L  內存中被鎖了內存分頁
s  主進程
l  多線程進程
+  前臺進程

查看網絡狀態

技術分享圖片
1.查看網絡監聽狀態:

[root@weix01 ~]# netstat -lnp
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      888/sshd            
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      993/master          
tcp6       0      0 :::22                   :::*                    LISTEN      888/sshd            
tcp6       0      0 ::1:25                  :::*                    LISTEN      993/master          
udp        0      0 0.0.0.0:68              0.0.0.0:*                           1562/dhclient       

2.查看所有狀態:

[root@weix01 ~]# netstat -an
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN     
tcp        0     52 192.168.188.130:22      192.168.188.1:51350     ESTABLISHED
tcp6       0      0 :::22                   :::*                    LISTEN     
tcp6       0      0 ::1:25                  :::*                    LISTEN     
udp        0      0 0.0.0.0:68              0.0.0.0:*                          
udp        0      0 0.0.0.0:13109           0.0.0.0:*                          
udp        0      0 127.0.0.1:323           0.0.0.0:*                          
udp6       0      0 :::5903                 :::*                               
udp6       0      0 ::1:323                 :::*                               
raw6       0      0 :::58                   :::*       

3.只看 tcp或者udp:

[root@weix01 ~]# netstat -lntp                      #加上t
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      888/sshd            
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      993/master          
tcp6       0      0 :::22                   :::*                    LISTEN      888/sshd            
tcp6       0      0 ::1:25                  :::*                    LISTEN      993/master          

4.統計端口狀態數量:需要記下該命令

[root@weix01 ~]# netstat -an|awk ‘/^tcp/ {++sta[$NF]} END {for(key in sta) print key,"\t",sta[key]}‘
LISTEN   4
ESTABLISHED      1

需要關註established數量,表示並發數,通常1000以內。

5.ss -an與netstat異曲同工,但是不會顯示進程名字

[root@weix01 ~]# ss -an
Netid  State      Recv-Q Send-Q Local Address:Port               Peer Address:Port              
nl     UNCONN     0      0                 0:-440401336                     *                   
nl     UNCONN     0      0                 0:0                              *                   
nl     UNCONN     0      0                 0:-440401336                     *                   
nl     UNCONN     768    0                 4:0                              *                   
nl     UNCONN     4352   0                 4:4114                           *                   
nl     UNCONN     0      0                 6:0                              *                   
nl     UNCONN     0      0                 7:1                              *                   
nl     UNCONN     0      0                 7:0                              *        

linux下抓包

技術分享圖片
1.安裝tcpdump包:

[root@weix01 ~]# yum install -y tcpdump
已加載插件:fastestmirror
Loading mirror speeds from cached hostfile
 * epel: mirrors.tongji.edu.cn
正在解決依賴關系
--> 正在檢查事務
---> 軟件包 tcpdump.x86_64.14.4.9.0-5.el7 將被 安裝
--> 正在處理依賴關系 libpcap.so.1()(64bit),它被軟件包 14:tcpdump-4.9.0-5.el7.x86_64 需要
--> 正在檢查事務
---> 軟件包 libpcap.x86_64.14.1.5.3-9.el7 將被 安裝
--> 解決依賴關系完成

2.tcpdunp命令:

[root@weix01 ~]# tcpdump -nn -i ens33   #兩個nn 主機顯示ip以及端口號,以數字方式顯示
22:20:31.341911 IP 192.168.188.130.22 > 192.168.188.1.51350: Flags [P.], seq 17045588:17045816, ack 2653, win 292, options [nop,nop,TS val 4518487 ecr 1303955918], length 228
22:20:31.341984 IP 192.168.188.130.22 > 192.168.188.1.51350: Flags [P.], seq 17045816:17046204, ack 2653, win 292, options [nop,nop,TS val 4518487 ecr 1303955918], length 388
22:20:31.342064 IP 192.168.188.130.22 > 192.168.188.1.51350: Flags [P.], seq 17046204:17046432, ack 2653, win 292, options [nop,nop,TS val 4518487 ecr 1303955918], length 228
22:20:31.342147 IP 192.168.188.130.22 > 192.168.188.1.51350: Flags [P.], seq 17046432:17046660, ack 2653, win 292, options [nop,nop,TS val 4518487 ecr 1303955918], length 228
22:20:31.342227 IP 192.168.188.130.22 > 192.168.188.1.51350: Flags [P.], seq 17046660:17046888, ack 2653, win 292, options [nop,nop,TS val 4518487 ecr 1303955918], length 228
22:20:31.342394 IP 192.168.188.1.51350 > 192.168.188.130.22: Flags [.], ack 17046660, win 2047, options [nop,nop,TS val 1303955919 ecr 4518487], length 0
22:20:31.342421 IP 192.168.188.130.22 > 192.168.188.1.51350: Flags [P.], seq 17046888:17047116, ack 2653, win 292, options [nop,nop,TS val 4518487 ecr 1303955919], length 228

3.可以指定端口:

[root@weix01 ~]# tcpdump -nn -i ens33 port 22

4.指定主機

[root@weix01 ~]# tcpdump -nn -i ens33 port 22 and host 192.168.188.1

5.將抓到的包寫入一個文件:

[root@weix01 ~]# tcpdump -nn -i ens33 -c 100 -w /tmp/1.cap
tcpdump: listening on ens33, link-type EN10MB (Ethernet), capture size 262144 bytes

6.查看抓到的包: -r

[root@weix01 ~]# file /tmp/1.cap
/tmp/1.cap: tcpdump capture file (little-endian) - version 2.4 (Ethernet, capture length 262144)
[root@weix01 ~]# tcpdump -r /tmp/1.cap 
reading from file /tmp/1.cap, link-type EN10MB (Ethernet)
22:30:24.498994 IP weix01.ssh > 192.168.188.1.51350: Flags [P.], seq 866074493:866074641, ack 2979720174, win 292, options [nop,nop,TS val 5111643 ecr 1304549072], length 148
22:30:24.499166 IP 192.168.188.1.51350 > weix01.ssh: Flags [.], ack 148, win 2080, options [nop,nop,TS val 1304549080 ecr 5111636], length 0
22:30:25.171411 ARP, Request who-has gateway tell 192.168.188.1, length 46
22:30:26.226708 ARP, Request who-has gateway tell 192.168.188.1, length 46
22:30:27.171785 ARP, Request who-has gateway tell 192.168.188.1, length 46
22:30:28.171693 ARP, Request who-has gateway tell 192.168.188.1, length 46

7.安裝wireshark包:

[root@weix01 ~]# yum install -y wireshark
已加載插件:fastestmirror
Loading mirror speeds from cached hostfile
 * epel: mirrors.ustc.edu.cn
正在解決依賴關系
--> 正在檢查事務
---> 軟件包 wireshark.x86_64.0.1.10.14-14.el7 將被 安裝
--> 正在處理依賴關系 libgnutls.so.28(GNUTLS_1_4)(64bit),它被軟件包 wireshark-1.10.14-14.el7.x86_64 需要

8.tshark命令:

[root@weix01 ~]# tshark -n -t a -R http.request -T fields -e "frame.time" -e "ip.src"-e "http.host" -e "http.request.method" -e "http.request.uri"

監控io性能,free,ps命令,查看網絡狀態以及抓包