linux性能统计 -- CPU&memory

系统级性能数据分析

 

 

常用性能指标:

所有指标都会直接间接影响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

 *大部分公司使用搭建专门的工具平台进行监控,命令行监控只是初级入门使用。

 

posted @ 2022-04-12 10:32  lms21  阅读(169)  评论(0)    收藏  举报