深度解析:Linux服务器性能监控与优化指南 —— 从CPU、内存到网络的全面诊断与调优策略

服务器信息查询

连接信息

#当前连接的信息
[root@testos:/root]$ w
 18:45:44 up 2 days, 11:38,  1 user,  load average: 0.01, 0.02, 0.05
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
root     pts/0    192.168.1.238    Thu07    0.00s  0.46s  0.00s w


#历史连接信息
[root@testos:/root]$ last
root     pts/0        192.168.1.238    Thu Mar 21 07:08   still logged in
reboot   system boot  3.10.0-957.el7.x Thu Mar 21 07:07 - 18:46 (2+11:38)
root     pts/4        192.168.1.229    Sun Jan 14 14:22 - down   (00:11)
root     pts/3        192.168.1.229    Sun Jan 14 14:16 - down   (00:17)
root     pts/2        192.168.1.229    Sun Jan 14 14:07 - down   (00:26)
root     pts/1        192.168.1.229    Sun Jan 14 13:48 - down   (00:46)
root     pts/0        192.168.1.229    Sun Jan 14 13:45 - down   (00:48)
reboot   system boot  3.10.0-957.el7.x Sun Jan 14 13:45 - 14:34  (00:48)
root     pts/1        yk-server-128    Sun Jan 14 13:31 - down   (00:13)
root     pts/0        yk-server-128    Sun Jan 14 13:30 - down   (00:14)
reboot   system boot  3.10.0-957.el7.x Sun Jan 14 13:30 - 13:45  (00:14)
root     pts/0        192.168.1.228    Thu Dec  2 22:58 - crash (772+14:31)
reboot   system boot  3.10.0-957.el7.x Thu Dec  2 22:57 - 13:45 (772+14:47)

wtmp begins Thu Dec  2 22:57:32 2021
[root@testos:/root]$

32位还是64位

[root@Centos7 ~]# getconf LONG_BIT
64

数据块大小

[root@Centos7 ~]# getconf PAGESIZE
4096

启动时间和运行时间

#服务器启动时间
[root@testos:/root]$ who -b
         system boot  2024-03-12 19:54
#运行时间
[root@testos:/root]$ uptime
 17:56:30 up 2 days, 10:48,  1 user,  load average: 0.01, 0.04, 0.05

CPU

查看CPU型号

[root@testos:/root]$ dmesg |grep -i xeon
[    2.020769] smpboot: CPU0: Intel(R) Xeon(R) CPU E5-2680 v2 @ 2.80GHz (fam: 06, model: 3e, stepping: 04)

cpu核心数

#物理个数
[root@testos:/root]$ cat /proc/cpuinfo|grep 'physical id'|uniq|wc -l
2
#每个物理CPU核心数
[root@testos:/root]$ cat /proc/cpuinfo|grep 'cores'|uniq
cpu cores       : 2
#逻辑个数(没开超线程的情况下,此项等于 物理个数*核心数)
[root@testos:/root]$ cat /proc/cpuinfo|grep 'processor'|wc -l
4

#lscpu命令可以一次性查全
[root@testos:/root]$ lscpu|egrep "^CPU\(s\)|Thread\(s\) per core|Core\(s\) per socket|Socket\(s\)"
CPU(s):                4                   #总逻辑数
Thread(s) per core:    1                   #每个核心的线程数,如果开启超线程这里的数值会大于1
Core(s) per socket:    2                   #单个物理CPU的核心数
Socket(s):             2                   #物理CPU个数
[root@testos:/root]$

查看CPU的物理信息,如下有两个物理CPU

[root@testLinux ~]# cat /proc/cpuinfo |grep 'physical id'
physical id     : 0
physical id     : 0
physical id     : 1
physical id     : 1
[root@testLinux ~]# cat /proc/cpuinfo |grep 'physical id'|uniq
physical id     : 0
physical id     : 1
[root@testLinux ~]#

查看物理CPU的核数,如下每个物理CPU有两个核,所以可以理解为4核CPU(2*2)

[root@testLinux ~]# cat /proc/cpuinfo|grep 'cpu cores'
cpu cores       : 2
cpu cores       : 2
cpu cores       : 2
cpu cores       : 2

也可以通过top命令查看

#top第3行中的Cpu(s)是总的显示
%Cpu(s):  0.0 us,  1.5 sy,  0.0 ni, 97.0 id,  0.0 wa,  0.0 hi,  1.5 si,  0.0 st
#查看单个cpu的情况 top + 1,如下可以看出有四个cpu
%Cpu0  :  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu1  :  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu2  :  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu3  :  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st

内存信息

1、确定内存大小,以及开始分配情况

[root@testos:/root]$ dmesg|grep -in memory|grep available
416:[    0.000000] Memory: 4974252k/9437184k available (7664k kernel code, 1049164k absent, 419476k reserved, 6055k data, 1876k init)

2、系统启动之后查看内存使用情况

[root@testos:/root]$ dmidecode -t 17|head -20
# dmidecode 3.1
Getting SMBIOS data from sysfs.
SMBIOS 2.7 present.

Handle 0x01A3, DMI type 17, 34 bytes
Memory Device
        Array Handle: 0x01A2
        Error Information Handle: No Error
        Total Width: 32 bits
        Data Width: 32 bits
        Size: 8192 MB
        Form Factor: DIMM
        Set: None
        Locator: RAM slot #0
        Bank Locator: RAM slot #0
        Type: DRAM
        Type Detail: EDO
        Speed: Unknown
        Manufacturer: Not Specified
        Serial Number: Not Specified

3、free工具

free工具从 /proc/meminfo 文件中检索到系统运行中的内存信息

[root@testos:/root]$ free -h
              total        used        free      shared  buff/cache   available
Mem:           7.6G        256M        5.4G        1.3G        1.9G        5.9G
Swap:          7.5G          0B        7.5G
[root@testos:/root]$ free -k
              total        used        free      shared  buff/cache   available
Mem:        7990276      263128     5714288     1405696     2012860     6146904
Swap:       7812092           0     7812092
[root@testos:/root]$ free -m
              total        used        free      shared  buff/cache   available
Mem:           7803         257        5580        1372        1965        6002
Swap:          7628           0        7628


[root@testos:/root]$ cat /proc/meminfo
MemTotal:        7990276 kB
MemFree:         5714748 kB
MemAvailable:    6147388 kB
Buffers:            6904 kB
Cached:          1941564 kB
SwapCached:            0 kB
Active:           291920 kB
Inactive:        1797308 kB
Active(anon):     219080 kB
Inactive(anon):  1327372 kB
Active(file):      72840 kB
Inactive(file):   469936 kB
Unevictable:           0 kB
Mlocked:               0 kB
SwapTotal:       7812092 kB
SwapFree:        7812092 kB
Dirty:                 8 kB
Writeback:             0 kB
AnonPages:        140756 kB
Mapped:          1065860 kB
Shmem:           1405696 kB
Slab:              64416 kB
SReclaimable:      26848 kB
SUnreclaim:        37568 kB
KernelStack:        4688 kB
PageTables:        22588 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:    11807228 kB
Committed_AS:    5732448 kB
VmallocTotal:   34359738367 kB
VmallocUsed:      191440 kB
VmallocChunk:   34359310332 kB
HardwareCorrupted:     0 kB
AnonHugePages:         0 kB
CmaTotal:              0 kB
CmaFree:               0 kB
HugePages_Total:       0
HugePages_Free:        0
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB
DirectMap4k:       96064 kB
DirectMap2M:     8292352 kB
[root@testos:/root]$

说明

  • Active = Active(anon) + Active(file)

  • Inactive = Inactive(anon) + Inactive(file)

  • Dirty:Dirty字段是关于放在内存里面,后续需要写入磁盘的数据

    #测试
    cat /proc/meminfo |grep Dirty && dd if=/dev//zero of=/tmp/testfile.txt bs=1M count=10 && cat /proc/meminfo |grep Dirty
    
    [root@testos:/root]$ cat /proc/meminfo |grep Dirty && dd if=/dev//zero of=/tmp/testfile.txt bs=1M count=10 && cat /proc/meminfo |grep Dirty
    Dirty:                20 kB
    10+0 records in
    10+0 records out
    10485760 bytes (10 MB) copied, 0.0673421 s, 156 MB/s
    Dirty:             10304 kB
    
  • slab:结合cache缓存内核频繁调用的数据

    slab = SReclaimable + SUnreclaim

4、vmstat命令

5、查看哪些进程使用了大量内存

[root@testos:/root]$ ps -e -orss=,args=|sort -nr|head
903548 ora_mman_testdb
108768 ora_mmon_testdb
103912 ora_smon_testdb
52968 ora_dia0_testdb
52052 ora_mmnl_testdb
41736 ora_cjq0_testdb
38936 ora_dbrm_testdb
37176 ora_ckpt_testdb
36492 ora_pmon_testdb
26148 ora_q000_testdb
[root@testos:/root]$

参考资料:

https://blog.csdn.net/renfufei/article/details/105851728

显卡

Linux查看显卡信息

[root@testos:/root]$ lspci | grep -i vga
00:0f.0 VGA compatible controller: VMware SVGA II Adapter

#使用nvidia GPU可以
lspci | grep -i nvidia

Linux查看Nvidia显卡信息及使用情况

Nvidia自带一个命令行工具可以查看显存的使用情况:

nvidia-smi

表头释义:

  • Fan:显示风扇转速,数值在0到100%之间,是计算机的期望转速,如果计算机不是通过风扇冷却或者风扇坏了,显示出来就是N/A;
  • Temp:显卡内部的温度,单位是摄氏度;
  • Perf:表征性能状态,从P0到P12,P0表示最大性能,P12表示状态最小性能;
  • Pwr:能耗表示;
  • Bus-Id:涉及GPU总线的相关信息;
  • Disp.A:是Display Active的意思,表示GPU的显示是否初始化;
  • Memory Usage:显存的使用率;
  • Volatile GPU-Util:浮动的GPU利用率;
  • Compute M:计算模式;

下边的Processes显示每块GPU上每个进程所使用的显存情况。

如果要周期性的输出显卡的使用情况,可以用watch指令实现:

#命令行参数-n后边跟的是执行命令的周期,以s为单位。
watch -n 10 nvidia-smi

端口使用情况

方式1:

#根据进程号查看端口号
netstat -nap|grep 4498
#通过端口找进程ID
netstat -anp|grep 8081 | grep LISTEN|awk '{printf$7}'|cut -d/ -f1

方法2:

lsof -i :端口号
  • 20
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值