Centos7下CPU内存等资源监控

1.查看内存使用情况:

[root@takeout web-takeout]# free -m
              total        used        free      shared  buff/cache   available
Mem:           3788        1358        1096          17        1333        1886
Swap:          3967          17        3950
[root@takeout web-takeout]# 

  

2.详细列出的进程情况,重点关注第10列内存使用占比:

top - 15:36:09 up 8 days,  5:07,  2 users,  load average: 0.01, 0.02, 0.05
Tasks: 330 total,   1 running, 329 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0.3 us,  1.3 sy,  0.0 ni, 98.3 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem :  3879356 total,  1122336 free,  1391484 used,  1365536 buff/cache
KiB Swap:  4063228 total,  4045192 free,    18036 used.  1931104 avail Mem 

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND                                                                                               
22388 root      20   0  160080   2448   1532 R  11.8  0.1   0:00.03 top                                                                                                   
 7743 systemd+  20   0  343652  88800  13740 S   5.9  2.3 145:50.06 mongod                                                                                                
    1 root      20   0  191776   4560   2520 S   0.0  0.1   0:31.86 systemd                                                                                               
    2 root      20   0       0      0      0 S   0.0  0.0   0:00.19 kthreadd                                                                                              
    3 root      20   0       0      0      0 S   0.0  0.0   0:12.19 ksoftirqd/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:24.82 kworker/u32:0                                                                                         
    7 root      20   0       0      0      0 S   0.0  0.0   0:10.72 kworker/u33:0                                                                                         
    8 root      rt   0       0      0      0 S   0.0  0.0   0:00.40 migration/0                                                                                           
    9 root      20   0       0      0      0 S   0.0  0.0   0:00.00 rcu_bh                                                                                                
   10 root      20   0       0      0      0 S   0.0  0.0   4:56.04 rcu_sched                                                                                             
   11 root      rt   0       0      0      0 S   0.0  0.0   0:03.77 watchdog/0                                                                                            
   12 root      rt   0       0      0      0 S   0.0  0.0   0:03.86 watchdog/1                                                                                            
   13 root      rt   0       0      0      0 S   0.0  0.0   0:00.59 migration/1                                                                                           
   14 root      20   0       0      0      0 S   0.0  0.0   0:00.05 ksoftirqd/1                                                                                           
   16 root       0 -20       0      0      0 S   0.0  0.0   0:00.00 kworker/1:0H                                                                                          
   17 root      rt   0       0      0      0 S   0.0  0.0   0:03.87 watchdog/2                                                                                            
   18 root      rt   0       0      0      0 S   0.0  0.0   0:00.41 migration/2                                                                                           
   19 root      20   0       0      0      0 S   0.0  0.0   0:00.04 ksoftirqd/2                                                                                           
   21 root       0 -20       0      0      0 S   0.0  0.0   0:00.00 kworker/2:0H                                                                                          
   22 root      rt   0       0      0      0 S   0.0  0.0   0:03.91 watchdog/3                                                                                            
   23 root      rt   0       0      0      0 S   0.0  0.0   0:00.41 migration/3                                                                                           
   24 root      20   0       0      0      0 S   0.0  0.0   0:14.72 ksoftirqd/3                                                                                           
   26 root       0 -20       0      0      0 S   0.0  0.0   0:00.00 kworker/3:0H                                                                                          
   27 root      rt   0       0      0      0 S   0.0  0.0   0:03.87 watchdog/4                                                                                            
   28 root      rt   0       0      0      0 S   0.0  0.0   0:00.43 migration/4                                                                                           
   29 root      20   0       0      0      0 S   0.0  0.0   0:00.16 ksoftirqd/4    

  

3.查看消耗内存最多的前40个进程:

[root@takeout web-takeout]# ps auxw|head -1;ps auxw|sort -rn -k4|head -40
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root     29801  2.9 18.3 2821716 711956 ?      Ssl  10:58   8:17 java -Djava.security.egd=file:/dev/./urandom -jar /app.jar
systemd+  2919  0.1  4.9 1452544 191028 ?      Ssl  7月02  15:40 mysqld
systemd+  7743  1.2  2.2 343652 88800 ?        SLsl 7月02 145:50 mongod --auth --storageEngine wiredTiger
root      1524  0.8  1.4 1627344 54956 ?       Ssl  7月02  96:06 /usr/bin/dockerd
root      1534  0.2  0.4 1188184 16012 ?       Ssl  7月02  25:54 docker-containerd -l unix:///var/run/docker/libcontainerd/docker-containerd.sock --metrics-interval=0 --start-timeout 2m --state-dir /var/run/docker/libcontainerd/containerd --shim docker-containerd-shim --runtime docker-runc
root       607  0.0  0.3  45024 15048 ?        Ss   7月02   0:08 /usr/lib/systemd/systemd-journald
root      1122  0.0  0.3 562600 14716 ?        Ssl  7月02   2:29 /usr/bin/python -Es /usr/sbin/tuned -l -P
root       887  0.0  0.2 470312  9540 ?        Ssl  7月02   0:26 /usr/sbin/NetworkManager --no-daemon
root       861  0.0  0.2 220312 10996 ?        Ssl  7月02   0:52 /usr/sbin/rsyslogd -n
polkitd    851  0.0  0.2 536336 11584 ?        Ssl  7月02   0:06 /usr/lib/polkit-1/polkitd --no-debug
root       856  0.0  0.1 216988  4788 ?        Ss   7月02   0:00 /usr/bin/abrt-watch-log -F BUG: WARNING: at WARNING: CPU: INFO: possible recursive locking detected ernel BUG at list_del corruption list_add corruption do_IRQ: stack overflow: ear stack overflow (cur: eneral protection fault nable to handle kernel ouble fault: RTNL: assertion failed eek! page_mapcount(page) went negative! adness at NETDEV WATCHDOG ysctl table check failed : nobody cared IRQ handler type mismatch Machine Check Exception: Machine check events logged divide error: bounds: coprocessor segment overrun: invalid TSS: segment not present: invalid opcode: alignment check: stack segment: fpu exception: simd exception: iret exception: /var/log/messages -- /usr/bin/abrt-dump-oops -xtD
root       854  0.0  0.1 219484  4204 ?        Ss   7月02   0:00 /usr/sbin/abrtd -d -s
root      7725  0.2  0.1 347456  4076 ?        Sl   7月02  33:09 docker-containerd-shim cfb7edfcbd710751322362ea32dc3025a5f28818e608ea34ce897206937b1333 /var/run/docker/libcontainerd/cfb7edfcbd710751322362ea32dc3025a5f28818e608ea34ce897206937b1333 docker-runc
root      7719  0.0  0.1 911148  6888 ?        Sl   7月02   1:34 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 9999 -container-ip 172.17.0.4 -container-port 27017
root      3165  0.0  0.1 414656  4056 ?        Sl   7月02   0:01 docker-containerd-shim f532147cc4de43223fe2bf9641b1d84147f0f6a297c3d1792ccc5bd0070eb12e /var/run/docker/libcontainerd/f532147cc4de43223fe2bf9641b1d84147f0f6a297c3d1792ccc5bd0070eb12e docker-runc
root      3076  0.0  0.1  36992  7608 ?        Ssl  7月02   6:28 /usr/bin/redis-server *:6379
root     29784  0.0  0.1 412992  3996 ?        Sl   10:58   0:00 docker-containerd-shim aa2d5e47a9b9a9624966fd3839128e78eec8f155931c3074439e2d61cd50a044 /var/run/docker/libcontainerd/aa2d5e47a9b9a9624966fd3839128e78eec8f155931c3074439e2d61cd50a044 docker-runc
root     18707  0.0  0.1 117264  4020 pts/1    Ss   09:13   0:00 -bash
root     18659  0.0  0.1 117240  4004 pts/0    Ss+  09:12   0:00 -bash
root     18656  0.0  0.1 150376  5828 ?        Ss   09:12   0:00 sshd: root@pts/0,pts/1
root      1120  0.0  0.1 105996  4112 ?        Ss   7月02   0:00 /usr/sbin/sshd -D
root     11101  0.0  0.1 150376  5892 ?        Ss   13:31   0:00 sshd: root@notty
root         1  0.0  0.1 191776  4560 ?        Ss   7月02   0:31 /usr/lib/systemd/systemd --switched-root --system --deserialize 21
postfix  20269  0.0  0.1  91732  4036 ?        S    15:15   0:00 pickup -l -t unix -u
postfix   1326  0.0  0.1  91800  4036 ?        S    7月02   0:01 qmgr -l -t unix -u
zabbix   31681  0.0  0.0  83944  2192 ?        S    11:18   0:01 /usr/sbin/zabbix_agentd: active checks #1 [idle 1 sec]
zabbix   31680  0.0  0.0  83936  2436 ?        S    11:18   0:09 /usr/sbin/zabbix_agentd: listener #3 [waiting for connection]
zabbix   31679  0.0  0.0  83936  2440 ?        S    11:18   0:08 /usr/sbin/zabbix_agentd: listener #2 [waiting for connection]
zabbix   31678  0.0  0.0  83936  2440 ?        S    11:18   0:08 /usr/sbin/zabbix_agentd: listener #1 [waiting for connection]
zabbix   31677  0.0  0.0  83812  2424 ?        S    11:18   0:08 /usr/sbin/zabbix_agentd: collector [idle 1 sec]
zabbix   31675  0.0  0.0  83812  1260 ?        S    11:18   0:00 /usr/sbin/zabbix_agentd -c /etc/zabbix/zabbix_agentd.conf
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root        99  0.0  0.0      0     0 ?        S<   7月02   0:00 [bioset]
root        98  0.0  0.0      0     0 ?        S<   7月02   0:00 [kintegrityd]
root        97  0.0  0.0      0     0 ?        S<   7月02   0:00 [writeback]
root        96  0.0  0.0      0     0 ?        S    7月02   0:02 [khungtaskd]
root      9573  0.0  0.0      0     0 ?        S    7月07   0:02 [kworker/7:2]
root        95  0.0  0.0      0     0 ?        S<   7月02   0:00 [netns]
root        94  0.0  0.0      0     0 ?        S    7月02   0:00 [kdevtmpfs]
root       904  0.0  0.0 110044   820 tty1     Ss+  7月02   0:00 /sbin/agetty --noclear tty1 linux
[root@takeout web-takeout]# 

  

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 为了提升 Centos7CPU 利用率,我们可以使用一些脚本来优化系统性能。这些脚本能够在提高 CPU 利用率的同时还能保证系统的稳定性和安全性。 首先,我们可以使用 CPU 核心调优脚本来优化 CPU 利用率,提高系统性能。这个脚本可以通过调整 CPU 的核心数来优化系统的性能。我们可以设置适当的核心数,从而提高 CPU 利用率。这个脚本需要对系统的设置进行修改,所以在使用前请备份系统文件。 其次,我们可以使用 I/O 优化脚本来提高系统的 I/O 性能,从而提高 CPU 利用率。这个脚本可以通过调整读写缓存来优化文件 IO,加速系统和应用的读写速度,从而改善系统性能。这个脚本也需要进行系统设置的修改,所以在使用前请备份系统文件。 最后,我们可以使用内存优化脚本来提高系统的内存利用率,从而提高 CPU 利用率。这个脚本可以通过调整系统的内存分配策略,从而让系统能够更好地管理内存资源,提高系统的性能。这个脚本也需要对系统的设置进行修改,所以在使用前请备份系统文件。 总之,采用上述的脚本可以提高 Centos7CPU 利用率,同时提升系统性能和稳定性。使用前请加倍小心,以免修改系统设置导致系统崩溃或出现其他问题。 ### 回答2: CentOS 7 提升 CPU 利用率脚本可以有效地提高系统的性能利用率,从而提升系统的运行效率和性能稳定性。下面是一个简单的脚本示例: #!/bin/bash # Set CPU scaling governor to "performance" mode for CPUFREQ in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor; do [ -f $CPUFREQ ] || continue echo performance > $CPUFREQ done # Disable frequency scaling for CPUFREQ in /sys/devices/system/cpu/cpu*/cpufreq/scaling_enabled; do [ -f $CPUFREQ ] || continue echo 0 > $CPUFREQ done # Enable IRQbalance systemctl enable irqbalance systemctl start irqbalance # Set CPU affinity for running processes for PROC in $(ps -Ao pid --no-headers); do taskset -p -c 0 $PROC > /dev/null 2>&1 done # Set kernel parameters to improve performance echo 'vm.swappiness = 10' >> /etc/sysctl.conf echo 'vm.vfs_cache_pressure = 50' >> /etc/sysctl.conf sysctl -p # Remove unnecessary services and packages yum remove -y abrt-plugin-bugzilla abrt-plugin-kerneloops abrt-plugin-logger abrt-plugin-mailx abrt-plugin-sos abrt abrtd acpid atd autofs avahi-daemon avahi-autoipd coolkey cpuspeed cups dhcpv6-client dhclient dhclient-script eject firewalld firstboot gdm gdm-plymouth gdm-user-switch-applet gnome-session-xsession irqbalance kdump kexec-tools kpartx kudzu lvm2-cluster lvm2 lvm2-lockd lvm2-monitor lvm2-sysmd mcstrans mdmonitor microcode_ctl mlocate net-snmp net-snmp-utils nfs-utils nscd ntp ntpdate oddjob oddjob-mkhomedir open-vm-tools openssh-clients openssh-server openssl-devel plymouth-core-libs plymouth-scripts pm-utils portreserve prelink rng-tools rsyslog smartmontools smartmontools-libs spice-vdagent sysstat system-config-firewall-tui system-config-network-tui upower usbutils util-linux-ng yum-langpacks yum-plugin-fastestmirror yum-plugin-remove-with-leaves yum-utils 这个脚本分为几个部分。首先是将 CPU 的 scaling governor 设置为 performance 模式,关闭 CPU 的 frequency scaling,启用 IRQbalance,并为运行的进程设置 CPU 亲和性。随后是设置内核参数以提高性能,最后是删除一些不必要的服务和包。 通过使用这个脚本,可以有效地提高 CentOS 7 系统的性能和稳定性,提高 CPU 利用率。需要注意的是,这个脚本可能会导致一些不必要的安全隐患,所以在使用前要谨慎评估其影响。 ### 回答3: 在 Centos7 上提升 CPU 利用率可以通过脚本实现。其中,最关键的是使用了 stress 工具,它可以模拟 CPU 的高负载状态,来测试系统的稳定性和性能。 以下是一个简单的脚本示例: ```bash #!/bin/bash # 设置压力测试时长和 CPU 数量 TIME=60 CPU_COUNT=$(grep -c ^processor /proc/cpuinfo) # 安装 stress 工具 yum install -y stress # 创建负载测试循环 while true do for i in $(seq $CPU_COUNT) do # 在每个 CPU 上使用 stress 工具 stress --cpu 1 --timeout $TIME & done # 等待压力测试完成 sleep $TIME done ``` 这个脚本会在后台执行一个无限循环,每次都会在每个 CPU 上启动一个 stress 进程,并且等待压力测试时长。通过这种方式,可以有效地提高 CPU 利用率。 在使用这个脚本时需要注意,它将会给系统带来相当大的负载,可能会导致其他应用程序的性能下降或者系统稳定性的问题。建议在测试环境中运行,并且对系统进行足够的测试和监控

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值