w 查看负载
[root@hanlin ~]# w
10:10:29(时间)0 up 10 days, 45 min(开机时间), 3 users, load average: 0.00, 0.01, 0.05
USER TTY FROM LOGIN@ (登入时间) IDLE JCPU PCPU WHAT
root pts/0 192.168.3.99 五10 17:30m 4.44s 3.70s -bash
root pts/1 192.168.3.99 三11 5.00s 0.18s 0.07s w
TTY 是终端登入
pts/n 是远程登入
load average 系统负载 系统活动进程
load average: 0.00(1min), 0.01(5min), 0.05(15min)
[root@hanlin ~]# cat /proc/cpuinfo
processor : 0 (0表示逻辑cpu有一颗,只要小于逻辑cpu的数目就可以了)
vendor_id : GenuineIntel
cpu family : 6
model : 158
vmstat
[root@hanlin ~]# vmstat 1 6
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
1 0 53796 330452 144 1131844 0 0 1 1 1 9 0 0 100 0 0
0 0 53796 330456 144 1131876 0 0 0 0 133 95 0 0 100 0 0
0 0 53796 330456 144 1131876 0 0 0 0 153 106 0 0 100 0 0
0 0 53796 330456 144 1131876 0 0 0 0 143 103 0 0 100 0 0
0 0 53796 330456 144 1131876 0 0 0 0 88 73 0 0 100 0 0
0 0 53796 330456 144 1131876 0 0 0 0 116 87 0 0 100 0 0
r run 有多少个进程正在运行中
b block 与多少个进程正在等待当中
swap 交换分区 当内存不够的时候从硬盘存储中取出来的临时空间
si swapin 有多少kb的数据从swap读取到内存
so swapout 从多少kb的数据从内存写入到swap
bi 数据从磁盘里读出来进入到内存里去,相当于是读取操作
bo 数据从内存写入到磁盘,相当于是写入操作
us 用户的资源的cpu占用备份比,最大100%
sy 系统本身占用的cpu占比
id 空闲的cpu百分比
wa 等待cpu的百分比
top
Tasks: 197 total, 1 running, 196 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.1 us, 0.2 sy, 0.0 ni, 99.7 id, 0.0 wa, 0.0 hi, 0.1 si, 0.0 st(被偷走的cpu百分比,虚拟化类型的)
KiB Mem : 2187824 total, 264448 free, 724256 used, 1199120 buff/cache
KiB Swap: 4194300 total, 4128620 free, 65680 used. 1202624 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
381 root 20 0 36960 5128 4892 S 0.3 0.2 0:29.13 systemd-journal
673 root 20 0 305368 3608 3276 S 0.3 0.2 61:48.02 vmtoolsd
11754 root 20 0 157756 2272 1568 R 0.3 0.1 0:00.21 top
26466 root 20 0 0 0 0 S 0.3 0.0 0:04.84 kworker/3:1
zombie 僵尸进程,主进程被杀掉了,子进程没关,自生自灭状态
RES 进程实际使用的内存单位是KB,除以总内存就是内存的使用率
M 切换使用内存多少的排列,返回到cpu使用率排列摁P
1 显示所有cpu核心的使用率,再摁1返回之前状态
top -c 显示进程具体的命令
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
11992 root 20 0 157784 2376 1652 R 0.3 0.1 0:00.13 top -c
1 root 20 0 128164 4744 2688 S 0.0 0.2 0:56.61 /usr/lib/systemd/sy+
2 root 20 0 0 0 0 S 0.0 0.0 0:02.69 [kthreadd]
3 root 20 0 0 0 0 S 0.0 0.0 1:07.63 [ksoftirqd/0]
top -bn1 一次性显示所有进程,静态显示
sar
[root@hanlin ~]# yum -y install sysstat.x86_64 ( sar命令安装包)
[root@hanlin ~]# sar -n DEV 1 5
Linux 3.10.0-693.el7.x86_64 (hanlin) 2018年06月15日 _x86_64_ (4 CPU)
15时42分27秒 IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s
15时42分28秒 lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
15时42分28秒 virbr0-nic 0.00 0.00 0.00 0.00 0.00 0.00 0.00
15时42分28秒 virbr0 0.00 0.00 0.00 0.00 0.00 0.00 0.00
15时42分28秒 ens33 18.00 1.00 1.22 0.18 0.00 0.00 0.00
[root@hanlin ~]# cd /var/log/sa (储存sar数据的路径,可以直接cat以前的记录数据,最多保存一个月)
[root@hanlin sa]# ls
sa01 sa05 sa08 sa11 sa14 sa24 sa27 sa30 sar05 sar08 sar11 sar14 sar27
sa02 sa06 sa09 sa12 sa15 sa25 sa28 sa31 sar06 sar09 sar12 sar23 sar30
sa04 sa07 sa10 sa13 sa23 sa26 sa29 sar04 sar07 sar10 sar13 sar26 sar31
[root@hanlin sa]# sar -q -f sa 29 (查看系统负载的历史数据,-f指定数据文件)
[root@hanlin sa]# sar -b -f sa29 (查看磁盘负载,可以选定具体日期的数据,美国比中国晚8h)
Linux 3.10.0-693.el7.x86_64 (hanlin) 2018年05月29日 _x86_64_ (4 CPU)
09时42分29秒 LINUX RESTART
09时50分01秒 tps rtps wtps bread/s bwrtn/s
10时00分01秒 0.05 0.00 0.05 0.00 0.58
10时10分01秒 0.10 0.02 0.08 0.33 1.07
10时20分01秒 5.58 4.98 0.60 140.22 28.35
10时30分01秒 0.03 0.00 0.03 0.00 0.46
10时40分01秒 0.05 0.00 0.05 0.00 0.60
10时50分01秒 0.04 0.00 0.04 0.00 0.59
要判断系统瓶颈问题,有时需几个 sar 命令选项结合起来
怀疑CPU存在瓶颈,可用 sar -u 和 sar -q 等来查看
怀疑内存存在瓶颈,可用 sar -B、sar -r 和 sar -W 等来查看
怀疑I/O存在瓶颈,可用 sar -b、sar -u 和 sar -d 等来查看
nload
[root@hanlin /]# yum install -y nload.x86_64 (nload安装包)
如下截图
incoming 表示进来的带宽
outgoing 表示出去的带宽,通常说的带宽就是指出去的带宽,也指上传速度