How to view server memory and CPU in Linux (including centos)

CPU architecture

The CPU architecture mainly includes: amd64, arm32v7, arm64v8, mips64el, mips32, ppc64le and ppc32 and other architectures.

CPU information

The CPU information is mainly the detailed information of the central processing unit, including:

  • architecture
  • number of cores
  • processing speed
  • Trade Names
  • CPU frequency
  • Label
    ...
    Note: Different operating systems or CPU architectures may not provide the same information.

1 Check the cpu status

cat /proc/cpuinfo

output:

root@super:/# cat /proc/cpuinfo 
processor       : 0
vendor_id       : GenuineIntel
cpu family      : 6
model           : 60
model name      : Intel(R) Core(TM) i7-4710MQ CPU @ 2.50GHz
stepping        : 3
microcode       : 0x25
cpu MHz         : 2494.235
cache size      : 6144 KB
physical id     : 0
siblings        : 2
core id         : 0
cpu cores       : 2
apicid          : 0
initial apicid  : 0
fpu             : yes
fpu_exception   : yes
cpuid level     : 13
wp              : yes
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 nopl xtopology tsc_reliable nonstop_tsc cpuid 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 cpuid_fault invpcid_single pti ssbd ibrs ibpb stibp fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid xsaveopt arat flush_l1d arch_capabilities
bugs            : cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs itlb_multihit
bogomips        : 4988.47
clflush size    : 64
cache_alignment : 64
address sizes   : 43 bits physical, 48 bits virtual
power management:

Information can be filtered by the grep command:

cat /proc/cpuinfo | grep processor | wc -l
cat /proc/cpuinfo | grep 'core id'

2 lscpu

lscpu is a small and fast command that does not require any options. It is able to simply print cpu details in a user friendly format

root@super:/# lscpu 
Architecture:        x86_64
CPU op-mode(s):      32-bit, 64-bit
Byte Order:          Little Endian
Address sizes:       43 bits physical, 48 bits virtual
CPU(s):              2
On-line CPU(s) list: 0,1
Thread(s) per core:  1
Core(s) per socket:  2
Socket(s):           1
NUMA node(s):        1
Vendor ID:           GenuineIntel
CPU family:          6
Model:               60
Model name:          Intel(R) Core(TM) i7-4710MQ CPU @ 2.50GHz
Stepping:            3
CPU MHz:             2494.235
BogoMIPS:            4988.47
Hypervisor vendor:   VMware
Virtualization type: full
L1d cache:           32K
L1i cache:           32K
L2 cache:            256K
L3 cache:            6144K
NUMA node0 CPU(s):   0,1
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 nopl xtopology tsc_reliable nonstop_tsc cpuid 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 cpuid_fault invpcid_single pti ssbd ibrs ibpb stibp fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid xsaveopt arat flush_l1d arch_capabilities

1 Server CPU situation –cat

1 View the number of physical CPUs:

Procs (process)

cat /proc/cpuinfo | grep "physical id" | sort | uniq | wc -l

2 View the number of server CPU cores

cat /proc/cpuinfo | grep "cpu cores" | uniq

2 Server Hard Disk Conditions –df

1 Linux view system memory (hard disk)

df -h

insert image description here

2 View the usage rate of the server hard disk (under the current folder):

du -sh * 

3 View the server hard disk (all file occupancy) usage:

du -a

3 Server Memory Conditions –free

1 View memory without units

free -m

insert image description here
total: Indicates the total amount of physical memory
used: the total amount allocated to the cache (including Buffer and cache), but some of the cache may not actually use
free: unallocated memory. is the actual amount of physical memory that has not been used.
shared: Shared memory, generally not used by the system, and not discussed here
buff: The number of buffers allocated by the system but not used
cache: The number of caches allocated by the system but not used
(cache is between the CPU and memory, buffer is The connection between memory and disk is to solve the problem of unequal speed.
Cache (cache) is to save the read data. If it hits when re-reading, it will not go to the hard disk. If there is no hit, it will read Hard disk, the data in it will be organized according to the reading frequency, put the most frequently read content in the easiest place to find, and keep the content that is no longer read in the back row until it is deleted. When buffering (buffer) according
to The read and write of the disk is designed to concentrate the scattered write operations, reduce disk fragmentation and repeated seeks of the hard disk, and improve system performance. Linux has a daemon process that regularly clears the buffer content (that is, writes to the disk). Buffer is about
to To be written to the disk, and the cache is read from the disk.)
available: It is different from free, and it is the maximum space that can actually be used. It is the amount of memory that the application thinks is available, available = free + buff/cache (Note: It is only an approximate calculation method). In order to improve the read and write performance, Linux will consume a part of memory resources to cache disk data. For the kernel, buffer and cache are actually both Belongs to memory that is already in use. But when the application applies for memory, if the free memory is not enough, the kernel will reclaim the buffer and cache memory to meet the application's request. This is the buffer and cache to be explained later.

2 View the memory usage, with units, and display the viewing results

free -h

Displayed parameters:

        total:总计物理内存的大小;

        used:已使用内存;

        free:可用内存;

        Shared:多个进程共享的内存总额;

        Buffers/cached:磁盘缓存的大小 缓存是可以清除的

3 cache busting

If the cached is too large and close to the total number, the cache needs to be cleared. The cache clear command:

echo 1 > /proc/sys/vm/drop_caches --释放网页缓存
echo 2 > /proc/sys/vm/drop_caches --释放目录项和索引
echo 3 > /proc/sys/vm/drop_caches --释放网页缓存,目录项和索引

4 View the average load of the server

View the status of each process on the server

top

insert image description here

Line parameter information:


first row:

12:18:39 系统当前时间
392 days, 17:32 系统从开机到现在的时间
1 user 当前用户数
load average: 5.44, 6.00, 6.10  系统1分钟、5分钟、15分钟的CPU负载信息

second line:

532 total:当前有532个任务,也就是532个进程。
2 running:2个进程正在运行
529 sleeping:529个进程睡眠
0 stopped:停止的进程数
1 zombie:僵死的进程数

The third row:

Cpu(s):表示这一行显示CPU总体信息

8.1us:用户态进程占用CPU时间百分比,不包含renice值为负的任务占用的CPU的时间。
2.4sy:内核占用CPU时间百分比
0.0ni:改变过优先级的进程占用CPU的百分比
89.0 id:空闲CPU时间百分比
0.2wa:等待I/O的CPU时间百分比
0.0hi:CPU硬中断时间百分比
0.3si:CPU软中断时间百分比
注:这里显示数据是所有cpu的平均值,如果想看每一个cpu的处理情况,按1即可;折叠,再次按1;

Fourth line:

Men:内存的意思
65281768k total:物理内存总量
30484308k used:使用的物理内存量
3235388k free:空闲的物理内存量
31562072k buff/cache:用作内核缓存的物理内存量

The fifth line:

Swap:交换空间

total:交换区总量
used:使用的交换区量
free:空闲的交换区量
avail Men:实际最大可用交换区总量

Process information:

PID:进程的ID
USER:进程所有者
PR:进程的优先级别,越小越优先被执行
NInice:值
VIRT:进程占用的虚拟内存
RES:进程占用的物理内存
SHR:进程使用的共享内存
S:进程的状态。S表示休眠,R表示正在运行,Z表示僵死状态,N表示该进程优先值为负数
%CPU:进程占用CPU的使用率
%MEM:进程使用的物理内存和总内存的百分比
TIME+:该进程启动后占用的总的CPU时间,即占用CPU使用时间的累加值。
COMMAND:进程启动命令名称

Then press a specific key to clearly view the usage of cpu and memory

① Type in uppercase P, and the results are sorted in descending order of CPU usage,%CPU

insert image description here

② Type in uppercase M, the results are sorted in descending order of memory usage,%MEN

insert image description here

Guess you like

Origin blog.csdn.net/weixin_45277161/article/details/131524555