vmstat
命令(監控系統資源)【經常使用】 vmstat [刷新延時 刷新次數]
r
:等待運行的進程數。
b
:不可被喚醒的進程數。這兩個數量越大,表示系統越繁忙node
swpd
:虛擬內存的使用狀況,單位KB。
free
:空閒的內存容量,單位KB。
buff
:緩衝的內存容量,單位KB。
cache
:緩存的內存容量,單位KB。緩衝(buffer)和緩衝(cache)的區別:
簡單來講,緩存(cache)是用來加速數據從硬盤中「讀取」的,而緩衝(buffer)是用來加速數據「寫入」硬盤的。linux
si
:從磁盤中交換到內存中數據的數量,單位KB。
so
:從內存中交換到磁盤中數據的數量,單位KB。這兩個數據越大,說明數據須要常常在磁盤和內存之間交換,系統性能越差。nginx
bi
:由磁盤寫入的塊數量,單位是塊。
bo
:寫入到磁盤中去的塊數量,單位是塊(如今的Linux版本塊的大小爲1kb)。這兩個數據越大,說明系統的I/O越繁忙。ubuntu
in
:每秒被中斷的進程次數。
cs
:每秒進行的時間切換次數。這兩個數據越大,說明系統與接口設備的通訊很是頻繁。這些接口設備包含磁盤、網卡、時鐘等。api
us
:非內核進程消耗CPU運算時間的百分比。
sy
:內核進程消耗CPU運算時間的百分比。
id
:空閒CPU的百分比。
wa
:等待I/O所消耗的CPU百分比。
st
:被虛擬機所盜用的CPU百分比數。
[vagrant~] ]$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 0 0 0 259312 28320 108272 0 0 30 4 41 202 0 0 99 0 0 0 0 0 259304 28320 108272 0 0 0 0 50 93 0 1 99 0 0 0 0 0 259300 28320 108272 0 0 0 0 33 73 0 0 100 0 0
dmesg
命令(開機時內核檢查信息)【經常使用】 dmesg | less
[vagrant~] ]$dmesg | less [ 0.000000] Initializing cgroup subsys cpuset [ 0.000000] Initializing cgroup subsys cpu [ 0.000000] Initializing cgroup subsys cpuacct [ 0.000000] Linux version 3.13.0-24-generic (buildd@panlong) (gcc version 4.8.2 (Ubuntu 4.8.2-19ubuntu1) ) #46-Ubuntu SMP Thu Apr 10 19:11:08 UTC 2014 (Ubuntu 3.13.0-24.46-generic 3.13.9) [ 0.000000] Command line: BOOT_IMAGE=/boot/vmlinuz-3.13.0-24-generic root=UUID=64ecdf77-db7b-48a8-9066-abfb837f2e24 ro ...省略n行... [ 0.000000] Zone ranges: [ 0.000000] DMA [mem 0x00001000-0x00ffffff] [ 0.000000] DMA32 [mem 0x01000000-0xffffffff] [ 0.000000] Normal empty [ 0.000000] Movable zone start for each node :
dmesg | grep CPU
[vagrant~] ]$dmesg | grep CPU [ 0.000000] CPU MTRRs all blank - virtualized system. [ 0.000000] ACPI: SSDT 000000001fff02a0 0001CC (v01 VBOX VBOXCPUT 00000002 INTL 20100528) [ 0.000000] smpboot: Allowing 1 CPUs, 0 hotplug CPUs [ 0.000000] setup_percpu: NR_CPUS:256 nr_cpumask_bits:256 nr_cpu_ids:1 nr_node_ids:1 [ 0.000000] PERCPU: Embedded 29 pages/cpu @ffff88001fc00000 s86336 r8192 d24256 u2097152 [ 0.000000] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=1, Nodes=1 [ 0.000000] RCU restricting CPUs from NR_CPUS=256 to nr_cpu_ids=1. [ 0.000000] Offload RCU callbacks from all CPUs [ 0.000000] Offload RCU callbacks from CPUs: 0. [ 0.004582] mce: CPU supports 0 MCE banks [ 0.078327] smpboot: CPU0: AMD A10-7870K Radeon R7, 12 Compute Cores 4C+8G (fam: 15, model: 38, stepping: 01) [ 0.083763] x86: Booted up 1 node, 1 CPUs [ 0.844045] microcode: CPU0: patch_level=0x06000626 [ 0.908285] ledtrig-cpu: registered to indicate activity on CPUs [ 3.624181] CPU: 0 PID: 293 Comm: systemd-udevd Tainted: GF O 3.13.0-24-generic #46-Ubuntu
dmesg | grep -i hd
[vagrant~] ]$dmesg | grep -i hd [ 0.084000] NMI watchdog: disabled (cpu0): hardware events not enabled
free
命令(查看內存使用狀態)【經常使用】 free [選項]
-b
:以字節爲單位顯示
-k
:以KB爲單位顯示(默認)
-m
:以MB爲單位顯示
-g
:以GB爲單位顯示
Mem | 總內存數 | 已使用內存數 | 空閒內存數 | 多個進程共享內存數 | 緩衝內存數 | 緩存內存數 |
Swap | swap總數 | 已經使用的swap數 | 空閒的swap數 |
-/+ buffers/cache
-buffers/cache
=used
-buffers
-cached
+buffers/cache
=free
+buffers
+cached
[vagrant~] ]$free total used free shared buffers cached Mem: 501832 248436 253396 2372 33216 109116 -/+ buffers/cache: 106104 395728 Swap: 522236 0 522236 [vagrant~] ]$free -b total used free shared buffers cached Mem: 513875968 254517248 259358720 2428928 34029568 111755264 -/+ buffers/cache: 108732416 405143552 Swap: 534769664 0 534769664 [vagrant~] ]$free -k total used free shared buffers cached Mem: 501832 248576 253256 2372 33232 109136 -/+ buffers/cache: 106208 395624 Swap: 522236 0 522236 [vagrant~] ]$free -m total used free shared buffers cached Mem: 490 242 247 2 32 106 -/+ buffers/cache: 103 386 Swap: 509 0 509 [vagrant~] ]$free -g total used free shared buffers cached Mem: 0 0 0 0 0 0 -/+ buffers/cache: 0 0 Swap: 0 0 0
cat /proc/cpuinfo
[vagrant~] ]$cat /proc/cpuinfo processor : 0 vendor_id : AuthenticAMD cpu family : 21 model : 56 model name : AMD A10-7870K Radeon R7, 12 Compute Cores 4C+8G stepping : 1 microcode : 0x6000626 cpu MHz : 3892.536 cache size : 2048 KB physical id : 0 siblings : 1 core id : 0 cpu cores : 1 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 syscall nx mmxext fxsr_opt rdtscp lm rep_good nopl extd_apicid pni pclmulqdq monitor ssse3 cx16 sse4_1 sse4_2 popcnt aes xsave avx lahf_lm cr8_legacy abm sse4a misalignsse 3dnowprefetch arat fsgsbase bogomips : 7785.07 TLB size : 1536 4K pages clflush size : 64 cache_alignment : 64 address sizes : 48 bits physical, 48 bits virtual power management:
uptime
命令(顯示系統的啓動時間和平均負載)輸出結果與top
命令和w
的第一行相同。
[vagrant~] ]$uptime 02:35:11 up 2:43, 1 user, load average: 0.00, 0.06, 0.07 [vagrant~] ]$w 02:35:13 up 2:43, 1 user, load average: 0.00, 0.06, 0.07 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT vagrant pts/0 10.0.2.2 23:52 1.00s 0.49s 0.00s w [vagrant~] ]$top top - 02:36:52 up 2:45, 1 user, load average: 0.00, 0.04, 0.06 Tasks: 80 total, 1 running, 79 sleeping, 0 stopped, 0 zombie %Cpu(s): 0.1 us, 0.3 sy, 0.0 ni, 99.5 id, 0.1 wa, 0.0 hi, 0.0 si, 0.0 st KiB Mem: 501832 total, 251856 used, 249976 free, 35560 buffers KiB Swap: 522236 total, 0 used, 522236 free. 109596 cached Mem ...省略n行...
uname
命令uname [選項]
-a
:查看系統全部相關信息
-r
:查看內核版本
-s
:查看內核名稱
-m
:查看系統的硬件名稱,例如 i686 或 x86_64 等
-p
:查看CPU的類型,與 -m 相似,只是顯示的是CPU的類型
-i
:查看硬件的平臺(ix86)
[vagrant~] ]$uname Linux [vagrant~] ]$uname -a Linux vagrant-ubuntu-trusty 3.13.0-24-generic #46-Ubuntu SMP Thu Apr 10 19:11:08 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux [vagrant~] ]$uname -s Linux [vagrant~] ]$uname -r 3.13.0-24-generic [vagrant~] ]$uname -m x86_64 [vagrant~] ]$uname -p x86_64 [vagrant~] ]$uname -i x86_64
file /bin/ls
[vagrant~] ]$file /bin/ls /bin/ls: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=64d095bc6589dd4bfbf1c6d62ae985385965461b, stripped
lsb_release -a
[vagrant~] ]$lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 14.04 LTS Release: 14.04 Codename: trusty
lsof
命令(列出進程打開或使用的文件信息)【經常使用】 lsof [選項]
-c
字符串:只列出以字符串開頭的進程打開的文件
-u
用戶名:只列出某個用戶的進程打開的文件
-p
pid:只列出某個PID進程打開的文件
lsof | less
[vagrant~] ]$sudo lsof | less COMMAND PID TID USER FD TYPE DEVICE SIZE/OFF NODE NAME init 1 root cwd DIR 8,1 4096 2 / init 1 root rtd DIR 8,1 4096 2 / init 1 root txt REG 8,1 265848 1835051 /sbin/init init 1 root mem REG 8,1 47712 1053013 /lib/x86_64-linux-gnu/libnss_files-2.19.so init 1 root mem REG 8,1 47760 1053033 ...省略n行... khelper 13 root cwd DIR 8,1 4096 2 / khelper 13 root rtd DIR 8,1 4096 2 / khelper 13 root txt unknown /proc/13/exe :
lsof 文件名
[vagrant~] ]$sudo lsof /sbin/init COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME init 1 root txt REG 8,1 265848 1835051 /sbin/init
lsof -c 進程名
[vagrant~] ]$sudo lsof -c nginx COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME nginx 1000 root cwd DIR 8,1 4096 2 / nginx 1000 root rtd DIR 8,1 4096 2 / nginx 1000 root txt REG 8,1 873176 1573477 /usr/sbin/nginx nginx 1000 root mem REG 8,1 47712 1053013 ...省略n行... nginx 1004 www-data 14u unix 0xffff88001b776000 0t0 9508 socket nginx 1004 www-data 15u 0000 0,9 0 5249 anon_inode
lsof -u 用戶名
[vagrant~] ]$sudo lsof -u vagrant COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME sshd 1516 vagrant cwd DIR 8,1 4096 2 / sshd 1516 vagrant rtd DIR 8,1 4096 2 / sshd 1516 vagrant txt REG 8,1 766784 1583210 /usr/sbin/sshd sshd 1516 vagrant DEL REG 0,4 11386 /dev/zero sshd 1516 vagrant mem REG 8,1 14464 1048876 /lib/x86_64-linux-gnu/security/pam_env.so ...省略n行... bash 1517 vagrant 0u CHR 136,0 0t0 3 /dev/pts/0 bash 1517 vagrant 1u CHR 136,0 0t0 3 /dev/pts/0 bash 1517 vagrant 2u CHR 136,0 0t0 3 /dev/pts/0 bash 1517 vagrant 255u CHR 136,0 0t0 3 /dev/pts/0
lsof -p PID
[vagrant~] ]$sudo lsof -p 1003 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME nginx 1003 www-data cwd DIR 8,1 4096 2 / nginx 1003 www-data rtd DIR 8,1 4096 2 / nginx 1003 www-data txt REG 8,1 873176 1573477 /usr/sbin/nginx nginx 1003 www-data mem REG 8,1 47712 1053013 /lib/x86_64-linux-gnu/libnss_files-2.19.so ...省略n行... nginx 1003 www-data 6u IPv4 9497 0t0 TCP *:http (LISTEN) nginx 1003 www-data 7u IPv6 9498 0t0 TCP *:http (LISTEN) nginx 1003 www-data 13u 0000 0,9 0 5249 anon_inode