01-05 Linux常用命令-性能统计

CPU 相关
w:查看当前系统的负载

[root@xiaojw ~]# w 14:02:34 up 272 days, 17:33,1 user,load average: 0.00, 0.03, 0.01 USERTTYFROMLOGIN@IDLEJCPUPCPU WHAT rootpts/0183.237.175.8914:022.00s0.26s0.00s w# 14:02:34 up 272 days, 17:33,1 user,load average: 0.00, 0.03, 0.01 # 时间系统运行时间登录用户数平均负载(重要!):1分钟内,5分钟内,15分钟内 # 平均负载,值越大,说明服务器压力越大;这个值只要不超过服务器的CPU数量即可

【01-05 Linux常用命令-性能统计】cat /proc/cupinfo:查看 CPU 相关的基本信息
[root@localhost ~]# cat /proc/cpuinfo processor: 0 vendor_id: GenuineIntel cpu family: 6 model: 158 model name: Intel(R) Core(TM) i5-9400 CPU @ 2.90GHz stepping: 13 cpu MHz: 2904.002 cache size: 9216 KB physical id: 0 siblings: 1 core id: 0 cpu cores: 1 apicid: 0 initial apicid: 0 fpu: yes fpu_exception: yes cpuid level: 22 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 ht syscall nx rdtscp lm constant_tsc rep_good nopl xtopology nonstop_tsc eagerfpu pni pclmulqdq monitor ssse3 cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx rdrand hypervisor lahf_lm abm 3dnowprefetch invpcid_single fsgsbase avx2 invpcid rdseed clflushopt flush_l1d bogomips: 5808.00 clflush size: 64 cache_alignment : 64 address sizes: 39 bits physical, 48 bits virtual power management:

top:显示进程所占的系统资源
top - 07:49:20 up 5 min,1 user,load average: 0.00, 0.01, 0.01 # 系统负载 Tasks:93 total,1 running,92 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 # CPU 使用情况 KiB Mem :2914272 total,2560228 free,222864 used,131180 buff/cache # 内存使用情况 KiB Swap:3145724 total,3145724 free,0 used.2542568 avail Mem # 交换分区使用情况PID USERPRNIVIRTRESSHR S %CPU %MEMTIME+ COMMAND 1 root20012801265964140 S0.00.20:00.86 systemd 2 root200000 S0.00.00:00.00 kthreadd 4 root0 -20000 S0.00.00:00.00 kworker/0:0H 5 root200000 S0.00.00:00.00 kworker/u2:0 6 root200000 S0.00.00:00.02 ksoftirqd/0 7 rootrt0000 S0.00.00:00.00 migration/0 8 root200000 S0.00.00:00.00 rcu_bh 9 root200000 S0.00.00:00.25 rcu_sched 10 root0 -20000 S0.00.00:00.00 lru-add-drain 11 rootrt0000 S0.00.00:00.00 watchdog/0 13 root200000 S0.00.00:00.00 kdevtmpfs 14 root0 -20000 S0.00.00:00.00 netns 15 root200000 S0.00.00:00.00 khungtaskd 16 root0 -20000 S0.00.00:00.00 writeback 17 root0 -20000 S0.00.00:00.00 kintegrityd 18 root0 -20000 S0.00.00:00.00 bioset 19 root0 -20000 S0.00.00:00.00 bioset# 按 shift + m:按照内存使用大小排序 # 按 1:列出所有核CPU的使用状态 # 按 q:退出

测试系统负载,参考命令:
{ yes > /dev/null & } && sleep 30 && ps -ef | grep yes | awk '{print $2}' | xargs kill

for i in $( seq 0 $(($(cat /proc/cpuinfo | grep processor | wc -l)-1)) ); do taskset -c $i yes > /dev/null & done && sleep 30 && ps -ef | grep yes | awk '{print $2}' | xargs kill

常用方式:
  • top -p 进程号:只观察一个进程的状态
$ top -p 732top - 22:35:00 up 42 days, 11:16, 28 users,load average: 0.00, 0.01, 0.05 Tasks:0 total,0 running,0 sleeping,0 stopped,0 zombie %Cpu(s):0.2 us,0.5 sy,0.0 ni, 99.3 id,0.0 wa,0.0 hi,0.0 si,0.0 st KiB Mem :3881920 total,702676 free,302076 used,2877168 buff/cache KiB Swap:0 total,0 free,0 used.1184568 avail MemPID USERPRNIVIRTRESSHR S%CPU %MEMTIME+ COMMAND

  • top -p 进程号 -d 间隔时间 -n 刷新次数
  • 其他:

  • -b:批处理模式
  • top -bn1:非动态打印系统资源的使用情况
关于内存
free:查看内存使用状况
[root@localhost ~]# free -m totalusedfreesharedbuff/cacheavailable # 内存总大小实际使用内存大小 空闲内存大小 共享内存缓冲/缓存可使用内存 Mem:2845211250681272488 Swap:307103071[root@localhost ~]# free -h# 更便于阅读 totalusedfreesharedbuff/cacheavailable Mem:2.8G211M2.4G8.5M127M2.4G Swap:3.0G0B3.0G

关于 IO
iostat(需要安装:yum install sysstat
  • -c:只看 CPU
  • -d:只看硬盘
[root@localhost ~]# iostat 1# 1秒刷新一次 Linux 3.10.0-1160.el7.x86_64 (localhost.localdomain)2020年12月10日_x86_64_(1 CPU)avg-cpu:%user%nice %system %iowait%steal%idle 0.260.000.320.050.0099.36Device:tpskB_read/skB_wrtn/skB_readkB_wrtn sda5.06181.5518.6424479325135 dm-03.43157.8717.1221286723087 dm-10.071.630.0022040

iftop:类似于top的实时流量监控工具(需要安装才能使用)

    推荐阅读