码迷,mamicode.com
首页 > 其他好文 > 详细

2018-1-23 7周2次课

时间:2018-01-24 11:02:24      阅读:219      评论:0      收藏:0      [点我收藏+]

标签:tle   and   art   cached   auditd   res   tps   使用情况   internet   

监控io性能

监控io性能,free,ps命令,查看网络状态以及抓包
1.iostat命令:

[root@weix01 ~]# iostat
Linux 3.10.0-693.el7.x86_64 (weix01) 2018年01月23日 _x8664 (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日 _x8664 (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命令

监控io性能,free,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 多线程进程

  • 前台进程

查看网络状态

监控io性能,free,ps命令,查看网络状态以及抓包
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下抓包

监控io性能,free,ps命令,查看网络状态以及抓包
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.m

2018-1-23 7周2次课

标签:tle   and   art   cached   auditd   res   tps   使用情况   internet   

原文地址:http://blog.51cto.com/8043410/2064442

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!