Linux 进程管理 vmstat、top、pstree命令

vmstat命令:监控系统资源

vmstat 是 Linux 中的一个综合性能分析工具,可以用来监控 CPU 使用、进程状态、内存使用、虚拟内存使用、磁盘输入/输出状态等信息。vmstat 命令格式如下:
[root@localhost ~]# vmstat [刷新延时 刷新次数]

使用vmstat检测,每隔1秒刷新一次,共刷新3次

[root@localhost ~]# vmstat 1 3
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 3  0   6780  93228  40080 1174336    0    0   170     3   42   72  0  1 99  0  0
 0  0   6780  93212  40088 1174332    0    0     0    12   34   61  0  0 100  0  0
 0  0   6780  93212  40088 1174336    0    0     0     0   31   48  0  0 100  0  0

1) procs:进程信息字段:

  • -r:等待运行的进程数,数量越大,系统越繁忙。
  • -b:不可被唤醒的进程数量,数量越大,系统越繁忙。
2) memory:内存信息字段:
  • -swpd:虚拟内存的使用情况,单位为KB。
  • -free:空闲的内存容量,单位为KB。
  • -buff:缓冲的内存容量,单位为KB。
  • -cache:缓存的内存容量,单位为KB。
3) swap:交换分区信息字段:
  • -si:从磁盘中交换到内存中数据的数量,单位为KB。
  • -so:从内存中交换到磁盘中数据的数量,单位为KB。
这两个数越大,表明数据需要经常在磁盘和内存之间进行交换,系统性能越差。

4) io:磁盘读/写信息字段:
  • -bi:从块设备中读入的数据的总量,单位是块。
  • -bo:写到块设备的数据的总量,单位是块。
这两个数越大,代表系统的 I/O 越繁忙。

5) system:系统信息字段:
  • -in:每秒被中断的进程次数。
  • -cs:每秒进行的事件切换次数。
这两个数越大,代表系统与接口设备的通信越繁忙。

6) cpu:CPU信息字段:
  • -us:非内核进程消耗CPU运算时间的百分比。
  • -sy:内核进程消耗CPU运算时间的百分比。
  • -id:空闲CPU的百分比。
  • -wa:等待I/O所消耗的CPU百分比。
  • -st:被虚拟机所盗用的CPU百分比。
如果服务器上的资源占用率比较高,那么使用 vmstat 命令查看到的参数值就会比较大。我们就需要手工进行干预,如果是非正常进程占用了系统资源,则需要判断这些进程是如何产生的;如果是正常进程占用了系统资源,则说明服务器需要升级了。

dmesg命令:显示开机时的内核检测信息

在系统启动过程中,内核还需要进行一次系统检测,这些内核检测信息会被记录在内存当中。使用dmesg 命令就可以查看这些内核检测信息。我们一般利用这个命令查看系统的硬件信息。dmesg 命令格式如下:

[root@localhost ~]# dmesg

查看CPU的信息

[root@localhost ~]# dmesg | grep CPU
[    0.000000] smpboot: Allowing 128 CPUs, 127 hotplug CPUs
[    0.000000] setup_percpu: NR_CPUS:5120 nr_cpumask_bits:128 nr_cpu_ids:128 nr_node_ids:1
[    0.000000] PERCPU: Embedded 31 pages/cpu @ffff88007c600000 s87168 r8192 d31616 u131072
[    0.000000] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=128, Nodes=1
[    0.000000]     RCU restricting CPUs from NR_CPUS=5120 to nr_cpu_ids=128.
[    0.000000]     Offload RCU callbacks from all CPUs
[    0.000000]     Offload RCU callbacks from CPUs: 0-127.
[    0.021791] CPU: Physical Processor ID: 0
[    0.022946] mce: CPU supports 8 MCE banks
[    0.091101] smpboot: CPU0: Intel(R) Core(TM) i5-6200U CPU @ 2.30GHz (fam: 06, model: 4e, stepping: 03)
[    0.091198] perf_event_intel: CPUID marked event: 'cpu cycles' unavailable
[    0.091199] perf_event_intel: CPUID marked event: 'instructions' unavailable
[    0.091200] perf_event_intel: CPUID marked event: 'bus cycles' unavailable
[    0.091200] perf_event_intel: CPUID marked event: 'cache references' unavailable
[    0.091201] perf_event_intel: CPUID marked event: 'cache misses' unavailable
[    0.091201] perf_event_intel: CPUID marked event: 'branch instructions' unavailable
[    0.091202] perf_event_intel: CPUID marked event: 'branch misses' unavailable
[    0.137337] Brought up 1 CPUs
[    1.383566] microcode: CPU0 sig=0x406e3, pf=0x1, revision=0xc6

查看第一块网卡的信息

[root@localhost ~]# dmesg | grep eth0
[    2.521339] e1000 0000:02:01.0 eth0: (PCI:66MHz:32-bit) 00:0c:29:19:e9:cb
[    2.521344] e1000 0000:02:01.0 eth0: Intel(R) PRO/1000 Network Connection

free命令:查看内存使用状态

free 命令可以查看系统内存和 swap 交换分区的使用情况,其输出和 top 命令的内存部分非常相似。free 命令格式如下:

[root@localhost ~]# free [选项]

选项:

  • -b:以字节为单位显示;
  • -k:以 KB 为单位显示,默认显示;
  • -m:以 MB 为单位显示;
  • -g:以 GB 为单位显示;

查看内存使用状态

[root@localhost ~]# free
              total        used        free      shared  buff/cache   available
Mem:        1868660      561096       93000        5148     1214564     1114304
Swap:       2097148        6776     2090372
  •  第一行:total 是总内存数,used 是已经使用的内存数,free 是空闲的内存数,shared 是多个进程共享的内存总数,buffers 是缓冲内存数,cached 是缓存内存数。默认单位是 KB。
  • 第二行:-/buffers/cache 的内存数,相当于第一行的 used-buffers-cached。+/buffers/cache 的内存数,相当于第一行的 free+buffers+cached。
  • 第三行:total 是 swap 交换分区的总数;used 是已经使用的 swap 交换分区数,free 是空闲的 swap 交换分区数。默认单位是 KB。

Linux查看CPU信息方法

CPU 的主要信息保存在 /proc/cpuinfo 这个文件中,我们只要查看这个文件,就可以知道 CPU 的相关信息。

[root@localhost ~]# cat /proc/cpuinfo
processor    : 0             #逻辑CPU编号
vendor_id    : GenuineIntel  #CPU制造厂商
cpu family   : 6             #产品的系列代号
model        : 78            #CPU系列代号
model name   : Intel(R) Core(TM) i5-6200U CPU @ 2.30GHz #CPU系列的名字、编号、主频
stepping     : 3   #更新版本
microcode    : 0xc6  
cpu MHz         : 2400.005   #实际主频
cache size      : 3072 KB    #二级缓存
physical id     : 0
siblings        : 1
core id         : 0
cpu cores       : 1
apicid          : 0
initial apicid  : 0
fpu             : yes
fpu_exception   : yes
cpuid level     : 22
wp           : yes
#CPU的功能标识
flags        : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon nopl xtopology tsc_reliable nonstop_tsc 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 arat fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid mpx rdseed adx smap clflushopt xsaveopt xsavec xsaves
bogomips     : 4800.01
clflush size    : 64
cache_alignment : 64
address sizes   : 43 bits physical, 48 bits virtual
power management:

猜你喜欢

转载自www.cnblogs.com/lizhouwei/p/10123617.html