系统基础监控命令实践

CPU 性能指标实践

安装实验工具

步骤 1 安装系统压测工具 stress

[root@localhost ~]# curl -o /etc/yum.repos.d/epel-OpenEuler.repo https://down.whsir.com/downloads/epel-OpenEuler.repo
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  1413  100  1413    0     0   3578      0 --:--:-- --:--:-- --:--:--  3586
[root@localhost ~]# dnf -y install stress

步骤 2 安装线程压测工具 sysbench

[root@localhost ~]# dnf -y install sysbench

步骤 3 安装系统性能工具包 sysstat

[root@localhost ~]# dnf -y install sysstat

查看 CPU 使用率

步骤 1 CPU 性能压测

[root@localhost ~]# stress -c 2 -i --timeout 300s &

步骤 2 查看系统 CPU 使用率

[root@localhost ~]# mpstat -P ALL 5 2
Linux 5.10.0-182.0.0.95.oe2203sp3.x86_64 (localhost.localdomain) 	03/18/2024 	_x86_64_	(2 CPU)

11:02:10 AM  CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest  %gnice   %idle
11:02:15 AM  all    0.00    0.00    0.00    0.00    0.10    0.00    0.00    0.00    0.00   99.90
11:02:15 AM    0    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00
11:02:15 AM    1    0.00    0.00    0.00    0.00    0.20    0.00    0.00    0.00    0.00   99.80

11:02:15 AM  CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest  %gnice   %idle
11:02:20 AM  all    0.00    0.00    0.00    0.00    0.10    0.10    0.00    0.00    0.00   99.80
11:02:20 AM    0    0.00    0.00    0.00    0.00    0.00    0.20    0.00    0.00    0.00   99.80
11:02:20 AM    1    0.00    0.00    0.00    0.00    0.20    0.00    0.00    0.00    0.00   99.80

Average:     CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest  %gnice   %idle
Average:     all    0.00    0.00    0.00    0.00    0.10    0.05    0.00    0.00    0.00   99.85
Average:       0    0.00    0.00    0.00    0.00    0.00    0.10    0.00    0.00    0.00   99.90
Average:       1    0.00    0.00    0.00    0.00    0.20    0.00    0.00    0.00    0.00   99.80

 步骤 3 查看进程 CPU 使用率

[root@localhost ~]# ps aux --sort -%cpu
USER         PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         790  1.0  0.4  89592  5976 ?        Ssl  10:52   0:07 /sbin/rngd -f
root           1  0.1  1.2 105980 18296 ?        Ss   10:52   0:01 /usr/lib/system
root          34  0.0  0.0      0     0 ?        I    10:52   0:00 [kworker/1:1-ev
root         817  0.0  2.8 146352 41616 ?        Ssl  10:52   0:00 /usr/bin/python
root         637  0.0  0.0      0     0 ?        I    10:52   0:00 [kworker/0:3-ev
root         845  0.0  2.0 355076 30012 ?        Ssl  10:52   0:00 /usr/bin/python
root          16  0.0  0.0      0     0 ?        S    10:52   0:00 [migration/1]
root        1674  0.0  0.0      0     0 ?        I    11:00   0:00 [kworker/1:2-pm
root        1519  0.0  0.3  15272  4988 ?        S    10:53   0:00 sshd: root@pts/
root         830  0.0  1.2 270580 18552 ?        Ssl  10:52   0:00 /usr/sbin/Netwo
root         671  0.0  0.7  30032 10796 ?        Ss   10:52   0:00 /usr/lib/system
root        1030  0.0  0.4 159264  7248 ?        Ssl  10:52   0:00 /usr/sbin/rsysl
root         533  0.0  0.0      0     0 ?        S    10:52   0:00 [jbd2/dm-0-8]
root          12  0.0  0.0      0     0 ?        I    10:52   0:00 [rcu_sched]
dbus         785  0.0  0.3   7736  4768 ?        Ss   10:52   0:00 /usr/bin/dbus-d
root         645  0.0  0.6  17984  8920 ?        Ss   10:52   0:00 /usr/lib/system
root          11  0.0  0.0      0     0 ?        S    10:52   0:00 [ksoftirqd/0]
root         793  0.0  0.6  16148  9316 ?        Ss   10:52   0:00 /usr/lib/system
root         435  0.0  0.0      0     0 ?        I    10:52   0:00 [kworker/u256:5
root         428  0.0  0.0      0     0 ?        I    10:52   0:00 [kworker/u256:3
root        1520  0.0  0.2  23088  4172 pts/0    Ss   10:53   0:00 -bash
root         794  0.0  0.1  79356  1728 ?        Ssl  10:52   0:00 /usr/sbin/irqba
root         242  0.0  0.0      0     0 ?        I    10:52   0:00 [kworker/1:4-cg
root          32  0.0  0.0      0     0 ?        SN   10:52   0:00 [khugepaged]
root          17  0.0  0.0      0     0 ?        S    10:52   0:00 [ksoftirqd/1]
root           5  0.0  0.0      0     0 ?        I    10:52   0:00 [kworker/0:0-at
root        1515  0.0  0.5  15272  8400 ?        Ss   10:53   0:00 sshd: root [pri
root         853  0.0  0.2  23296  3440 ?        Ss   10:52   0:00 /usr/sbin/crond
root         854  0.0  0.3   9988  5312 ?        Ss   10:52   0:00 login -- root
chrony       802  0.0  0.2  84428  3336 ?        S    10:52   0:00 /usr/sbin/chron
polkitd      788  0.0  0.5 234636  8540 ?        Ssl  10:52   0:00 /usr/lib/polkit
root         728  0.0  0.0      0     0 ?        S    10:52   0:00 [irq/16-vmwgfx]
root         416  0.0  0.0      0     0 ?        S    10:52   0:00 [scsi_eh_0]
root           2  0.0  0.0      0     0 ?        S    10:52   0:00 [kthreadd]
root           3  0.0  0.0      0     0 ?        I<   10:52   0:00 [rcu_gp]
root           4  0.0  0.0      0     0 ?        I<   10:52   0:00 [rcu_par_gp]
root           6  0.0  0.0      0     0 ?        I<   10:52   0:00 [kworker/0:0H-e
root           8  0.0  0.0      0     0 ?        I<   10:52   0:00 [mm_percpu_wq]
root           9  0.0  0.0      0     0 ?        S    10:52   0:00 [rcu_tasks_rude
root          10  0.0  0.0      0     0 ?        S    10:52   0:00 [rcu_tasks_trac
root          13  0.0  0.0      0     0 ?        S    10:52   0:00 [migration/0]
root          14  0.0  0.0      0     0 ?        S    10:52   0:00 [cpuhp/0]
root          15  0.0  0.0      0     0 ?        S    10:52   0:00 [cpuhp/1]
root          19  0.0  0.0      0     0 ?        I<   10:52   0:00 [kworker/1:0H-e
root          22  0.0  0.0      0     0 ?        S    10:52   0:00 [kdevtmpfs]
root          23  0.0  0.0      0     0 ?        I<   10:52   0:00 [netns]
root          24  0.0  0.0      0     0 ?        S    10:52   0:00 [kauditd]
root          27  0.0  0.0      0     0 ?        S    10:52   0:00 [khungtaskd]
root          28  0.0  0.0      0     0 ?        S    10:52   0:00 [oom_reaper]
root          29  0.0  0.0      0     0 ?        I<   10:52   0:00 [writeback]
root          30  0.0  0.0      0     0 ?        S    10:52   0:00 [kcompactd0]
root          31  0.0  0.0      0     0 ?        SN   10:52   0:00 [ksmd]
root          49  0.0  0.0      0     0 ?        I<   10:52   0:00 [cryptd]
root          94  0.0  0.0      0     0 ?        I<   10:52   0:00 [kintegrityd]
root          95  0.0  0.0      0     0 ?        I<   10:52   0:00 [kblockd]
root          96  0.0  0.0      0     0 ?        I<   10:52   0:00 [blkcg_punt_bio
root          97  0.0  0.0      0     0 ?        I<   10:52   0:00 [tpm_dev_wq]
root          98  0.0  0.0      0     0 ?        I<   10:52   0:00 [md]
root          99  0.0  0.0      0     0 ?        I<   10:52   0:00 [edac-poller]
root         100  0.0  0.0      0     0 ?        S    10:52   0:00 [watchdogd]
root         101  0.0  0.0      0     0 ?        I<   10:52   0:00 [kworker/0:1H-k
root         111  0.0  0.0      0     0 ?        S    10:52   0:00 [kswapd0]
root         113  0.0  0.0      0     0 ?        I<   10:52   0:00 [kthrotld]
root         114  0.0  0.0      0     0 ?        S    10:52   0:00 [irq/24-pciehp]
root         115  0.0  0.0      0     0 ?        S    10:52   0:00 [irq/25-pciehp]
root         116  0.0  0.0      0     0 ?        S    10:52   0:00 [irq/26-pciehp]
root         117  0.0  0.0      0     0 ?        S    10:52   0:00 [irq/27-pciehp]
root         118  0.0  0.0      0     0 ?        S    10:52   0:00 [irq/28-pciehp]
root         119  0.0  0.0      0     0 ?        S    10:52   0:00 [irq/29-pciehp]
root         120  0.0  0.0      0     0 ?        S    10:52   0:00 [irq/30-pciehp]
root         121  0.0  0.0      0     0 ?        S    10:52   0:00 [irq/31-pciehp]
root         122  0.0  0.0      0     0 ?        S    10:52   0:00 [irq/32-pciehp]
root         123  0.0  0.0      0     0 ?        S    10:52   0:00 [irq/33-pciehp]
root         124  0.0  0.0      0     0 ?        S    10:52   0:00 [irq/34-pciehp]
root         125  0.0  0.0      0     0 ?        S    10:52   0:00 [irq/35-pciehp]
root         126  0.0  0.0      0     0 ?        S    10:52   0:00 [irq/36-pciehp]
root         127  0.0  0.0      0     0 ?        S    10:52   0:00 [irq/37-pciehp]
root         128  0.0  0.0      0     0 ?        S    10:52   0:00 [irq/38-pciehp]
root         129  0.0  0.0      0     0 ?        S    10:52   0:00 [irq/39-pciehp]
root         130  0.0  0.0      0     0 ?        S    10:52   0:00 [irq/40-pciehp]
root         131  0.0  0.0      0     0 ?        S    10:52   0:00 [irq/41-pciehp]
root         132  0.0  0.0      0     0 ?        S    10:52   0:00 [irq/42-pciehp]
root         133  0.0  0.0      0     0 ?        S    10:52   0:00 [irq/43-pciehp]
root         134  0.0  0.0      0     0 ?        S    10:52   0:00 [irq/44-pciehp]
root         135  0.0  0.0      0     0 ?        S    10:52   0:00 [irq/45-pciehp]
root         136  0.0  0.0      0     0 ?        S    10:52   0:00 [irq/46-pciehp]
root         137  0.0  0.0      0     0 ?        S    10:52   0:00 [irq/47-pciehp]
root         138  0.0  0.0      0     0 ?        S    10:52   0:00 [irq/48-pciehp]
root         139  0.0  0.0      0     0 ?        S    10:52   0:00 [irq/49-pciehp]
root         140  0.0  0.0      0     0 ?        S    10:52   0:00 [irq/50-pciehp]
root         141  0.0  0.0      0     0 ?        S    10:52   0:00 [irq/51-pciehp]
root         142  0.0  0.0      0     0 ?        S    10:52   0:00 [irq/52-pciehp]
root         143  0.0  0.0      0     0 ?        S    10:52   0:00 [irq/53-pciehp]
root         144  0.0  0.0      0     0 ?        S    10:52   0:00 [irq/54-pciehp]
root         145  0.0  0.0      0     0 ?        S    10:52   0:00 [irq/55-pciehp]
root         146  0.0  0.0      0     0 ?        I<   10:52   0:00 [acpi_thermal_p
root         147  0.0  0.0      0     0 ?        I<   10:52   0:00 [kmpath_rdacd]
root         148  0.0  0.0      0     0 ?        I<   10:52   0:00 [kaluad]
root         150  0.0  0.0      0     0 ?        I<   10:52   0:00 [ipv6_addrconf]
root         151  0.0  0.0      0     0 ?        I<   10:52   0:00 [kworker/1:1H-k
root         152  0.0  0.0      0     0 ?        I<   10:52   0:00 [kstrp]
root         196  0.0  0.0      0     0 ?        I<   10:52   0:00 [kworker/u257:0
root         411  0.0  0.0      0     0 ?        I<   10:52   0:00 [ata_sff]
root         412  0.0  0.0      0     0 ?        I<   10:52   0:00 [nvme-wq]
root         417  0.0  0.0      0     0 ?        I<   10:52   0:00 [nvme-reset-wq]
root         419  0.0  0.0      0     0 ?        I<   10:52   0:00 [scsi_tmf_0]
root         420  0.0  0.0      0     0 ?        I<   10:52   0:00 [nvme-delete-wq
root         424  0.0  0.0      0     0 ?        S    10:52   0:00 [scsi_eh_1]
root         427  0.0  0.0      0     0 ?        I<   10:52   0:00 [scsi_tmf_1]
root         505  0.0  0.0      0     0 ?        I<   10:52   0:00 [kdmflush]
root         512  0.0  0.0      0     0 ?        I<   10:52   0:00 [kdmflush]
root         534  0.0  0.0      0     0 ?        I<   10:52   0:00 [ext4-rsv-conve
root         733  0.0  0.0      0     0 ?        I<   10:52   0:00 [ttm_swap]
root         734  0.0  0.0      0     0 ?        S    10:52   0:00 [card0-crtc0]
root         736  0.0  0.0      0     0 ?        S    10:52   0:00 [card0-crtc1]
root         739  0.0  0.0      0     0 ?        S    10:52   0:00 [card0-crtc2]
root         740  0.0  0.0      0     0 ?        S    10:52   0:00 [card0-crtc3]
root         741  0.0  0.0      0     0 ?        S    10:52   0:00 [card0-crtc4]
root         742  0.0  0.0      0     0 ?        S    10:52   0:00 [card0-crtc5]
root         743  0.0  0.0      0     0 ?        S    10:52   0:00 [card0-crtc6]
root         744  0.0  0.0      0     0 ?        S    10:52   0:00 [card0-crtc7]
root         746  0.0  0.0      0     0 ?        S    10:52   0:00 [jbd2/nvme0n1p1
root         748  0.0  0.0      0     0 ?        I<   10:52   0:00 [ext4-rsv-conve
root         760  0.0  0.0      0     0 ?        I<   10:52   0:00 [kworker/u257:1
root         767  0.0  0.1  17728  2160 ?        S<sl 10:52   0:00 /sbin/auditd
root         799  0.0  0.2  10664  3844 ?        Ss   10:52   0:00 /usr/sbin/resto
root         842  0.0  0.4  13936  6756 ?        Ss   10:52   0:00 sshd: /usr/sbin
root        1444  0.0  0.2  22956  4096 tty1     Ss+  10:53   0:00 -bash
root        1622  0.0  0.0      0     0 ?        I    10:58   0:00 [kworker/1:0-cg
root        1689  0.0  0.1  22332  1880 ?        Ss   11:01   0:00 /usr/sbin/anacr
root        1694  0.0  0.0      0     0 ?        I    11:01   0:00 [kworker/0:1-at
root        1697  0.0  0.3  26112  4904 pts/0    R+   11:03   0:00 ps aux --sort -

 步骤 4 查看系统平均负载

[root@localhost ~]# uptime
 11:04:03 up 11 min,  2 users,  load average: 0.00, 0.05, 0.05

 查看上下文切换

步骤 1 上下文切换压测

[root@localhost ~]# sysbench --threads=4 --time=300 threads run &

步骤 2 查看系统上下文切换

[root@localhost ~]# vmstat 3 5
procs -----------memory---------- ---swap-- -----io---- -system-- -------cpu-------
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st gu
 2  0  63232 1127892   6920 177656   73   74   173   231  310  152 20  1 79  0  0  0
 2  0  63232 1127884   6920 177712    0    0     0     0   83  163  0  0 100  0  0  0

步骤 3 查看线程上下文切换

[root@localhost ~]# pidstat -w 5 2 -t | grep sysbench

内存性能指标实践

创建交换分区

步骤 1 生成 2G 大小的数据文件

[root@localhost ~]# dd if=/dev/zero of=/mnt/swap bs=1M count=248
248+0 records in
248+0 records out
260046848 bytes (260 MB, 248 MiB) copied, 0.354314 s, 734 MB/s

步骤 2 格式化文件类型并查看

[root@localhost ~]# mkswap /mnt/swap
mkswap: /mnt/swap: insecure permissions 0644, fix with: chmod 0600 /mnt/swap
Setting up swapspace version 1, size = 248 MiB (260042752 bytes)
no label, UUID=88b25dad-d9b0-4f90-9af9-a14e22bd3482

步骤 3 修改分区文件权限并激活

[root@localhost ~]# chmod 0600 /mnt/swap
[root@localhost ~]# swapon /mnt/swap

步骤 4 查看交换分区容量

[root@localhost ~]# swapon -s
Filename				Type		Size		Used	 Priority
/dev/dm-1                               partition	2097148		0	 -2
/mnt/swap                               file		253948		0	 -3

查看系统内存

步骤 1 物理内存性能压测

[root@localhost ~]# stress --vm 2 --vm-bytes 300M --vm-keep --timeout 300s &
[3] 1719
[root@localhost ~]# stress: info: [1719] dispatching hogs: 0 cpu, 0 io, 2 vm, 0 hdd

步骤 2 查看物理内存

[root@localhost ~]# free -h
               total        used        free      shared  buff/cache   available
Mem:           1.4Gi       1.4Gi        60Mi       2.1Mi        55Mi        15Mi
Swap:          2.2Gi       130Mi       2.1Gi

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

元气满满的热码式

感谢您的支持!我会继续努力发布

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值