查询Unix下机器内存、cpu、磁盘等信息

 

介 绍

  Linux系统上的/proc目录是一种伪文件系统(也即虚拟文件系统),存储的是当前内核运行状态的一系列特殊文件,用户可以通过这些文件查看有关系统硬件及当前正在运行进程的信息,甚至可以通过更改其中某些文件来改变内核的运行状态。

 

1. 查看CPU信息


/proc/cpuinfo
例如:下面的机器配置
4个CPU(processor的个数) -> cat /proc/cpuinfo | grep  processor
型号:Intel(R) Xeon(R) Platinum 8163 CPU @ 2.50GHz -> cat /proc/cpuinfo | grep 'model name'
8核(每个CPU是2核) -> cat /proc/cpuinfo | grep 'cpu cores'

128MB缓存(每个CPU32MB缓存) -> cat /proc/cpuinfo | grep 'cache size'
等等等等


  1 [root@192.168.1.101 /]# cat /proc/cpuinfo 
  2 processor       : 0
  3 vendor_id       : GenuineIntel
  4 cpu family      : 6
  5 model           : 85
  6 model name      : Intel(R) Xeon(R) Platinum 8163 CPU @ 2.50GHz
  7 stepping        : 4
  8 microcode       : 0x1
  9 cpu MHz         : 2499.998
 10 cache size      : 33792 KB
 11 physical id     : 0
 12 siblings        : 4
 13 core id         : 0
 14 cpu cores       : 2
 15 apicid          : 0
 16 initial apicid  : 0
 17 fpu             : yes
 18 fpu_exception   : yes
 19 cpuid level     : 13
 20 wp              : yes
 21 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 rep_good nopl 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 invpcid_single ibrs ibpb stibp fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm mpx avx512f avx512dq rdseed adx smap avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1 spec_ctrl intel_stibp
 22 bogomips        : 4999.99
 23 clflush size    : 64
 24 cache_alignment : 64
 25 address sizes   : 46 bits physical, 48 bits virtual
 26 power management:
 27 
 28 processor       : 1
 29 vendor_id       : GenuineIntel
 30 cpu family      : 6
 31 model           : 85
 32 model name      : Intel(R) Xeon(R) Platinum 8163 CPU @ 2.50GHz
 33 stepping        : 4
 34 microcode       : 0x1
 35 cpu MHz         : 2499.998
 36 cache size      : 33792 KB
 37 physical id     : 0
 38 siblings        : 4
 39 core id         : 0
 40 cpu cores       : 2
 41 apicid          : 1
 42 initial apicid  : 1
 43 fpu             : yes
 44 fpu_exception   : yes
 45 cpuid level     : 13
 46 wp              : yes
 47 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 rep_good nopl 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 invpcid_single ibrs ibpb stibp fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm mpx avx512f avx512dq rdseed adx smap avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1 spec_ctrl intel_stibp
 48 bogomips        : 4999.99
 49 clflush size    : 64
 50 cache_alignment : 64
 51 address sizes   : 46 bits physical, 48 bits virtual
 52 power management:
 53 
 54 processor       : 2
 55 vendor_id       : GenuineIntel
 56 cpu family      : 6
 57 model           : 85
 58 model name      : Intel(R) Xeon(R) Platinum 8163 CPU @ 2.50GHz
 59 stepping        : 4
 60 microcode       : 0x1
 61 cpu MHz         : 2499.998
 62 cache size      : 33792 KB
 63 physical id     : 0
 64 siblings        : 4
 65 core id         : 1
 66 cpu cores       : 2
 67 apicid          : 2
 68 initial apicid  : 2
 69 fpu             : yes
 70 fpu_exception   : yes
 71 cpuid level     : 13
 72 wp              : yes
 73 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 rep_good nopl 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 invpcid_single ibrs ibpb stibp fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm mpx avx512f avx512dq rdseed adx smap avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1 spec_ctrl intel_stibp
 74 bogomips        : 4999.99
 75 clflush size    : 64
 76 cache_alignment : 64
 77 address sizes   : 46 bits physical, 48 bits virtual
 78 power management:
 79 
 80 processor       : 3
 81 vendor_id       : GenuineIntel
 82 cpu family      : 6
 83 model           : 85
 84 model name      : Intel(R) Xeon(R) Platinum 8163 CPU @ 2.50GHz
 85 stepping        : 4
 86 microcode       : 0x1
 87 cpu MHz         : 2499.998
 88 cache size      : 33792 KB
 89 physical id     : 0
 90 siblings        : 4
 91 core id         : 1
 92 cpu cores       : 2
 93 apicid          : 3
 94 initial apicid  : 3
 95 fpu             : yes
 96 fpu_exception   : yes
 97 cpuid level     : 13
 98 wp              : yes
 99 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 rep_good nopl 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 invpcid_single ibrs ibpb stibp fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm mpx avx512f avx512dq rdseed adx smap avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1 spec_ctrl intel_stibp
100 bogomips        : 4999.99
101 clflush size    : 64
102 cache_alignment : 64
103 address sizes   : 46 bits physical, 48 bits virtual
104 power management:
View Code


2. 查看内存信息

 1)/proc/meminfo

     例如:下面的机器配置
      总内存16GB     ->     cat /proc/meminfo | grep MemTotal

 

 1 [root@192.168.1.101 /]# cat /proc/meminfo 
 2 MemTotal:       16266248 kB
 3 MemFree:          187700 kB
 4 MemAvailable:    3607004 kB
 5 Buffers:          345352 kB
 6 Cached:          3065816 kB
 7 SwapCached:            0 kB
 8 Active:         13992656 kB
 9 Inactive:        1393300 kB
10 Active(anon):   11979680 kB
11 Inactive(anon):      716 kB
12 Active(file):    2012976 kB
13 Inactive(file):  1392584 kB
14 Unevictable:           0 kB
15 Mlocked:               0 kB
16 SwapTotal:             0 kB
17 SwapFree:              0 kB
18 Dirty:              1844 kB
19 Writeback:             0 kB
20 AnonPages:      11974788 kB
21 Mapped:           200612 kB
22 Shmem:              5608 kB
23 Slab:             425576 kB
24 SReclaimable:     351984 kB
25 SUnreclaim:        73592 kB
26 KernelStack:       35600 kB
27 PageTables:        47152 kB
28 NFS_Unstable:          0 kB
29 Bounce:                0 kB
30 WritebackTmp:          0 kB
31 CommitLimit:     8133124 kB
32 Committed_AS:   24125312 kB
33 VmallocTotal:   34359738367 kB
34 VmallocUsed:       33716 kB
35 VmallocChunk:   34359614132 kB
36 HardwareCorrupted:     0 kB
37 AnonHugePages:   4734976 kB
38 CmaTotal:              0 kB
39 CmaFree:               0 kB
40 HugePages_Total:       0
41 HugePages_Free:        0
42 HugePages_Rsvd:        0
43 HugePages_Surp:        0
44 Hugepagesize:       2048 kB
45 DirectMap4k:      219008 kB
46 DirectMap2M:    10266624 kB
47 DirectMap1G:     8388608 kB
View Code

 

2)也可以使用命令:free -h

3. 查看磁盘信息

1)查看总磁盘大小

  fdisk -l | grep Disk

如下,总磁盘大小260GB,2个分区(/dev/vda和/dev/vdb)

 

[root@192.168.1.101 /]# fdisk -l | grep Disk
Disk /dev/vda: 42.9 GB, 42949672960 bytes, 83886080 sectors
Disk label type: dos
Disk identifier: 0x0008d73a
Disk /dev/vdb: 214.7 GB, 214748364800 bytes, 419430400 sectors
Disk label type: dos
Disk identifier: 0x739f15b1

 

2)查看磁盘使用情况

df -h

3)查看当前目录下文件大小

du -sh *

 

4. 查看Linux版本详情

/proc/version

例如:Linux版本:3.10.0-1062.9.1.el7.x86_64 垃圾回收机制:(Red Hat 4.8.5-39) (GCC)
cat /proc/version 
Linux version 3.10.0-1062.9.1.el7.x86_64 (mockbuild@kbuilder.bsys.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) ) #1 SMP Fri Dec 6 15:49:49 UTC 2019
____________________________特此,勉励____________________________
本文作者cheng2839
本文链接https://www.cnblogs.com/cheng2839
关于博主:评论和私信会在第一时间回复。
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角【推荐】一下。您的鼓励是博主的最大动力!
原文地址:https://www.cnblogs.com/cheng2839/p/12660519.html