天天看點

Linux - 系統性能監控指令知識點1:系統性能監控 

目錄

知識點1:系統性能監控 

1.1 cpu性能:top指令、uptime指令、w指令

1.1.1   什麼是load average?

1.1.2  讓top指令按記憶體使用率來顯示程序資訊(預設是根據cpu使用率來排序的)

 1.2  記憶體 :top指令,free指令

使用top指令來檢視記憶體使用情況

1.2.1  buffer 和 cache的差別

 1.2.2  什麼是交換分區 swap(swappiness)?

檢視交換分區:

修改交換分區大小

臨時修改:

永久修改交換分區大小(進入 /etc/sysctl.conf檔案)

free指令檢視記憶體使用情況

1.3  磁盤 df -Th,fdisk,iostat

df -Th :檢視磁盤使用情況

fdisk -l :檢視磁盤分區

iostat:檢視磁盤讀寫的速度

sar :收集、報告或儲存系統活動資訊。 

1.4 :端口:netstat,ss,lsof,nc

檢視自己機器上面使用了哪些端口

檢視别人機器上面有哪些端口開放 

nmap:檢視整個網段有哪些IP位址是啟用的以及開啟哪些端口

fping -g 192.168.44.0/24 :檢視哪些IP位址沒有啟用

1.5 網絡流量:dstat ,glances

dstat --top-cpu --top-mem --top-io  :檢視cpu,記憶體,io讀寫,最高的程序

dstat 輸出csv檔案儲存

 glances:一個跨平台的系統監控工具

1.6  程序:top指令,ps aux指令,jobs指令,fg指令

top指令效果圖

 将top指令顯示的資訊儲存到檔案裡面  top -n 1 >top.txt

jobs指令:檢視目前終端有哪些程序在背景運作

fg (foreground)将某個指令從背景調到前台運作

ps aux指令

top指令和ps aux指令差別?

檢視消耗cpu最多的前10個程序

檢視消耗記憶體最多的1前10個程序

知識點1:系統性能監控 

1.1 cpu性能:top指令、uptime指令、w指令

Linux - 系統性能監控指令知識點1:系統性能監控 
Linux - 系統性能監控指令知識點1:系統性能監控 
Linux - 系統性能監控指令知識點1:系統性能監控 

########################################################################################  

1.1.1   什麼是load average?

檢視一下uptime的使用手冊,關于load average的解釋是這樣的

System load averages is the average number of processes that are either in a runnable or  uninterruptable  state.  

 A  process  in  a runnable state is either using the CPU or waiting to use the CPU.  A process in uninterruptable state is waiting for some I/O access, eg waiting fordisk.

系統平均負載是處于可運作狀态和不可中斷狀态的平均程序數,它反映了cpu在過去的1分鐘,5分鐘,15分鐘的一個繁忙程度,平均負載情況,

 結合三個時間的load average,來分析

1分鐘Load>1,5分鐘Load<1,15分鐘Load<1:短期内繁忙,中長期空閑,初步判斷是一個“抖動”,或者是“擁塞前兆”

1分鐘Load>1,5分鐘Load>1,15分鐘Load<1:短期内繁忙,中期内緊張,很可能是一個“擁塞的開始”

1分鐘Load>1,5分鐘Load>1,15分鐘Load>1:短、中、長期都繁忙,系統“正在擁塞”

1分鐘Load<1,5分鐘Load>1,15分鐘Load>1:短期内空閑,中、長期繁忙,不用緊張,系統“擁塞正在好轉”

檢視cpu資訊

[[email protected] ~]# cat /proc/cpuinfo 
processor	: 0
vendor_id	: GenuineIntel
cpu family	: 6
model		: 126
model name	: Intel(R) Core(TM) i5-1035G1 CPU @ 1.00GHz
stepping	: 5
microcode	: 0xb0
cpu MHz		: 1190.402
cache size	: 6144 KB
physical id	: 0
siblings	: 1
core id		: 0
cpu cores	: 1
apicid		: 0
initial apicid	: 0
fpu		: yes
fpu_exception	: yes
cpuid level	: 27
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 invpcid_single ssbd ibrs ibpb stibp ibrs_enhanced fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid avx512f avx512dq rdseed adx smap avx512ifma clflushopt avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 arat avx512vbmi umip pku ospke avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg avx512_vpopcntdq md_clear spec_ctrl intel_stibp flush_l1d arch_capabilities
bogomips	: 2380.80
clflush size	: 64
cache_alignment	: 64
address sizes	: 45 bits physical, 48 bits virtual
power management:
           

########################################################################################  

1.1.2  讓top指令按記憶體使用率來顯示程序資訊(預設是根據cpu使用率來排序的)

進入top後按M來按記憶體使用多少來顯示

Linux - 系統性能監控指令知識點1:系統性能監控 

########################################################################################  

 1.2  記憶體 :top指令,free指令

使用top指令來檢視記憶體使用情況

Linux - 系統性能監控指令知識點1:系統性能監控 

top指令會以kb為機關,total顯示記憶體總共有多大,free剩餘沒有使用的有多少,used已經使用的記憶體大小,以及buffer和cache的記憶體大小

avail Mem其實指的是 free 剩餘沒有使用的空間,以及buff和cache裡面沒有使用的空間,例如:buff裡面的資料已經寫到了磁盤,那麼buff就空出來了一些空間

1.2.1  buffer 和 cache的差別

buffer和cache都是記憶體中的一塊區域

1.Buffer的核心作用是用來緩沖,緩和沖擊。着重于寫操作。Buffer是對原始磁盤塊的臨時存儲,也就是用來緩存磁盤的資料,buffer通常不會特别大(20MB 左右)。是以核心就可以把分散的寫的操作集中起來,統一優化磁盤的寫入。

2.Cache的核心作用是加快取用的速度(與memory相關)。着重于讀操作。Cache 是從磁盤讀取檔案的頁緩存,也就是用來緩存從檔案讀取的資料。這樣,下次通路這些檔案資料時,就可以直接從記憶體中快速擷取,而不需要再次通路緩慢的磁盤。

總結:buffer是加速資料寫入磁盤,cache是用來加速資料從磁盤裡面讀取的

Linux - 系統性能監控指令知識點1:系統性能監控 

########################################################################################  

 1.2.2  什麼是交換分區 swap(swappiness)?

交換分區就是在實體記憶體使用完之後,從磁盤劃出一塊區域來作為虛拟記憶體使用

檢視交換分區:

[[email protected] ~]# cat /proc/sys/vm/swappiness 
30
           
 含義:在實體記憶體隻剩下 30%的時候使用交換分區

修改交換分區大小

臨時修改:

[[email protected] ~]# echo 0 >/proc/sys/vm/swappiness 
[[email protected] ~]# cat /proc/sys/vm/swappiness 
0
           

永久修改交換分區大小(進入 /etc/sysctl.conf檔案)

sysctl -p :讓核心讀取sysctl.conf檔案
[[email protected] ~]# vim /etc/sysctl.conf 
[[email protected] ~]# sysctl -p
vm.swappiness = 0

           

free指令檢視記憶體使用情況

-m :以M的形式顯示

-h:以human人類可以讀懂的形式顯示

[[email protected] ~]# free
              total        used        free      shared  buff/cache   available
Mem:         995672      529184       98968       35352      367520      280832
Swap:       2097148        5896     2091252
[[email protected] ~]# free -m
              total        used        free      shared  buff/cache   available
Mem:            972         516          96          34         358         274
Swap:          2047           5        2042
[[email protected] ~]# free -h
              total        used        free      shared  buff/cache   available
Mem:           972M        516M         96M         34M        358M        274M
Swap:          2.0G        5.8M        2.0G
[[email protected] ~]# 
           

########################################################################################  

1.3  磁盤 df -Th,fdisk,iostat

df -Th :檢視磁盤使用情況

[[email protected] ~]# df -Th
檔案系統                類型      容量  已用  可用 已用% 挂載點
devtmpfs                devtmpfs  475M     0  475M    0% /dev
tmpfs                   tmpfs     487M     0  487M    0% /dev/shm
tmpfs                   tmpfs     487M  8.0M  479M    2% /run
tmpfs                   tmpfs     487M     0  487M    0% /sys/fs/cgroup
/dev/mapper/centos-root xfs        17G  8.0G  9.1G   47% /
/dev/sda1               xfs      1014M  138M  877M   14% /boot
tmpfs                   tmpfs      98M     0   98M    0% /run/user/0
overlay                 overlay    17G  8.0G  9.1G   47% /var/lib/docker/overlay2/94cb041475d250f0b96b873af048a475d5702774b38ce49ff84d2a5d7f281d34/merged
overlay                 overlay    17G  8.0G  9.1G   47% /var/lib/docker/overlay2/d860e9489d67bfdab062cff7fcf910bcf46d2ac8ecbe9270a82142029363d5df/merged
           

fdisk -l :檢視磁盤分區

[[email protected] ~]# fdisk -l

磁盤 /dev/sda:21.5 GB, 21474836480 位元組,41943040 個扇區
Units = 扇區 of 1 * 512 = 512 bytes
扇區大小(邏輯/實體):512 位元組 / 512 位元組
I/O 大小(最小/最佳):512 位元組 / 512 位元組
磁盤标簽類型:dos
磁盤辨別符:0x000ca43d

   裝置 Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200    41943039    19921920   8e  Linux LVM

磁盤 /dev/mapper/centos-root:18.2 GB, 18249416704 位元組,35643392 個扇區
Units = 扇區 of 1 * 512 = 512 bytes
扇區大小(邏輯/實體):512 位元組 / 512 位元組
I/O 大小(最小/最佳):512 位元組 / 512 位元組


磁盤 /dev/mapper/centos-swap:2147 MB, 2147483648 位元組,4194304 個扇區
Units = 扇區 of 1 * 512 = 512 bytes
扇區大小(邏輯/實體):512 位元組 / 512 位元組
I/O 大小(最小/最佳):512 位元組 / 512 位元組
           

iostat:檢視磁盤讀寫的速度

[[email protected] ~]# iostat
Linux 3.10.0-1160.el7.x86_64 (docker1) 	2022年09月06日 	_x86_64_	(1 CPU)

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           0.31    0.00    0.42    0.01    0.00   99.26

Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
sda               2.19        63.97        16.50     962347     248230
scd0              0.00         0.07         0.00       1028          0
dm-0              2.06        63.08        15.88     948901     238814
dm-1              0.15         0.24         0.49       3664       7352
           
-x :顯示很多參數 ,顯示擴充的統計資訊
[[email protected] ~]# iostat -x
Linux 3.10.0-1160.el7.x86_64 (docker1) 	2022年09月06日 	_x86_64_	(1 CPU)

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           0.31    0.00    0.42    0.01    0.00   99.26

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.15    1.50    0.70    63.96    16.68    73.14     0.00    0.61    0.67    0.47   0.29   0.06
scd0              0.00     0.00    0.00    0.00     0.07     0.00   114.22     0.00    2.11    2.11    0.00   1.67   0.00
dm-0              0.00     0.00    1.34    0.73    63.07    16.06    76.12     0.00    0.66    0.73    0.52   0.30   0.06
dm-1              0.00     0.00    0.03    0.12     0.24     0.49     9.62     0.00    0.73    0.28    0.83   0.07   0.00
           
iostat -x 1 2 :每隔1秒統計一次輸出出來
[[email protected] ~]# iostat -x 1 2
Linux 3.10.0-1160.el7.x86_64 (docker1) 	2022年09月06日 	_x86_64_	(1 CPU)

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           0.31    0.00    0.41    0.01    0.00   99.27

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.15    1.45    0.69    61.73    16.22    72.96     0.00    0.61    0.67    0.47   0.29   0.06
scd0              0.00     0.00    0.00    0.00     0.07     0.00   114.22     0.00    2.11    2.11    0.00   1.67   0.00
dm-0              0.00     0.00    1.30    0.72    60.86    15.62    75.90     0.00    0.66    0.74    0.52   0.30   0.06
dm-1              0.00     0.00    0.03    0.12     0.24     0.47     9.61     0.00    0.73    0.30    0.83   0.08   0.00

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

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.00    0.00    0.00     0.00     0.00     0.00     0.00    0.00    0.00    0.00   0.00   0.00
scd0              0.00     0.00    0.00    0.00     0.00     0.00     0.00     0.00    0.00    0.00    0.00   0.00   0.00
dm-0              0.00     0.00    0.00    0.00     0.00     0.00     0.00     0.00    0.00    0.00    0.00   0.00   0.00
dm-1              0.00     0.00    0.00    0.00     0.00     0.00     0.00     0.00    0.00    0.00    0.00   0.00   0.00

[[email protected] ~]# 
           

sar :收集、報告或儲存系統活動資訊。 

[[email protected] ~]# sar -d 1 2
Linux 3.10.0-1160.el7.x86_64 (docker1) 	2022年09月06日 	_x86_64_	(1 CPU)

16時49分04秒       DEV       tps  rd_sec/s  wr_sec/s  avgrq-sz  avgqu-sz     await     svctm     %util
16時49分05秒    dev8-0      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
16時49分05秒   dev11-0      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
16時49分05秒  dev253-0      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
16時49分05秒  dev253-1      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00

16時49分05秒       DEV       tps  rd_sec/s  wr_sec/s  avgrq-sz  avgqu-sz     await     svctm     %util
16時49分06秒    dev8-0      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
16時49分06秒   dev11-0      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
16時49分06秒  dev253-0      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
16時49分06秒  dev253-1      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00

平均時間:       DEV       tps  rd_sec/s  wr_sec/s  avgrq-sz  avgqu-sz     await     svctm     %util
平均時間:    dev8-0      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
平均時間:   dev11-0      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
平均時間:  dev253-0      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
平均時間:  dev253-1      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
[[email protected] ~]# 
           
[[email protected] ~]# sar -b
Linux 3.10.0-1160.el7.x86_64 (docker1) 	2022年09月06日 	_x86_64_	(1 CPU)

16時40分01秒       tps      rtps      wtps   bread/s   bwrtn/s
16時50分01秒      0.23      0.07      0.15      3.45      1.87
平均時間:      0.23      0.07      0.15      3.45      1.87
[[email protected] ~]# 
           

######################################################################################## 

1.4 :端口:netstat,ss,lsof,nc

檢視自己機器上面使用了哪些端口

[[email protected] ~]# netstat -anplut
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      675/rpcbind         
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      2358/docker-proxy   
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1042/sshd           
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1191/master         
tcp        0      0 192.168.44.201:45506    202.202.1.140:80        TIME_WAIT   -                   
tcp        0      0 192.168.44.201:45508    202.202.1.140:80        TIME_WAIT   -                   
tcp        0      0 192.168.44.201:22       192.168.44.1:58394      ESTABLISHED 3017/sshd: [email protected] 
tcp        0      0 192.168.44.201:22       192.168.44.1:55063      ESTABLISHED 3367/sshd: [email protected] 
tcp6       0      0 :::111                  :::*                    LISTEN      675/rpcbind         
tcp6       0      0 :::80                   :::*                    LISTEN      2365/docker-proxy   
tcp6       0      0 :::22                   :::*                    LISTEN      1042/sshd           
tcp6       0      0 ::1:25                  :::*                    LISTEN      1191/master         
udp        0      0 0.0.0.0:111             0.0.0.0:*                           675/rpcbind         
udp        0      0 127.0.0.1:323           0.0.0.0:*                           687/chronyd         
udp        0      0 0.0.0.0:848             0.0.0.0:*                           675/rpcbind         
udp6       0      0 :::111                  :::*                                675/rpcbind         
udp6       0      0 ::1:323                 :::*                                687/chronyd         
udp6       0      0 :::848                  :::*                                675/rpcbind   
           
[[email protected] ~]# ss -anplut
Netid  State      Recv-Q Send-Q      Local Address:Port                     Peer Address:Port              
udp    UNCONN     0      0                       *:111                                 *:*                   users:(("rpcbind",pid=675,fd=6))
udp    UNCONN     0      0               127.0.0.1:323                                 *:*                   users:(("chronyd",pid=687,fd=5))
udp    UNCONN     0      0                       *:848                                 *:*                   users:(("rpcbind",pid=675,fd=7))
udp    UNCONN     0      0                    [::]:111                              [::]:*                   users:(("rpcbind",pid=675,fd=9))
udp    UNCONN     0      0                   [::1]:323                              [::]:*                   users:(("chronyd",pid=687,fd=6))
udp    UNCONN     0      0                    [::]:848                              [::]:*                   users:(("rpcbind",pid=675,fd=10))
tcp    LISTEN     0      128                     *:111                                 *:*                   users:(("rpcbind",pid=675,fd=8))
tcp    LISTEN     0      128                     *:80                                  *:*                   users:(("docker-proxy",pid=2358,fd=4))
tcp    LISTEN     0      128                     *:22                                  *:*                   users:(("sshd",pid=1042,fd=3))
tcp    LISTEN     0      100             127.0.0.1:25                                  *:*                   users:(("master",pid=1191,fd=13))
tcp    LISTEN     0      128                  [::]:111                              [::]:*                   users:(("rpcbind",pid=675,fd=11))
tcp    LISTEN     0      128                  [::]:80                               [::]:*                   users:(("docker-proxy",pid=2365,fd=4))
tcp    LISTEN     0      128                  [::]:22                               [::]:*                   users:(("sshd",pid=1042,fd=4))
tcp    LISTEN     0      100                 [::1]:25                               [::]:*                   users:(("master",pid=1191,fd=14))
           
[[email protected] ~]# lsof -i:80
COMMAND    PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
docker-pr 2358 root    4u  IPv4  43862      0t0  TCP *:http (LISTEN)
docker-pr 2365 root    4u  IPv6  43903      0t0  TCP *:http (LISTEN)
           

檢視别人機器上面有哪些端口開放 

檢視别人機器上面有哪些端口開放

nc -z 114.114.114.114 53

-z 選項:不發送資料包

53 :檢視53号端口是否開放

echo $? 檢視傳回值,如果傳回值為0則端口是開放的,非0則沒有開放

-w選項:隻等待1秒鐘

[[email protected] ~]# nc -z 114.114.114.114 53
[[email protected] ~]# echo $?
0
[[email protected] ~]# nc -z 114.114.114.114 80
[[email protected] ~]# echo $?
1
           
[[email protected] ~]# nc -z -w 1 114.114.114.114 22
[[email protected] ~]# echo $?
1
           

nmap:檢視整個網段有哪些IP位址是啟用的以及開啟哪些端口

[[email protected] ~]# nmap 192.168.44.0/24

Starting Nmap 6.40 ( http://nmap.org ) at 2022-09-06 17:00 CST
Nmap scan report for 192.168.44.1
Host is up (0.00076s latency).
Not shown: 999 filtered ports
PORT     STATE SERVICE
9091/tcp open  xmltec-xmlmail
MAC Address: 00:50:56:C0:00:08 (VMware)

Nmap scan report for 192.168.44.2
Host is up (0.00029s latency).
All 1000 scanned ports on 192.168.44.2 are closed
MAC Address: 00:50:56:EF:D1:5C (VMware)

Nmap scan report for 192.168.44.254
Host is up (-0.10s latency).
All 1000 scanned ports on 192.168.44.254 are filtered
MAC Address: 00:50:56:E0:49:C8 (VMware)

Nmap scan report for 192.168.44.201
Host is up (0.0000070s latency).
Not shown: 997 closed ports
PORT    STATE SERVICE
22/tcp  open  ssh
80/tcp  open  http
111/tcp open  rpcbind

Nmap done: 256 IP addresses (4 hosts up) scanned in 93.27 seconds
           

fping -g 192.168.44.0/24 :檢視哪些IP位址沒有啟用

^C192.168.44.1 is unreachable
192.168.44.3 is unreachable
192.168.44.4 is unreachable
192.168.44.5 is unreachable
192.168.44.6 is unreachable
192.168.44.7 is unreachable
192.168.44.8 is unreachable
192.168.44.9 is unreachable
192.168.44.10 is unreachable
192.168.44.11 is unreachable
192.168.44.12 is unreachable
192.168.44.13 is unreachable
192.168.44.14 is unreachable
192.168.44.15 is unreachable
192.168.44.16 is unreachable
192.168.44.17 is unreachable
192.168.44.18 is unreachable
192.168.44.19 is unreachable
192.168.44.20 is unreachable
192.168.44.21 is unreachable
192.168.44.22 is unreachable
192.168.44.23 is unreachable
192.168.44.24 is unreachable
192.168.44.25 is unreachable
192.168.44.26 is unreachable
192.168.44.27 is unreachable
192.168.44.28 is unreachable
192.168.44.29 is unreachable
192.168.44.30 is unreachable
192.168.44.31 is unreachable
192.168.44.32 is unreachable
192.168.44.33 is unreachable
192.168.44.34 is unreachable
192.168.44.35 is unreachable
192.168.44.36 is unreachable
192.168.44.37 is unreachable
192.168.44.38 is unreachable
192.168.44.39 is unreachable
192.168.44.40 is unreachable
192.168.44.41 is unreachable
192.168.44.42 is unreachable
192.168.44.43 is unreachable
192.168.44.44 is unreachable
192.168.44.45 is unreachable
192.168.44.46 is unreachable
192.168.44.47 is unreachable
192.168.44.48 is unreachable
192.168.44.49 is unreachable
192.168.44.50 is unreachable
192.168.44.51 is unreachable
192.168.44.52 is unreachable
192.168.44.53 is unreachable
192.168.44.54 is unreachable
192.168.44.55 is unreachable
192.168.44.56 is unreachable
192.168.44.57 is unreachable
192.168.44.58 is unreachable
192.168.44.59 is unreachable
192.168.44.60 is unreachable
192.168.44.61 is unreachable
192.168.44.62 is unreachable
192.168.44.63 is unreachable
192.168.44.64 is unreachable
192.168.44.65 is unreachable
192.168.44.66 is unreachable
192.168.44.67 is unreachable
192.168.44.68 is unreachable
192.168.44.69 is unreachable
192.168.44.70 is unreachable
192.168.44.71 is unreachable
192.168.44.72 is unreachable
192.168.44.73 is unreachable
192.168.44.74 is unreachable
192.168.44.75 is unreachable
192.168.44.76 is unreachable
192.168.44.77 is unreachable
192.168.44.78 is unreachable
192.168.44.79 is unreachable
192.168.44.80 is unreachable
192.168.44.81 is unreachable
192.168.44.82 is unreachable
192.168.44.83 is unreachable
192.168.44.84 is unreachable
192.168.44.85 is unreachable
192.168.44.86 is unreachable
192.168.44.87 is unreachable
192.168.44.88 is unreachable
192.168.44.89 is unreachable
192.168.44.90 is unreachable
192.168.44.91 is unreachable
192.168.44.92 is unreachable
192.168.44.93 is unreachable
192.168.44.94 is unreachable
192.168.44.95 is unreachable
192.168.44.96 is unreachable
192.168.44.97 is unreachable
192.168.44.98 is unreachable
192.168.44.99 is unreachable
192.168.44.100 is unreachable
192.168.44.101 is unreachable
192.168.44.102 is unreachable
192.168.44.103 is unreachable
192.168.44.104 is unreachable
192.168.44.105 is unreachable
192.168.44.106 is unreachable
192.168.44.107 is unreachable
192.168.44.108 is unreachable
192.168.44.109 is unreachable
192.168.44.110 is unreachable
192.168.44.111 is unreachable
192.168.44.112 is unreachable
192.168.44.113 is unreachable
192.168.44.114 is unreachable
192.168.44.115 is unreachable
192.168.44.116 is unreachable
192.168.44.117 is unreachable
192.168.44.118 is unreachable
192.168.44.119 is unreachable
192.168.44.120 is unreachable
192.168.44.121 is unreachable
192.168.44.122 is unreachable
192.168.44.123 is unreachable
192.168.44.124 is unreachable
192.168.44.125 is unreachable
192.168.44.126 is unreachable
192.168.44.127 is unreachable
192.168.44.128 is unreachable
192.168.44.129 is unreachable
192.168.44.130 is unreachable
192.168.44.131 is unreachable
192.168.44.132 is unreachable
192.168.44.133 is unreachable
192.168.44.134 is unreachable
192.168.44.135 is unreachable
192.168.44.136 is unreachable
192.168.44.137 is unreachable
192.168.44.138 is unreachable
192.168.44.139 is unreachable
192.168.44.140 is unreachable
192.168.44.141 is unreachable
192.168.44.142 is unreachable
192.168.44.143 is unreachable
192.168.44.144 is unreachable
192.168.44.145 is unreachable
192.168.44.146 is unreachable
192.168.44.147 is unreachable
192.168.44.148 is unreachable
192.168.44.149 is unreachable
192.168.44.150 is unreachable
192.168.44.151 is unreachable
192.168.44.152 is unreachable
192.168.44.153 is unreachable
192.168.44.154 is unreachable
192.168.44.155 is unreachable
192.168.44.156 is unreachable
192.168.44.157 is unreachable
192.168.44.158 is unreachable
192.168.44.159 is unreachable
192.168.44.160 is unreachable
192.168.44.161 is unreachable
192.168.44.162 is unreachable
192.168.44.163 is unreachable
192.168.44.164 is unreachable
192.168.44.165 is unreachable
192.168.44.166 is unreachable
192.168.44.167 is unreachable
192.168.44.168 is unreachable
192.168.44.169 is unreachable
192.168.44.170 is unreachable
192.168.44.171 is unreachable
192.168.44.172 is unreachable
192.168.44.173 is unreachable
192.168.44.174 is unreachable
192.168.44.175 is unreachable
192.168.44.176 is unreachable
192.168.44.177 is unreachable
192.168.44.178 is unreachable
192.168.44.179 is unreachable
192.168.44.180 is unreachable
192.168.44.181 is unreachable
192.168.44.182 is unreachable
192.168.44.183 is unreachable
192.168.44.184 is unreachable
192.168.44.185 is unreachable
192.168.44.186 is unreachable
192.168.44.187 is unreachable
192.168.44.188 is unreachable
192.168.44.189 is unreachable
192.168.44.190 is unreachable
192.168.44.191 is unreachable
192.168.44.192 is unreachable
192.168.44.193 is unreachable
192.168.44.194 is unreachable
192.168.44.195 is unreachable
192.168.44.196 is unreachable
192.168.44.197 is unreachable
192.168.44.198 is unreachable
192.168.44.199 is unreachable
192.168.44.200 is unreachable
192.168.44.202 is unreachable
192.168.44.203 is unreachable
192.168.44.204 is unreachable
192.168.44.205 is unreachable
192.168.44.206 is unreachable
192.168.44.207 is unreachable
192.168.44.208 is unreachable
192.168.44.209 is unreachable
192.168.44.210 is unreachable
192.168.44.211 is unreachable
192.168.44.212 is unreachable
192.168.44.213 is unreachable
192.168.44.214 is unreachable
192.168.44.215 is unreachable
192.168.44.216 is unreachable
192.168.44.217 is unreachable
192.168.44.218 is unreachable
192.168.44.219 is unreachable
192.168.44.220 is unreachable
192.168.44.221 is unreachable
192.168.44.222 is unreachable
192.168.44.223 is unreachable
192.168.44.224 is unreachable
192.168.44.225 is unreachable
192.168.44.226 is unreachable
192.168.44.227 is unreachable
192.168.44.228 is unreachable
192.168.44.229 is unreachable
192.168.44.230 is unreachable
192.168.44.231 is unreachable
192.168.44.232 is unreachable
192.168.44.233 is unreachable
192.168.44.234 is unreachable
192.168.44.235 is unreachable
192.168.44.236 is unreachable
192.168.44.237 is unreachable
192.168.44.238 is unreachable
192.168.44.239 is unreachable
192.168.44.240 is unreachable
192.168.44.241 is unreachable
192.168.44.242 is unreachable
192.168.44.243 is unreachable
192.168.44.244 is unreachable
192.168.44.245 is unreachable
192.168.44.246 is unreachable
192.168.44.247 is unreachable
192.168.44.248 is unreachable
192.168.44.249 is unreachable
192.168.44.250 is unreachable
192.168.44.251 is unreachable
192.168.44.252 is unreachable
192.168.44.253 is unreachable
192.168.44.254 is unreachable
           

######################################################################################## 

1.5 網絡流量:dstat ,glances

dstat:用于生成系統資源統計的通用工具 

Linux - 系統性能監控指令知識點1:系統性能監控 

dstat --top-cpu --top-mem --top-io  :檢視cpu,記憶體,io讀寫,最高的程序

Linux - 系統性能監控指令知識點1:系統性能監控 

dstat 輸出csv檔案儲存

[[email protected] ~]# cat dstat_monitor.csv 
"Dstat 0.7.2 CSV output"
"Author:","Dag Wieers <[email protected]>",,,,"URL:","http://dag.wieers.com/home-made/dstat/"
"Host:","docker1",,,,"User:","root"
"Cmdline:","dstat -am --output /root/dstat_monitor.csv",,,,"Date:","06 Sep 2022 18:36:24 CST"

"total cpu usage",,,,,,"dsk/total",,"net/total",,"paging",,"system",,"memory usage",,,
"usr","sys","idl","wai","hiq","siq","read","writ","recv","send","in","out","int","csw","used","buff","cach","free"
0.359,0.336,99.271,0.008,0.0,0.026,48397.530,20792.628,0.0,0.0,69.032,333.897,68.080,131.393,595779584.0,28672.0,252149760.0,171610112.0,
0.0,0.0,100.0,0.0,0.0,0.0,0.0,0.0,120.0,898.0,0.0,0.0,53.0,108.0,595775488.0,28672.0,252153856.0,171610112.0,
0.0,0.0,100.0,0.0,0.0,0.0,0.0,0.0,120.0,346.0,0.0,0.0,56.0,100.0,595775488.0,28672.0,252153856.0,171610112.0,
0.0,0.0,100.0,0.0,0.0,0.0,0.0,0.0,120.0,346.0,0.0,0.0,54.0,104.0,595775488.0,28672.0,252153856.0,171610112.0,
           
[[email protected] ~]# dstat -am --output /root/dstat_monitor.csv
           

 glances:一個跨平台的系統監控工具

Linux - 系統性能監控指令知識點1:系統性能監控 

 ######################################################################################## 

1.6  程序:top指令,ps aux指令,jobs指令,fg指令

top指令效果圖

top指令預設1.5秒疊代更新一次
Linux - 系統性能監控指令知識點1:系統性能監控 

 将top指令顯示的資訊儲存到檔案裡面  top -n 1 >top.txt

-n 1  :top指令疊代一次,output到top.txt檔案裡面
[[email protected] ~]# top -n 1 >top.txt
[[email protected] ~]# cat top.txt 
top - 18:40:56 up  6:20,  3 users,  load average: 0.00, 0.01, 0.05
Tasks: 124 total,   1 running, 123 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem :   995672 total,   169860 free,   521348 used,   304464 buff/cache
KiB Swap:  2097148 total,  2091508 free,     5640 used.   282780 avail Mem 

   PID USER      PR  NI    VIRT    RES    SHR S %CPU %MEM     TIME+ COMMAND         
     1 root      20   0  128272   5712   2960 S  0.0  0.6   0:02.36 systemd         
     2 root      20   0       0      0      0 S  0.0  0.0   0:00.01 kthreadd        
     4 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 kworker/0:0H    
     6 root      20   0       0      0      0 S  0.0  0.0   0:01.78 ksoftirqd/0     
     7 root      rt   0       0      0      0 S  0.0  0.0   0:00.00 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:01.44 rcu_sched       
    10 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 lru-add-drain   
    11 root      rt   0       0      0      0 S  0.0  0.0   0:00.26 watchdog/0      
    13 root      20   0       0      0      0 S  0.0  0.0   0:00.00 kdevtmpfs       
    14 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 netns           
    15 root      20   0       0      0      0 S  0.0  0.0   0:00.02 khungtaskd      
    16 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 writeback       
    17 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 kintegrityd     
    18 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 bioset          
    19 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 bioset          
    20 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 bioset          
[[email protected] ~]# 
           

jobs指令:檢視目前終端有哪些程序在背景運作

在指令後面使用 & 可以将一個程序放到背景運作
[[email protected] ~]# vim wang.txt &
[1] 3903
[[email protected] ~]# vim liu.txt &
[2] 3904

[1]+  已停止               vim wang.txt
[[email protected] ~]# vim li.txt &
[3] 3905

[2]+  已停止               vim liu.txt
[[email protected] ~]# jobs
[1]   已停止               vim wang.txt
[2]-  已停止               vim liu.txt
[3]+  已停止               vim li.txt
[[email protected] ~]# echo "hello" &
[4] 3907
[[email protected] ~]# hello
jobs
[1]   已停止               vim wang.txt
[2]-  已停止               vim liu.txt
[3]+  已停止               vim li.txt
[4]   完成                  echo "hello"
           

fg (foreground)将某個指令從背景調到前台運作

[[email protected] ~]# fg 2
vim liu.txt
           

ps aux指令

top指令和ps aux指令差別?

top指令會疊代顯示程序資訊,ps aux是顯示的一瞬間的程序資訊
  • a:顯示一個終端所有的程序
  • u:顯示程序的歸屬使用者及記憶體使用情況
  • x:顯示沒有關聯控制終端的程序
[[email protected] ~]# ps aux
USER        PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root          1  0.0  0.5 128272  5804 ?        Ss   15:29   0:02 /usr/lib/systemd/systemd --switched-roo
root          2  0.0  0.0      0     0 ?        S    15:29   0:00 [kthreadd]
root          4  0.0  0.0      0     0 ?        S<   15:29   0:00 [kworker/0:0H]
root          6  0.0  0.0      0     0 ?        S    15:29   0:01 [ksoftirqd/0]
root          7  0.0  0.0      0     0 ?        S    15:29   0:00 [migration/0]
root          8  0.0  0.0      0     0 ?        S    15:29   0:00 [rcu_bh]
root          9  0.0  0.0      0     0 ?        R    15:29   0:01 [rcu_sched]
root         10  0.0  0.0      0     0 ?        S<   15:29   0:00 [lru-add-drain]
root         11  0.0  0.0      0     0 ?        S    15:29   0:00 [watchdog/0]
root         13  0.0  0.0      0     0 ?        S    15:29   0:00 [kdevtmpfs]
root         14  0.0  0.0      0     0 ?        S<   15:29   0:00 [netns]
root         15  0.0  0.0      0     0 ?        S    15:29   0:00 [khungtaskd]
root         16  0.0  0.0      0     0 ?        S<   15:29   0:00 [writeback]
root         17  0.0  0.0      0     0 ?        S<   15:29   0:00 [kintegrityd]
root         18  0.0  0.0      0     0 ?        S<   15:29   0:00 [bioset]
root         19  0.0  0.0      0     0 ?        S<   15:29   0:00 [bioset]
root         20  0.0  0.0      0     0 ?        S<   15:29   0:00 [bioset]
root         21  0.0  0.0      0     0 ?        S<   15:29   0:00 [kblockd]
root         22  0.0  0.0      0     0 ?        S<   15:29   0:00 [md]
root         23  0.0  0.0      0     0 ?        S<   15:29   0:00 [edac-poller]
root         24  0.0  0.0      0     0 ?        S<   15:29   0:00 [watchdogd]
root         30  0.0  0.0      0     0 ?        S    15:29   0:00 [kswapd0]
root         31  0.0  0.0      0     0 ?        SN   15:29   0:00 [ksmd]
root         32  0.0  0.0      0     0 ?        SN   15:29   0:00 [khugepaged]
root         33  0.0  0.0      0     0 ?        S<   15:29   0:00 [crypto]
           

檢視消耗cpu最多的前10個程序

[[email protected] ~]# ps aux |tail -n +2 |sort -k 3 -rn | head
root        678  0.1  0.4 273196  4268 ?        Ssl  15:29   0:38 /usr/bin/vmtoolsd
rpc         675  0.0  0.1  69256  1004 ?        Ss   15:29   0:00 /sbin/rpcbind -w
root         95  0.0  0.0      0     0 ?        S    15:29   0:00 [kauditd]
root          9  0.0  0.0      0     0 ?        R    15:29   0:01 [rcu_sched]
root          8  0.0  0.0      0     0 ?        S    15:29   0:00 [rcu_bh]
root        730  0.0  0.7 475036  7296 ?        Ssl  15:29   0:02 /usr/sbin/NetworkManager --no-daemon
root        713  0.0  0.2  96572  2348 ?        Ss   15:29   0:00 login -- root
root        711  0.0  0.1 126416  1704 ?        Ss   15:29   0:00 /usr/sbin/crond -n
root          7  0.0  0.0      0     0 ?        S    15:29   0:00 [migration/0]
root        689  0.0  0.1 195204  1152 ?        Ssl  15:29   0:00 /usr/sbin/gssproxy -D
           

檢視消耗記憶體最多的1前10個程序

[[email protected] ~]# ps aux |tail -n +2 |sort -k 4 -rn | head
polkitd    2385  0.0  7.8 1074544 77856 ?       Ssl  16:33   0:10 mysqld --default-authentication-plugin=mysql_native_password
33         2585  0.0  5.9 362492 59648 ?        S    16:33   0:01 apache2 -DFOREGROUND
root       1106  0.0  4.6 1341788 46676 ?       Ssl  15:29   0:09 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
33         2583  0.0  4.0 308440 40372 ?        S    16:33   0:01 apache2 -DFOREGROUND
33         2587  0.0  3.6 343016 36600 ?        S    16:33   0:00 apache2 -DFOREGROUND
33         2681  0.0  3.5 308896 35148 ?        S    16:38   0:01 apache2 -DFOREGROUND
33         2762  0.0  3.3 340740 33256 ?        S    17:10   0:00 apache2 -DFOREGROUND
33         2767  0.0  3.1 308604 31236 ?        S    17:10   0:00 apache2 -DFOREGROUND
root       1049  0.0  2.8 1026176 27888 ?       Ssl  15:29   0:12 /usr/bin/containerd
33         2780  0.0  2.8 308552 28500 ?        S    17:12   0:00 apache2 -DFOREGROUND
           

繼續閱讀