|
维护服务器的时候,要经常查看系统资源的,可以了解一下服务器的运行情况。系统优化时,比如使用memcache时,我要决定分配多少内存给他合适呢,mysql的innodb的参数优化也要考虑到内存使用率,i/o的频繁程度啊,如果使用apache的话,要启动多少个httpd比较合适呢,如果数据库的数据太大,我要看看是不是增加磁盘呢等等,这个时候,我们要知道,有多少资源可用,才能更好的优化我们的系统。
1.top命令查看cpu,mem的使用情况
1
2
3
4
5
6
7
8
9
10
11
| top - 13:54:34 up 4:29, 1 user, load average: 0.00, 0.00, 0.00
Tasks: 78 total, 1 running, 77 sleeping, 0 stopped, 0 zombie
Cpu(s): 0.0%us, 0.3%sy, 0.0%ni, 99.3%id, 0.0%wa, 0.0%hi, 0.3%si, 0.0%st
Mem: 1012548k total, 555232k used, 457316k free, 38052k buffers
Swap: 2047992k total, 0k used, 2047992k free, 378176k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
7 root 20 0 0 0 0 S 0.3 0.0 0:14.05 events/0
1 root 20 0 19360 1536 1220 S 0.0 0.2 0:01.04 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
|
top 后 在shift + p 所占进程的排序显示
top 后 在shift + m 所占内存的排序显示
2.vmstat命令查看
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
| [iyunv@master ~]# vmstat 2 #每隔2s钟显示一次
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 457324 38076 378176 0 0 19 21 19 30 0 0 99 0 0
0 0 0 457316 38076 378176 0 0 0 0 22 17 0 0 100 0 0
0 0 0 457316 38076 378176 0 0 0 0 18 15 0 1 100 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工作时间的百分比
|
3.mpstat命令查看
1
2
3
4
5
6
7
8
9
10
11
12
13
| [iyunv@master ~]# mpstat 1 #1s钟显示一次结果
Linux 2.6.32-358.el6.x86_64 (master) 07/08/2015 _x86_64_ (1 CPU)
02:00:35 PM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %idle
02:00:36 PM all 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00
02:00:37 PM all 0.00 0.00 1.00 0.00 0.00 0.00 0.00 0.00 99.00
02:00:38 PM all 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00
%user 用户所占的CPU时间百分比
%nice nice值为负进程的CPU时间百分比
%sys 系统内核所占cpu时间的百分比
%iowait i/o等待所占cpu时间的百分比
%idle cpu闲置时间的百分比
intr/s 每秒cpu的中断次数
|
4.iostat查看磁盘I/O情况
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
| [iyunv@master ~]# iostat -x 2
Linux 2.6.32-358.el6.x86_64 (master) 07/08/2015 _x86_64_ (1 CPU)
avg-cpu: %user %nice %system %iowait %steal %idle
0.08 0.03 0.27 0.27 0.00 99.36
Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s avgrq-sz avgqu-sz await svctm %util
sda 0.25 4.43 0.72 0.63 37.16 40.54 57.60 0.01 8.79 2.78 0.37
avg-cpu: %user %nice %system %iowait %steal %idle
0.00 0.00 0.50 1.51 0.00 97.99
Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s avgrq-sz avgqu-sz await svctm %util
sda 0.00 0.00 0.50 0.00 8.04 0.00 16.00 0.02 37.00 37.00 1.86
avg-cpu: %user %nice %system %iowait %steal %idle
0.00 0.00 0.50 0.00 0.00 99.50
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的单位为毫秒)
|
5.dstat命令查看
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
| root@master ~]# dstat
----total-cpu-usage---- -dsk/total- -net/total- ---paging-- ---system--
usr sys idl wai hiq siq| read writ| recv send| in out | int csw
0 0 99 0 0 0| 18k 20k| 0 0 | 0 0 | 19 30
0 1 99 0 0 0| 0 0 | 349B 952B| 0 0 | 24 22
0 0 100 0 0 0| 0 0 | 244B 526B| 0 0 | 20 19
0 0 100 0 0 0| 0 0 | 214B 472B| 0 0 | 24 22
0 0 100 0 0 0| 0 0 | 214B 472B| 0 0 | 21 17
0 0 100 0 0 0| 0 0 | 214B 472B| 0 0 | 27 26
0 0 99 0 0 1| 0 32k| 214B 472B| 0 0 | 27 26
0 1 99 0 0 0| 0 0 | 214B 472B| 0 0 | 25 19
1 0 99 0 0 0| 0 0 | 214B 472B| 0 0 | 18 17
0 0 100 0 0 0| 0 0 | 214B 472B| 0 0 | 21 20
0 0 100 0 0 0| 0 0 | 214B 472B| 0 0 | 21 21
0 0 100 0 0 0| 0 0 | 214B 472B| 0 0 | 22 21
0 0 100 0 0 0| 0 0 | 214B 472B| 0 0 | 19 17
0 1 99 0 0 0| 0 0 | 214B 472B| 0 0 | 24 19
0 0 100 0 0 0| 0 0 | 214B 472B| 0 0 | 19 17
0 0 100 0 0 0| 0 0 | 214B 472B| 0 0 | 29 28
常用参数:
-c, --cpu 显示CPU情况
-C 0,3,total 统计指定CPU或汇总信息
-d, --disk 显示磁盘情况
-D total,hda 统计指定磁盘或汇总信息
-g, --page enable page stats
-i, --int 显示中断统计
-I 5,eth2 统计系统负载情况,包括1分钟、5分钟、15分钟平均值
-l, --load enable load stats
-m, --mem 显示内存情况
-n, --net 显示网络情况
-N eth1,total 可以指定网络接口
-p, --proc 统计进程信息,包括runnable、uninterruptible、new
-r, --io 统计I/O请求,包括读写请求
-s, --swap 显示swap情况
-S swap1,total 可以指定多个swap
-t, --time 显示统计时时间,对分析历史数据非常有用
-y, --sys 统计系统信息,包括中断、上下文切换
--ipc 报告IPC消息队列和信号量的使用情况
--lock 统计lock信息
--raw 统计raw信息
--tcp 统计tcp信息
--udp 统计udp信息
--unix 统计unix信息
-M stat1,stat2 统计external信息
--mods stat1,stat2
-a, --all 使用-cdngy 缺省的就是这样显示
-f, --full 使用 -C, -D, -I, -N and -S 显示
-v, --vmstat 使用-pmgdsc -D 显示
--integer show integer values
--nocolor 不使用颜色功能
--noheaders 只显示一次表头以后就不显示了,使用重定向写入文件时很有用
--noupdate disable intermediate updates
--output file 写入到CVS文件中
|
|
|