使用w查看系統(tǒng)負(fù)載
監(jiān)控系統(tǒng)狀態(tài)
w查看系統(tǒng)負(fù)載,如果w不行就用w|cat
data可以查看當(dāng)前時(shí)間
(w查看系統(tǒng)負(fù)載,如果w不行就用w|cat)
[root@localhost ~]# w|cat
(顯示當(dāng)前時(shí)間和系統(tǒng)啟動(dòng)了多長(zhǎng)時(shí)間,load average表示系統(tǒng)負(fù)載,三個(gè)數(shù)字分別表示一分鐘
五分鐘和十五分鐘時(shí)間段內(nèi)的系統(tǒng)負(fù)載數(shù)值)
18:09:46 up 1 day, 8:44, 2 users, load average: 0.02, 0.02, 0.05(這三個(gè)最主要)
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
(下面是連接的用戶,物理鏈接是tty1,通過(guò)網(wǎng)絡(luò)鏈接是pts/數(shù)字)
root tty1 231月18 2days 0.05s 0.05s -bash(使用CPU的時(shí)間和命令)
root pts/0 172.16.79.1 18:08 2.00s 0.05s 0.00s w
(data可以查看當(dāng)前時(shí)間)
[root@localhost ~]# date
2018年 03月 02日 星期五 18:10:55 CST
[root@localhost ~]# uptime
18:55:48 up 1 day, 9:29, 2 users, load average: 0.00, 0.01, 0.05
查看系統(tǒng)邏輯CPU來(lái)確定我們的系統(tǒng)負(fù)載是否合適
processor為0的時(shí)候?yàn)?顆邏輯CPU,依次增加
比如邏輯CPU為4顆的時(shí)候,則負(fù)載不超過(guò)4就正常,維持在4就最好,以此類推
[root@localhost ~]# cat /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 61
model name : Intel(R) Core(TM) i5-5257U CPU @ 2.70GHz
stepping : 4
microcode : 0x21
cpu MHz : 2699.259
cache size : 3072 KB
physical id : 0
siblings : 1
core id : 0
cpu cores : 1
apicid : 0
initial apicid : 0
fpu : yes
fpu_exception : yes
cpuid level : 20
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon nopl xtopology tsc_reliable nonstop_tsc eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid rdseed adx smap xsaveopt arat
bogomips : 5399.78
clflush size : 64
cache_alignment : 64
address sizes : 43 bits physical, 48 bits virtual
power management:
vmstat命令
r 表示有多少進(jìn)程在運(yùn)行
[root@localhost ~]# vmstat
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 0 845316 4172 867512 0 0 1 3 50 38 0 0 100 0 0
[root@localhost ~]# vmstat 1
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 0 845316 4172 867512 0 0 1 3 50 38 0 0 100 0 0
0 0 0 845300 4172 867512 0 0 0 0 55 43 0 0 100 0 0
0 0 0 845300 4172 867512 0 0 0 0 46 38 0 0 100 0 0
^C
[root@localhost ~]# vmstat 1 2
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 0 845236 4172 867512 0 0 1 3 50 38 0 0 100 0 0
0 0 0 845212 4172 867512 0 0 0 0 75 60 0 0 100 0 0
procs顯示進(jìn)程相關(guān)信息
r(run):表示運(yùn)行或等待CPU時(shí)間片的進(jìn)程數(shù)。
b(block):表示等待資源的進(jìn)程數(shù),這個(gè)資源指的是I/O、內(nèi)存等。
memory顯示內(nèi)存的相關(guān)信息。
swpd:表示切換到交換分區(qū)中的內(nèi)存數(shù),內(nèi)存不夠的時(shí)候會(huì)用到,如果數(shù)字不變還好。單位為KB。
free:表示電氣概念空閑內(nèi)存數(shù)量,單位為KB。
buff:表示(即將寫入磁盤的)緩沖大小,單位為KB。
cache:表示(從磁盤中讀取的)緩存大小,單位為KB。
swap顯示內(nèi)存的交換情況。
si:表示由交換區(qū)寫入內(nèi)存的數(shù)據(jù)量,單位為KB。
so:表示由內(nèi)存寫入交換區(qū)的數(shù)據(jù)量,單位為KB。
io顯示磁盤的使用情況。
bi:從塊設(shè)備讀取數(shù)據(jù)的量
bo:從塊設(shè)備寫入數(shù)據(jù)的量
system顯示采集間隔內(nèi)發(fā)生的中斷次數(shù)
in:在某一時(shí)間間隔內(nèi)觀測(cè)到的每秒設(shè)備中斷次數(shù)。
cs:每秒產(chǎn)生的上下文切換次數(shù)。
cpu顯示CPU的使用狀態(tài)。
us:用戶花費(fèi)CPU的百分比
sy:系統(tǒng)花費(fèi)CPU的百分比
id:CPU處于空閑狀態(tài)的百分比
wa:I/O等待所占用CPU的百分比
st:被偷走的CPU所占百分比(一般都為0,不用關(guān)注)
top命令
top - 10:47:53 up 7 days, 18:29, 3 users, load average: 0.02, 0.04, 0.00
(進(jìn)程情況)Tasks: 196 total, 1 running, 194 sleeping, 0 stopped, 1 zombie
(CUP使用率)%Cpu(s): 0.2 us, 0.8 sy, 0.0 ni, 98.9 id, 0.1 wa, 0.0 hi, 0.1 si, 0.0 st
(物理內(nèi)存)KiB Mem : 949580 total, 61248 free, 119580 used, 768752 buff/cache
(交換分區(qū))KiB Swap: 102396 total, 0 free, 102396 used. 707748 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1197 root 20 0 10388 3320 2748 R 1.6 0.3 0:19.60 top
593 root 20 0 23128 7340 3108 S 0.7 0.8 13:34.87 EmbedThund+
476 root 20 0 39968 8440 4052 S 0.3 0.9 65:23.69 python
700 root 20 0 141840 10620 1436 S 0.3 1.1 4:04.84 Xorg
1306 pi 20 0 173632 15188 5044 S 0.3 1.6 30:19.66 lxpanel
1409 pi 20 0 53620 2736 2384 S 0.3 0.3 2:41.36 gvfsd-trash
30359 root 20 0 1860 1188 1048 S 0.3 0.1 1:14.39 ETMDaemon
1 root 20 0 28168 4288 3388 S 0.0 0.5 3:12.14 systemd
2 root 20 0 0 0 0 S 0.0 0.0 0:00.69 kthreadd
3 root 20 0 0 0 0 S 0.0 0.0 4:15.25 ksoftirqd/0
5 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/0:+
7 root 20 0 0 0 0 S 0.0 0.0 8:11.77 rcu_sched
8 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcu_bh
9 root rt 0 0 0 0 S 0.0 0.0 0:02.45 migration/0
10 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 lru-add-dr+
11 root 20 0 0 0 0 S 0.0 0.0 0:00.00 cpuhp/0
12 root 20 0 0 0 0 S 0.0 0.0 0:00.00 cpuhp/1
這里我們重點(diǎn)關(guān)注%CPU/、%MEM(使用內(nèi)存的百分比)和COMMAND。
在top狀態(tài)下,按Shift+m鍵可以按照內(nèi)存使用大小排序
在top狀態(tài)下,按1鍵可以列出所有核CPU的使用狀態(tài)
top -c
查看的是全路徑命令的使用情況
top - 20:09:45 up 2 days, 10:56, 2 users, load average: 0.00, 0.01, 0.05
Tasks: 101 total, 1 running, 100 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.2 us, 0.2 sy, 0.0 ni, 99.7 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem : 1867048 total, 844428 free, 150460 used, 872160 buff/cache
KiB Swap: 4194300 total, 4194300 free, 0 used. 1484400 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
40947 root 20 0 0 0 0 S 0.3 0.0 0:00.48 [kworker/0:0]
40970 root 20 0 157612 2224 1596 R 0.3 0.1 0:00.01 top -c
1 root 20 0 46052 6368 3896 S 0.0 0.3 0:08.24 /usr/lib/syst+
2 root 20 0 0 0 0 S 0.0 0.0 0:00.07 [kthreadd]
3 root 20 0 0 0 0 S 0.0 0.0 0:00.48 [ksoftirqd/0]
5 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 [kworker/0:0H]
7 root rt 0 0 0 0 S 0.0 0.0 0:00.15 [migration/0]
8 root 20 0 0 0 0 S 0.0 0.0 0:00.00 [rcu_bh]
9 root 20 0 0 0 0 S 0.0 0.0 0:05.26 [rcu_sched]
10 root rt 0 0 0 0 S 0.0 0.0 0:01.16 [watchdog/0]
11 root rt 0 0 0 0 S 0.0 0.0 0:01.04 [watchdog/1]
12 root rt 0 0 0 0 S 0.0 0.0 0:00.13 [migration/1]
13 root 20 0 0 0 0 S 0.0 0.0 0:01.58 [ksoftirqd/1]
15 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 [kworker/1:0H]
17 root 20 0 0 0 0 S 0.0 0.0 0:00.01 [kdevtmpfs]
18 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 [netns]
19 root 20 0 0 0 0 S 0.0 0.0 0:00.06 [khungtaskd]
top -bn1可以靜態(tài)的顯示
[root@localhost ~]# top -bn1|head
top - 20:10:50 up 2 days, 10:57, 2 users, load average: 0.00, 0.01, 0.05
Tasks: 102 total, 2 running, 100 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.0 us, 3.2 sy, 0.0 ni, 96.8 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem : 1867048 total, 844412 free, 150476 used, 872160 buff/cache
KiB Swap: 4194300 total, 4194300 free, 0 used. 1484384 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
40972 root 20 0 157584 2016 1476 R 6.2 0.1 0:00.01 top
1 root 20 0 46052 6368 3896 S 0.0 0.3 0:08.24 systemd
2 root 20 0 0 0 0 S 0.0 0.0 0:00.07 kthreadd
sar命令
image.png
使用sar命令需要安裝包
[root@localhost ~]# yum install -y sysstat
第一次直接單獨(dú)使用sar會(huì)報(bào)錯(cuò),因?yàn)閟ar工具還沒(méi)有產(chǎn)生相應(yīng)的數(shù)據(jù)庫(kù)文件,第一次需要先跟參數(shù)使用。
rxpck/s(每秒接受數(shù)據(jù)包個(gè)數(shù)) txpck/s(每秒發(fā)送數(shù)據(jù)包) rxkB/s(每秒接受數(shù)據(jù)KB) txkB/s(每秒發(fā)送數(shù)據(jù)KB)
數(shù)據(jù)包幾萬(wàn)幾十萬(wàn)就有可能是被攻擊
[root@localhost ~]# sar -n DEV 1 2 (每秒一次,一共兩次)
Linux 3.10.0-693.el7.x86_64 (localhost.localdomain) 2018年03月05日 _x86_64_ (2 CPU)
20時(shí)30分41秒 IFACE rxpck/s(每秒接受數(shù)據(jù)包個(gè)數(shù)) txpck/s(每秒發(fā)送數(shù)據(jù)包) rxkB/s(每秒接受數(shù)據(jù)KB) txkB/s(每秒發(fā)送數(shù)據(jù)KB) rxcmp/s txcmp/s rxmcst/s
20時(shí)30分42秒 lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
20時(shí)30分42秒 ens33 1.00 1.00 0.06 0.19 0.00 0.00 0.00
20時(shí)30分42秒 IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s
20時(shí)30分43秒 lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
20時(shí)30分43秒 ens33 1.00 1.00 0.06 0.39 0.00 0.00 0.00
平均時(shí)間: IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s
平均時(shí)間: lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
平均時(shí)間: ens33 1.00 1.00 0.06 0.29 0.00
具體查看5號(hào)的歷史流量
[root@localhost ~]# sar -n DEV -f /var/log/sa/sa05
Linux 3.10.0-693.el7.x86_64 (localhost.localdomain) 2018年03月05日 _x86_64_ (2 CPU)
20時(shí)20分03秒 IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s
20時(shí)30分05秒 lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
20時(shí)30分05秒 ens33 0.07 0.07 0.01 0.01 0.00 0.00 0.00
20時(shí)40分01秒 lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
20時(shí)40分01秒 ens33 0.11 0.10 0.01 0.01 0.00 0.00 0.00
20時(shí)50分03秒 lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
20時(shí)50分03秒 ens33 0.08 0.08 0.01 0.01 0.00 0.00 0.00
21時(shí)00分01秒 lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
21時(shí)00分01秒 ens33 0.08 0.08 0.01 0.01 0.00 0.00 0.00
平均時(shí)間: lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
平均時(shí)間: ens33 0.08 0.08 0.01 0.01 0.00 0.00 0.00
查看當(dāng)天的
[root@localhost ~]# sar -q
Linux 3.10.0-693.el7.x86_64 (localhost.localdomain) 2018年03月05日 _x86_64_ (2 CPU)
20時(shí)20分03秒 runq-sz plist-sz ldavg-1 ldavg-5 ldavg-15 blocked
20時(shí)30分05秒 0 116 0.00 0.01 0.05 0
20時(shí)40分01秒 0 116 0.00 0.01 0.05 0
20時(shí)50分03秒 0 116 0.00 0.01 0.05 0
21時(shí)00分01秒 0 116 0.00 0.01 0.05 0
21時(shí)10分01秒 0 116 0.00 0.01 0.05 0
21時(shí)20分01秒 0 115 0.00 0.01 0.05 0
21時(shí)30分06秒 0 116 0.03 0.03 0.05 0
21時(shí)40分01秒 1 116 0.00 0.02 0.05 0
平均時(shí)間: 0 116 0.00 0.01 0.05 0
查看磁盤的情況
[root@localhost ~]# sar -b 1 5
Linux 3.10.0-693.el7.x86_64 (localhost.localdomain) 2018年03月05日 _x86_64_ (2 CPU)
21時(shí)53分51秒 tps rtps wtps bread/s bwrtn/s
21時(shí)53分52秒 0.00 0.00 0.00 0.00 0.00
21時(shí)53分53秒 0.00 0.00 0.00 0.00 0.00
21時(shí)53分54秒 0.00 0.00 0.00 0.00 0.00
21時(shí)53分55秒 0.00 0.00 0.00 0.00 0.00
21時(shí)53分56秒 0.00 0.00 0.00 0.00 0.00
平均時(shí)間: 0.00 0.00 0.00 0.00 0.00
nload命令
安裝nload
[root@localhost ~]# yum install -y epel-release
[root@localhost ~]# yum install -y nload
動(dòng)態(tài)顯示
Device ens33 [172.16.79.140] (1/2):
====================================================================================
Incoming:
Curr: 1.02 kBit/s
Avg: 1.26 kBit/s
Min: 1.02 kBit/s
Max: 2.04 kBit/s
Ttl: 168.07 MByte
Outgoing:
Curr: 7.80 kBit/s
Avg: 7.55 kBit/s
Min: 4.02 kBit/s
Max: 8.30 kBit/s
Ttl: 8.36 MByte
方向鍵左右切換網(wǎng)卡

