linux效能統計 -- CPU&memory
阿新 • • 發佈:2022-04-12
系統級效能資料分析
常用效能指標:
所有指標都會直接間接影響CPU和mem
cpu代表演算法的高效性
mem代表資料結構的使用合理性
使用工具平臺:系統性分析 promethus grafana
CPU使用統計:
列出cpu 基本資訊:
cat /proc/cpuinfo
系統負載與程序 cpu 佔用:
top
ps 命令的 cpu 是平均 cpu 利用率,不適合做效能分析
可以在proc資料夾使用PID檢視對應程序的情況
CPU的關鍵指標
- cpu 利用率 程序的 cpu 利用情況
- load average 系統負載情況 (=1為正常,>1不正常)
記憶體管理
常用命令:
free
可以看到總記憶體,使用記憶體,未使用記憶體等
--> free
總計 已用 空閒 共享 緩衝/快取 可用
記憶體: 16066856 1807248 12465444 577848 1794164 13356992
交換: 5999612 0 5999612
A:程序自己專有的記憶體
B:與其他程序共享庫的記憶體
C:先分配佔用留到後續使用的記憶體
PSS:共享記憶體平均分到各使用記憶體
記憶體洩露需關注USS
程序級別記憶體分析
top
ps(可用記憶體分析,不可做CPU分析)
ps -e -o uid,pid,ppid,pcpu,pmem,rss,vsz,comm --sort -%mem | head -10
網路連線統計:
netstat -tlnp
印表機器上被監聽的埠
-l 監聽狀態
網路狀態:
- ESTABLISHED 成功連線 The socket has an established connection
- SYN_SENT The socket is actively attempting to establish a connection
- SYN_RECV A connection request has been received from the network.
- FIN_WAIT1 The socket is closed, and the connection is shutting down.
- FIN_WAIT2 Connection is closed, and the socket is waiting for a shutdown from the remote end
- TIME_WAIT 主動關閉 The socket is waiting after close to handle packets still in the network
- CLOSE The socket is not being used
- CLOSE_WAIT 被動關閉 The remote end has shut down, waiting for the socket to close.
- LISTEN The socket is listening for incoming connections
連線數統計:
netstat -tn | awk 'NR>2{print $NF}'| sort | uniq -c | sort -nr
31 ESTABLISHED
7 TIME_WAIT
2 CLOSE_WAIT
*大部分公司使用搭建專門的工具平臺進行監控,命令列監控只是初級入門使用。