【11.12】监控 linux 系统状态

本文详细介绍了Linux系统状态监控的常用命令,包括CPU、内存、磁盘、网络和进程的监控。例如,使用`top`命令动态查看系统状态,`free`命令查看内存使用,`iostat`监控磁盘,`netstat`检查网络连接,以及`ps`查看进程等。这些工具对于了解系统性能和诊断问题非常有用。
摘要由CSDN通过智能技术生成

5.1-5.9 监控linux系统状态

1、监控 CPU 的命令

  • w 查看系统负载
[root@alexis-01 ~]# w
 20:39:38 up 1 min,  1 user,  load average: 0.47, 0.29, 0.12
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
root     pts/0    192.168.194.1    20:39    2.00s  0.00s  0.00s w

1分钟内,5分钟内,15分钟内
负载值:平均时间内,有多少个活动的进程。数字越大越忙。
正在使用 CPU 或等待 CPU 都属于活动的进程,无论在排队还是正在使用都属于活动进程

  • uptime 查看系统负载
[root@alexis-01 ~]# uptime
 20:39:57 up 1 min,  1 user,  load average: 0.34, 0.27, 0.11
  • top 动态查看系统状态
    可以让进程按从高到低顺序自动排列,默认按 CPU 使用率排列,同样可以显示系统负载
[root@arslinux-01 ~]# top
top - 20:40:49 up 2 min,  1 user,  load average: 0.14, 0.23, 0.11
Tasks: 103 total,   1 running, 102 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0.3 us,  1.0 sy,  0.0 ni, 98.7 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem :   995896 total,   266560 free,   581216 used,   148120 buff/cache
KiB Swap:  4194300 total,  4194300 free,        0 used.   253124 avail Mem 

   PID USER      PR  NI    VIRT    RES    SHR S %CPU %MEM     TIME+ COMMAND                                                                                                                                                                                                  
    25 root      20   0       0      0      0 S  0.3  0.0   0:00.27 kworker/0:1                                                                                                                                                                                              
    32 root      39  19       0      0      0 S  0.3  0.0   0:00.07 khugepaged                                                                                                                                                                                               
  2903 root      20   0       0      0      0 S  0.3  0.0   0:00.04 xfsaild/sda3                                                                                                                                                                                             
  6152 root      20   0  301048   6488   5124 S  0.3  0.7   0:00.20 vmtoolsd                                                                                                                                                                                                 
     1 root      20   0  125308   3748   2564 S  0.0  0.4   0:01.08 systemd                                                                                                                                                                                                  
略

按 q 退出

CPU 使用率 = 100% - id值
RES 进程占用物理内存的大小

top 命令不仅要关注 Tasks 、%CPU 列,同样要关注下方 %CPU、%MEM、RES 列
– 每 3 秒刷新一次
– 按 M 键更改未按内存使用率大小排列
– 按数字 1 可以查看所有 CPU 的使用率详情(多核)

  • top -bn1 静态显示所有进程情况,也是按 CPU 百分比排序
[root@alexis-01 ~]# top -bn1
top - 20:42:28 up 4 min,  1 user,  load average: 0.11, 0.18, 0.10
Tasks: 103 total,   1 running, 102 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 :   995896 total,   261884 free,   585892 used,   148120 buff/cache
KiB Swap:  4194300 total,  4194300 free,        0 used.   248448 avail Mem 

   PID USER      PR  NI    VIRT    RES    SHR S %CPU %MEM     TIME+ COMMAND
     1 root      20   0  125308   3748   2564 S  0.0  0.4   0:01.08 systemd
     2 root      20   0       0      0      0 S  0.0  0.0   0:00.00 kthreadd
     3 root      20   0       0      0      0 S  0.0  0.0   0:00.11 ksoftirqd/0
     4 root      20   0       0      0      0 S  0.0  0.0   0:00.00 kworker/0:0
     5 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:00.02 kworker/u256: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:00.42 rcu_sched
    10 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 lru-add-drain

(内容过多不全显示)
静态显示进程信息方便与在脚本里使用

  • cat /proc/cpuinfo 查看机器有几个CPU
[root@alexis-01 ~]# cat /proc/cpuinfo 
processor	: 0
vendor_id	: GenuineIntel
cpu family	: 6
model		: 142
model name	: Intel(R) Core(TM) i5-8265U CPU @ 1.60GHz
stepping	: 11
microcode	: 0xa4
cpu MHz		: 1799.999
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	: 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 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 ssbd ibrs ibpb stibp fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid mpx rdseed adx smap clflushopt xsaveopt xsavec arat spec_ctrl intel_stibp flush_l1d arch_capabilities
bogomips	: 3599.99
clflush size	: 64
cache_alignment	: 64
address sizes	: 43 bits physical, 48 bits virtual
power management:
  • lscpu 查看CPU的信息
[root@alexis-01 ~]# lscpu
Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                1
On-line CPU(s) list:   0
Thread(s) per core:    1
Core(s) per socket:    1
座:                 1
NUMA 节点:         1
厂商 ID:           GenuineIntel
CPU 系列:          6
型号:              142
型号名称:        Intel(R) Core(TM) i5-8265U CPU @ 1.60GHz
步进:              11
CPU MHz:             1799.999
BogoMIPS:            3599.99
超管理器厂商:  VMware
虚拟化类型:     完全
L1d 缓存:          32K
L1i 缓存:          32K
L2 缓存:           256K
L3 缓存:           6144K
NUMA 节点0 CPU:    0
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 ssbd ibrs ibpb stibp fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid mpx rdseed adx smap clflushopt xsaveopt xsavec arat spec_ctrl intel_stibp flush_l1d arch_capabilities

2、监控内存的命令

  • free 查看内存和 swap 使用情况(默认以 kb 为单位)
[root@alexis-01 ~]# free
              total        used        free      shared  buff/cache   available
Mem:         995896      585696      261816        7860      148384      248512
Swap:       4194300           0     4194300
  • free -m 按 M 为单位查看系统内存相关信息
[root@alexis-01 ~]# free -m
              total        used        free      shared  buff/cache   available
Mem:            972         571         255           7         144         242
Swap:          4095           0        4095
  • free -h 自动以单位显示内存信息
[root@alexis-01 ~]# free -h
              total        used        free      shared  buff/cache   available
Mem:           972M        571M        255M        7.7M        144M        242M
Swap:          4.0G          0B        4.0G
  • free -b
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值