Linux 性能调优之硬件资源监控

2023年 11月 28日 28.8k 0

1写在前面

对每个人而言,真正的职责只有一个:找到自我。然后在心中坚守其一生,全心全意,永不停息。所有其它的路都是不完整的,是人的逃避方式,是对大众理想的懦弱回归,是随波逐流,是对内心的恐惧 ——赫尔曼·黑塞《德米安》

系统出现问题,或者存在异常的日志信息,某些进程运行缓慢,往往可能需要排除是否存在硬件问题,所以需要对硬件信息进行监控,查看是否存在异常信息

启动系统时会进行系统硬件检测,这些检测信息同时还会被写到 dmesg buffer 中, 在 Linux 系统中 ,dmesg buffer 记录下面一些信息:

  • 启动系统硬件检测信息
  • 驱动程序的信息
  • 查看系统警告或者错误

使用 dmesg 和 jounalctl -k选项 可以查看 dmesg buffer 的信息。

查看最后 10 行的数据信息,系统事件和操作的信息

┌──[root@liruilongs.github.io]-[~]
└─$dmesg  | tail -f -n 10
[56429.310740] br0: port 3(vnet4) entered blocking state
[56429.310741] br0: port 3(vnet4) entered forwarding state
[56431.360035] privbr0: port 3(vnet3) entered learning state
[56433.408995] privbr0: port 3(vnet3) entered forwarding state
[56433.409013] privbr0: topology change detected, propagating
[56440.853859] kvm [45569]: vcpu0, guest rIP: 0xffffffff9e060e38 disabled perfctr wrmsr: 0xc2 data 0xffff
[59043.415922] device-mapper: uevent: version 1.0.3
[59043.416104] device-mapper: ioctl: 4.39.0-ioctl (2018-04-03) initialised: dm-devel@redhat.com
[59176.644265] kvm [45401]: vcpu0, guest rIP: 0xffffffffa0260e38 disabled perfctr wrmsr: 0xc2 data 0xffff
[59463.089835] bash (2579): drop_caches: 3

dmesg -T 可以将时间转化为人类可读的形式

┌──[root@liruilongs.github.io]-[~]
└─$dmesg -T | tail -f -n 10
[Sun Sep 17 02:19:18 2023] br0: port 3(vnet4) entered blocking state
[Sun Sep 17 02:19:18 2023] br0: port 3(vnet4) entered forwarding state
[Sun Sep 17 02:19:20 2023] privbr0: port 3(vnet3) entered learning state
[Sun Sep 17 02:19:22 2023] privbr0: port 3(vnet3) entered forwarding state
[Sun Sep 17 02:19:22 2023] privbr0: topology change detected, propagating
[Sun Sep 17 02:19:29 2023] kvm [45569]: vcpu0, guest rIP: 0xffffffff9e060e38 disabled perfctr wrmsr: 0xc2 data 0xffff
[Sun Sep 17 03:02:52 2023] device-mapper: uevent: version 1.0.3
[Sun Sep 17 03:02:52 2023] device-mapper: ioctl: 4.39.0-ioctl (2018-04-03) initialised: dm-devel@redhat.com
[Sun Sep 17 03:05:05 2023] kvm [45401]: vcpu0, guest rIP: 0xffffffffa0260e38 disabled perfctr wrmsr: 0xc2 data 0xffff
[Sun Sep 17 03:09:52 2023] bash (2579): drop_caches: 3

查看前 10 行的数据信息.Linux内核启动过程的信息

┌──[root@liruilongs.github.io]-[~]
└─$dmesg -T | head -n 10
[Sat Sep 16 10:38:49 2023] Linux version 4.18.0-193.el8.x86_64 (mockbuild@x86-vm-08.build.eng.bos.redhat.com) (gcc version 8.3.1 20191121 (Red Hat 8.3.1-5) (GCC)) #1 SMP Fri Mar 27 14:35:58 UTC 2020
[Sat Sep 16 10:38:49 2023] Command line: BOOT_IMAGE=(hd0,msdos1)/vmlinuz-4.18.0-193.el8.x86_64 root=UUID=893bf4a5-f929-4a4f-9bb3-f1694d8ad757 ro resume=UUID=56504db0-34ca-458f-970b-1591a6af18bb rhgb quiet rd.shell=0
[Sat Sep 16 10:38:49 2023] x86/fpu: Supporting XSAVE feature 0x001: 'x87 floating point registers'
[Sat Sep 16 10:38:49 2023] x86/fpu: Supporting XSAVE feature 0x002: 'SSE registers'
[Sat Sep 16 10:38:49 2023] x86/fpu: Supporting XSAVE feature 0x004: 'AVX registers'
[Sat Sep 16 10:38:49 2023] x86/fpu: Supporting XSAVE feature 0x020: 'AVX-512 opmask'
[Sat Sep 16 10:38:49 2023] x86/fpu: Supporting XSAVE feature 0x040: 'AVX-512 Hi256'
[Sat Sep 16 10:38:49 2023] x86/fpu: Supporting XSAVE feature 0x080: 'AVX-512 ZMM_Hi256'
[Sat Sep 16 10:38:49 2023] x86/fpu: Supporting XSAVE feature 0x200: 'Protection Keys User registers'
[Sat Sep 16 10:38:49 2023] x86/fpu: xstate_offset[2]:  576, xstate_sizes[2]:  256
┌──[root@liruilongs.github.io]-[~]
└─$

通过  journalctl -k 命令来查看

┌──[root@liruilongs.github.io]-[~]
└─$ journalctl -k
-- Logs begin at 五 2023-11-10 10:32:56 CST, end at 五 2023-11-10 10:36:16 CST. --
11月 10 10:32:56 vms81.liruilongs.github.io kernel: Initializing cgroup subsys cpuset
11月 10 10:32:56 vms81.liruilongs.github.io kernel: Initializing cgroup subsys cpu
11月 10 10:32:56 vms81.liruilongs.github.io kernel: Initializing cgroup subsys cpuacct
11月 10 10:32:56 vms81.liruilongs.github.io kernel: Linux version 3.10.0-1160.76.1.el7.x86_64 (mockbuild@kbuilder.bsys.c
11月 10 10:32:56 vms81.liruilongs.github.io kernel: Command line: BOOT_IMAGE=/boot/vmlinuz-3.10.0-1160.76.1.el7.x86_64 r
......

在日常维护中,往往结合 grep 快速定位问题

┌──[root@liruilongs.github.io]-[~]
└─$ dmesg -T | grep -i error
[五 11月 10 10:32:57 2023] BERT: Boot Error Record Table support is disabled. Enable it by using bert_enable as kernel parameter.
┌──[root@liruilongs.github.io]-[~]
└─$ dmesg -T | grep -i warn
[五 11月 10 10:32:54 2023] Warning: Intel Processor - this hardware has not undergone upstream testing. Please consult http://wiki.centos.org/FAQ for more information
┌──[root@liruilongs.github.io]-[~]
└─$

2硬件信息查看

当前系统中一般会使用多个 CPU,每个 CPU 有多个核心,每个内核还可能具备超线程并具备不同级别的共享缓存

lscpu 命令可以查看系统的 CPU 的信息

Intel CPU 信息

┌──[root@liruilongs.github.io]-[~]
└─$lscpu
Architecture:        x86_64
CPU op-mode(s):      32-bit, 64-bit
Byte Order:          Little Endian
CPU(s):              8
On-line CPU(s) list: 0-7
Thread(s) per core:  1
Core(s) per socket:  4
Socket(s):           2
NUMA node(s):        1
Vendor ID:           GenuineIntel
CPU family:          6
Model:               140
Model name:          11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz
Stepping:            1
CPU MHz:             2419.226
BogoMIPS:            4838.45
Virtualization:      VT-x
Hypervisor vendor:   VMware
Virtualization type: full
L1d cache:           48K
L1i cache:           32K
L2 cache:            1280K
L3 cache:            8192K
NUMA node0 CPU(s):   0-7
Flags:               fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon rep_good nopl xtopology tsc_reliable nonstop_tsc cpuid pni pclmulqdq vmx ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch cpuid_fault invpcid_single ssbd ibrs ibpb stibp ibrs_enhanced tpr_shadow vnmi ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves arat avx512vbmi umip pku ospke avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg avx512_vpopcntdq rdpid movdiri movdir64b md_clear flush_l1d arch_capabilities

简单的输出信息说明

系统架构是 x86_64(64 位),支持 32 位和 64 位的 CPU 操作模式。字节顺序为小端(Little Endian)。系统有 8 个 CPU 核心,每个核心有 1 个线程。每个 CPU 插槽有 4 个核心,共有 2 个插槽。NUMA 节点数为 1。

以下是有关您的 CPU 的信息:

  • 厂商 ID:GenuineIntel
  • CPU 家族:6
  • 型号:140
  • 型号名称:11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz
  • 步进:1
  • CPU 频率:2419.226 MHz
  • BogoMIPS:4838.45
  • 支持虚拟化技术:VT-x
  • Hypervisor 厂商:VMware
  • 虚拟化类型:full
  • 关于 CPU 缓存的信息:
  • L1d 缓存:48K
  • L1i 缓存:32K
  • L2 缓存:1280K
  • L3 缓存:8192K
  • 系统具有许多 CPU 功能和特性,包括浮点运算单元(fpu)、虚拟化扩展(vmx)、超线程(ht)、AES 指令集(aes)、AVX 指令集(avx)等等。

服务器 CPU 信息查看

┌──[root@hp-ProLiant-SL270s-Gen8-SE]-[~]
└─$ lscpu
架构:                   x86_64
  CPU 运行模式:         32-bit, 64-bit
  Address sizes:         46 bits physical, 48 bits virtual
  字节序:               Little Endian
CPU:                     32
  在线 CPU 列表:        0-31
厂商 ID:                GenuineIntel
  型号名称:             Intel(R) Xeon(R) CPU E5-2670 0 @ 2.60GHz
    CPU 系列:           6
    型号:               45
    每个核的线程数:     2
    每个座的核数:       8
    座:                 2
    步进:               7
    CPU 最大 MHz:       3300.0000
    CPU 最小 MHz:       1200.0000
    BogoMIPS:           5187.49
    标记:               fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fx
                         sr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_go
                         od nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est
                         tm2 ssse3 cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx
                         lahf_lm epb pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid xsaveopt dtherm ida
                         arat pln pts md_clear flush_l1d
Virtualization features:
  虚拟化:               VT-x
Caches (sum of all):
  L1d:                   512 KiB (16 instances)
  L1i:                   512 KiB (16 instances)
  L2:                    4 MiB (16 instances)
  L3:                    40 MiB (2 instances)
NUMA:
  NUMA 节点:            2
  NUMA 节点0 CPU:       0-7,16-23
  NUMA 节点1 CPU:       8-15,24-31
Vulnerabilities:
  Itlb multihit:         KVM: Mitigation: VMX disabled
  L1tf:                  Mitigation; PTE Inversion; VMX conditional cache flushes, SMT vulnerable
  Mds:                   Mitigation; Clear CPU buffers; SMT vulnerable
  Meltdown:              Mitigation; PTI
  Mmio stale data:       Unknown: No mitigations
  Retbleed:              Not affected
  Spec store bypass:     Mitigation; Speculative Store Bypass disabled via prctl
  Spectre v1:            Mitigation; usercopy/swapgs barriers and __user pointer sanitization
  Spectre v2:            Mitigation; Retpolines, IBPB conditional, IBRS_FW, STIBP conditional, RSB filling, PBRSB-eIBRS
                         Not affected
  Srbds:                 Not affected
  Tsx async abort:       Not affected
┌──[root@hp-ProLiant-SL270s-Gen8-SE]-[~]
└─$

基本信息:

  • CPU: Intel Xeon E5-2670, Sandy Bridge-EP微架构,双芯片(Socket)每个Socket 8核心
  • 多线程支持:每个核心支持两个线程
  • 缓存结构:每个核心有512KB L1缓存,4MB L2缓存,两颗CPU共享40MB L3缓存
  • NUMA结构:有两个NUMA节点,第一个节点CPU为0-7,第二个为8-15
  • 虚拟化支持:支持Intel VT-x虚拟化技术
  • 性能信息:基准指标5187.49 Bogomips
  • 支持特性:SSE,AVX,虚拟化、数据本地性等
  • 漏洞修复:针对Meltdown、Spectre等已修复

AMD CPU 信息

┌──[root@liruilongs.github.io]-[~]
└─$ lscpu
Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                4
On-line CPU(s) list:   0-3
Thread(s) per core:    1
Core(s) per socket:    2
座:                 2
NUMA 节点:         1
厂商 ID:           AuthenticAMD
CPU 系列:          23
型号:              17
型号名称:        AMD Ryzen 7 2700U with Radeon Vega Mobile Gfx
步进:              0
CPU MHz:             2195.781
BogoMIPS:            4391.56
超管理器厂商:  VMware
虚拟化类型:     完全
L1d 缓存:          32K
L1i 缓存:          64K
L2 缓存:           512K
L3 缓存:           4096K
NUMA 节点0 CPU:    0-3
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 mmxext fxsr_opt pdpe1gb rdtscp lm constant_tsc art rep_good nopl tsc_reliable nonstop_tsc extd_apicid eagerfpu pni pclmulqdq ssse3 fma cx16 sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm cmp_legacy cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw fsgsbase bmi1 avx2 smep bmi2 rdseed adx smap clflushopt sha_ni xsaveopt xsavec arat overflow_recov succor
┌──[root@liruilongs.github.io]-[~]
└─$

dmidecode 可以查看 主板设备信息

┌──[root@hp-ProLiant-SL270s-Gen8-SE]-[~]
└─$ dmidecode | head -n 10
# dmidecode 3.3
Getting SMBIOS data from sysfs.
SMBIOS 2.8 present.
188 structures occupying 5969 bytes.
Table at 0xBFBD8000.

Handle 0x0000, DMI type 0, 24 bytes
BIOS Information
        Vendor: HP
        Version: P75
┌──[root@hp-ProLiant-SL270s-Gen8-SE]-[~]
└─$

查看 usb 设备信息,通过 -vv 可以查看详细信息

┌──[root@liruilongs.github.io]-[~]
└─$lsusb
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 003 Device 002: ID 0e0f:0003 VMware, Inc. Virtual Mouse
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 003: ID 0e0f:0002 VMware, Inc. Virtual USB Hub
Bus 002 Device 002: ID 0e0f:0008 VMware, Inc.
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub

lspci命令用于列出连接到 PCI 总线的设备信息,它可以显示计算机上安装的 PCI 设备的详细信息,包括网络适配器、显卡、声卡、存储控制器等。 -vv 选项可以查看详细的信息

┌──[root@liruilongs.github.io]-[~]
└─$lspci -vv
00:00.0 Host bridge: Intel Corporation 440BX/ZX/DX - 82443BX/ZX/DX Host bridge (rev 01)
Subsystem: VMware Virtual Machine Chipset
Control: I/O- Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B- DisINTx-
Status: Cap- 66MHz- UDF- FastB2B- ParErr- DEVSEL=medium >TAbort-

相关文章

服务器端口转发,带你了解服务器端口转发
服务器开放端口,服务器开放端口的步骤
产品推荐:7月受欢迎AI容器镜像来了,有Qwen系列大模型镜像
如何使用 WinGet 下载 Microsoft Store 应用
百度搜索:蓝易云 – 熟悉ubuntu apt-get命令详解
百度搜索:蓝易云 – 域名解析成功但ping不通解决方案

发布评论