7.12 10.6-10.10

10.6 监控io性能

iostat

sar同属一个包

[root@hyc-01-01 ~]# iostat 显示信息类似sar –b

Linux 3.10.0-693.el7.x86_64 (hyc-01-01)    20180711      _x86_64_   (1 CPU)

avg-cpu:  %user   %nice %system %iowait  %steal   %idle

           0.06    0.00    0.15    0.00    0.00   99.79

Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn

sda               0.18         2.95         1.89     227609     146156

[root@hyc-01-01 ~]# iostat 1 每秒显示一次

[root@hyc-01-01 ~]# iostat -x

Linux 3.10.0-693.el7.x86_64 (hyc-01-01)    20180711      _x86_64_         (1 CPU)

avg-cpu:  %user   %nice %system %iowait  %steal   %idle

           0.06    0.00    0.15    0.00    0.00   99.79

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.01    0.11    0.08     2.91     1.87    52.67     0.00    1.60    0.99    2.44   0.60   0.01

%util:单位时间内cpu等待io所用时间占比,该值过大说明磁盘io较差

rkB/swkB/s较小但%util仍较大则说明磁盘可能存在故障;

 

iotop命令

[root@hyc-01-01 ~]# yum install -y iotop 安装iotop命令

[root@hyc-01-01 ~]# 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  

    1 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % systemd --s~serialize 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]

7 rt/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [migration/0]

IO> 单位时间内进程占用IO的百分比

 

10.7 free命令

 

用于查看内存使用情况

[root@hyc-01-01 ~]# free

              total        used        free      shared  buff/cache   available

Mem:        1008152      132904      507340        6888      367908      691460

Swap:       2097148           0     2097148

mem 内存 swap 交换分区

默认单位为KB

[root@hyc-01-01 ~]# free –m 将信息以MB为单位显示

              total        used        free      shared  buff/cache   available

Mem:            984         129         495           6         359         675

Swap:          2047           0        2047

[root@hyc-01-01 ~]# free –h 在具体数字后加上单位

              total        used        free      shared  buff/cache   available

Mem:           984M        129M        495M        6.7M        359M        675M

Swap:          2.0G          0B        2.0G

buffercache

Linux操作系统会将内存预分配一部分给buffercache

cache:磁盘里的数据要到cpu去处理,数据会先被从磁盘读入内存的cache中,再从cachecpu

buffercpu中处理完的数据写入磁盘时会先被放到内存的buffer中,再从buffer写入磁盘

available=free+未被使用的buffer/cache

total=used+free+buffer/cache

查看剩余内存时通常关注available

swap:

swapused过多可能因为内存不充足导致内存与交换分区发生数据交换

也有可能是内存泄露导致内存被占满导致需要使用swap分区将暂时不用的数据交换出内存

 

10.8 ps命令

 

ps 查看系统进程

[root@hyc-01-01 ~]# ps

  PID TTY          TIME CMD

 5249 pts/0    00:00:00 bash

 5268 pts/0    00:00:00 ps

[root@hyc-01-01 ~]# ps aux

USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND

root         1  0.0  0.6 128208  6856 ?        Ss   711   0:03 /usr/lib/systemd/s

root         2  0.0  0.0      0     0 ?        S    711   0:00 [kthreadd]

root         3  0.0  0.0      0     0 ?        S    711   0:00 [ksoftirqd/0]

root         5  0.0  0.0      0     0 ?        S<   711   0:00 [kworker/0:0H]

root         7  0.0  0.0      0     0 ?        S    711   0:00 [migration/0]

[root@hyc-01-01 ~]# ps -elf

F S UID        PID  PPID  C PRI  NI ADDR SZ WCHAN  STIME TTY          TIME CMD

4 S root         1     0  0  80   0 - 32052 ep_pol 711 ?       00:00:03 /usr/lib/

1 S root         2     0  0  80   0 -     0 kthrea 711 ?       00:00:00 [kthreadd

1 S root         3     2  0  80   0 -     0 smpboo 711 ?       00:00:00 [ksoftirq

1 S root         5     2  0  60 -20 -     0 worker 711 ?       00:00:00 [kworker/

1 S root         7     2  0 -40   - -     0 smpboo 711 ?       00:00:00 [migratio

1 S root         8     2  0  80   0 -     0 rcu_gp 711 ?       00:00:00 [rcu_bh]

1 R root         9     2  0  80   0 -     0 -      711 ?       00:00:01 [rcu_sche

5 S root        10     2  0 -40   - -     0 smpboo 711 ?       00:00:01 [watchdog

5 S root        12     2  0  80   0 -     0 devtmp 711 ?       00:00:00 [kdevtmpf

blob.png

 

10.9 查看网络状态

 

[root@hyc-01-01 ~]# netstat

Active Internet connections (w/o servers)

Proto Recv-Q Send-Q Local Address           Foreign Address         State     

[root@hyc-01-01 ~]# 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      854/sshd           

tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      957/master         

tcp6       0      0 :::22                   :::*                    LISTEN      854/sshd    

 

 

 

 

 

tcp        0     52 hyc-01-01:ssh           192.168.31.1:49749      ESTABLISHED

Active UNIX domain sockets (w/o servers)

Proto RefCnt Flags       Type       State         I-Node   Path

unix  2      [ ]         DGRAM                    11850    /run/systemd/shutdownd

unix  2      [ ]         DGRAM                    14727    /var/run/chrony/chronyd.sock

[root@hyc-01-01 ~]# 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.31.129:22       192.168.31.1:49749      ESTABLISHED

tcp6       0      0 :::22                   :::*                    LISTEN    

tcp6       0      0 ::1:25                  :::*                    LISTEN    

udp        0      0 127.0.0.1:323           0.0.0.0:*                         

udp6       0      0 ::1:323                 :::*                              

raw6       0      0 :::58                   :::*                    7         

Active UNIX domain sockets (servers and established)

Proto RefCnt Flags       Type       State         I-Node   Path

unix  2      [ ACC ]     STREAM     LISTENING     17933    public/qmgr

unix  2      [ ACC ]     STREAM     LISTENING     17970    public/showq

unix  2      [ ACC ]     STREAM     LISTENING     17955    public/flush

[root@hyc-01-01 ~]# netstat -an|awk '/^tcp/{++sta[$NF]}END{for(key in sta)print key,"\t",sta[key]}'

LISTEN     4

ESTABLISHED         

 

10.10 linux下抓包

 

[root@hyc-01-01 ~]# yum install -y tcpdump 安装tcpdump相关的包

[root@hyc-01-01 ~]# tcpdump -nn -i ens33

[root@hyc-01-01 ~]# tcpdump -nn -c 100 -w 1.cap

tcpdump: listening on nflog, link-type NFLOG (Linux netfilter log messages), capture size 262144 bytes


猜你喜欢

转载自blog.51cto.com/12216458/2140682