【Linux】監控系統的狀態


1.w命令

w命令是一個很強大的命令,該命令顯示的信息比較豐富。以下是我的虛擬機w命令的一個展示

image

從上圖我們可以看到:

第一行從左面開始顯示的信息依次為:時間、系統運行時間、登陸用戶數、平均負載

第二行以及下面所有行告訴我們,當前登陸的用戶以及從哪里登陸的

我們重點關注一下load average

第一個數值表示1分鍾內系統的平均負載值;第二個數值表示5分鍾系統的平均負載值;第三個數值表示的是系統15分鍾內的平均負載值,這個值的意義是單位時間段內CPU進程活動數,這個值越大就說明服務器壓力越大

一般情況下這個值只要不超過CPU數量就沒關系,那么CPU數量如何查看呢?

2.查看CPU數量

Linux:/ # cat /proc/cpuinfo
processor	: 0
vendor_id	: GenuineIntel
cpu family	: 6
model		: 78
model name	: Intel(R) Core(TM) i5-6200U CPU @ 2.30GHz
stepping	: 3
microcode	: 186
cpu MHz		: 2400.000
cache size	: 3072 KB
fpu		: yes
fpu_exception	: yes
cpuid level	: 22
wp		: yes
flags		: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts mmx fxsr sse sse2 ss syscall nx pdpe1gb rdtscp lm constant_tsc up arch_perfmon pebs bts nopl xtopology tsc_reliable nonstop_tsc aperfmperf pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt xsave avx f16c rdrand hypervisor lahf_lm 3dnowprefetch ida arat epb pln pts dtherm fsgsbase smep
bogomips	: 4800.00
clflush size	: 64
cache_alignment	: 64
address sizes	: 40 bits physical, 48 bits virtual
power management:

上述參數釋意

processor :系統中邏輯處理核的編號。對於單核處理器,則課認為是其CPU編號,對於多核處理器則可以是物理核、或者使用超線程技術虛擬的邏輯核
vendor_id :CPU制造商    
cpu family :CPU產品系列代號
model   :CPU屬於其系列中的哪一代的代號
model name:CPU屬於的名字及其編號、標稱主頻
stepping   :CPU屬於制作更新版本
cpu MHz   :CPU的實際使用主頻
cache size   :CPU二級緩存大小
physical id   :單個CPU的標號(由於我的虛擬機只有一個CPU,所以無以下紅色標記信息項
siblings       :單個CPU邏輯物理核數
core id        :當前物理核在其所處CPU中的編號,這個編號不一定連續
cpu cores    :該邏輯核所處CPU的物理核數
apicid          :用來區分不同邏輯核的編號,系統中每個邏輯核的此編號必然不同,此編號不一定連續
fpu             :是否具有浮點運算單元(Floating Point Unit)
fpu_exception  :是否支持浮點計算異常
cpuid level   :執行cpuid指令前,eax寄存器中的值,根據不同的值cpuid指令會返回不同的內容
wp             :表明當前CPU是否在內核態支持對用戶空間的寫保護(Write Protection)
flags          :當前CPU支持的功能
bogomips   :在系統內核啟動時粗略測算的CPU速度(Million Instructions Per Second)
clflush size  :每次刷新緩存的大小單位
cache_alignment :緩存地址對齊單位
address sizes     :可訪問地址空間位數

power management :對能源管理的支持,有以下幾個可選支持功能:

  ts:  temperature sensor

  fid:   frequency id control

  vid:  voltage id control

  ttp:  thermal trip

  tm:

  stc:

  100mhzsteps:

  hwpstate:

CPU信息中flags各項含義:

fpu: Onboard (x87) Floating Point Unit
vme: Virtual Mode Extension
de: Debugging Extensions
pse: Page Size Extensions
tsc: Time Stamp Counter: support for RDTSC and WRTSC instructions
msr: Model-Specific Registers
pae: Physical Address Extensions: ability to access 64GB of memory; only 4GB can be accessed at a time though
mce: Machine Check Architecture
cx8: CMPXCHG8 instruction
apic: Onboard Advanced Programmable Interrupt Controller
sep: Sysenter/Sysexit Instructions; SYSENTER is used for jumps to kernel memory during system calls, and SYSEXIT is used for jumps: back to the user code
mtrr: Memory Type Range Registers
pge: Page Global Enable
mca: Machine Check Architecture
cmov: CMOV instruction
pat: Page Attribute Table
pse36: 36-bit Page Size Extensions: allows to map 4 MB pages into the first 64GB RAM, used with PSE.
pn: Processor Serial-Number; only available on Pentium 3
clflush: CLFLUSH instruction
dtes: Debug Trace Store
acpi: ACPI via MSR
mmx: MultiMedia Extension
fxsr: FXSAVE and FXSTOR instructions
sse: Streaming SIMD Extensions. Single instruction multiple data. Lets you do a bunch of the same operation on different pieces of input: in a single clock tick.
sse2: Streaming SIMD Extensions-2. More of the same.
selfsnoop: CPU self snoop
acc: Automatic Clock Control
IA64: IA-64 processor Itanium.
ht: HyperThreading. Introduces an imaginary second processor that doesn’t do much but lets you run threads in the same process a  bit quicker.
nx: No Execute bit. Prevents arbitrary code running via buffer overflows.
pni: Prescott New Instructions aka. SSE3
vmx: Intel Vanderpool hardware virtualization technology
svm: AMD “Pacifica” hardware virtualization technology
lm: “Long Mode,” which means the chip supports the AMD64 instruction set
tm: “Thermal Monitor” Thermal throttling with IDLE instructions. Usually hardware controlled in response to CPU temperature.
tm2: “Thermal Monitor 2″ Decrease speed by reducing multipler and vcore.
est: “Enhanced SpeedStep”

根據以上內容,我們則可以很方便的知道當前系統關於CPU、CPU的核數、CPU是否啟用超線程等信息。

3.vmstat 監控系統的狀態


image

輸出字段釋意

Procs

r: The number of processes waiting for run time.

等待運行的進程數。如果等待運行的進程數越多,意味着CPU非常繁忙。另外,如果該參數長期大於和等於邏輯cpu個數,則CPU資源可能存在較大的瓶頸。

b: The number of processes in uninterruptible sleep.

處在非中斷睡眠狀態的進程數。意味着進程被阻塞。主要是指被資源阻塞的進程對列數(比如IO資源、頁面調度等),當這個值較大時,需要根據應用程序來進行分析,比如數據庫產品,中間件應用等。

Memory

swpd: the amount of virtual memory used.

已使用的虛擬內存大小。如果虛擬內存使用較多,可能系統的物理內存比較吃緊,需要采取合適的方式來減少物理內存的使用。swapd不為0,並不意味物理內存吃緊,如果swapd沒變化,si、so的值長期為0,這也是沒有問題的

       free: the amount of idle memory.

空閑的物理內存的大小

buff: the amount of memory used as buffers.

用來做buffer(緩存,主要用於塊設備緩存)的內存數,單位:KB

cache: the amount of memory used as cache.

用來做cache(緩存,主要用於緩存文件)的內存,單位:KB

inact: the amount of inactive memory. (-a option)

inactive memory的總量

active: the amount of active memory. (-a option)

active memroy的總量。

Swap

si: Amount of memory swapped in from disk (/s).

從磁盤交換到內存的交換頁數量,單位:KB/秒。

so: Amount of memory swapped to disk (/s).

從內存交換到磁盤的交換頁數量,單位:KB/秒

內存夠用的時候,這2個值都是0,如果這2個值長期大於0時,系統性能會受到影響,磁盤IO和CPU資源都會被消耗。

當看到空閑內存(free)很少的或接近於0時,就認為內存不夠用了,這個是不正確的。不能光看這一點,還要結合si和so,

如果free很少,但是si和so也很少(大多時候是0),那么不用擔心,系統性能這時不會受到影響的。

當內存的需求大於RAM的數量,服務器啟動了虛擬內存機制,通過虛擬內存,可以將RAM段移到SWAP DISK的特殊磁盤段上,

這樣會 出現虛擬內存的頁導出和頁導入現象,頁導出並不能說明RAM瓶頸,虛擬內存系統經常會對內存段進行頁導出,

但頁導入操作就表明了服務器需要更多的內存了, 頁導入需要從SWAP DISK上將內存段復制回RAM,導致服務器速度變慢。

IO

bi: Blocks received from a block device (blocks/s).

每秒從塊設備接收到的塊數,單位:塊/秒 也就是讀塊設備。

bo: Blocks sent to a block device (blocks/s).

每秒發送到塊設備的塊數,單位:塊/秒 也就是寫塊設備。

System

in: The number of interrupts per second, including the clock.

每秒的中斷數,包括時鍾中斷

cs: The number of context switches per second.

每秒的環境(上下文)切換次數。比如我們調用系統函數,就要進行上下文切換,而過多的上下文切換會浪費較多的cpu資源,這個數值應該越小越好。

CPU

These are percentages of total CPU time.

us: Time spent running non-kernel code. (user time, including nice time)

用戶CPU時間(非內核進程占用時間)(單位為百分比)。 us的值比較高時,說明用戶進程消耗的CPU時間多

sy: Time spent running kernel code. (system time)

系統使用的CPU時間(單位為百分比)。sy的值高時,說明系統內核消耗的CPU資源多,這並不是良性表現,我們應該檢查原因。

id: Time spent idle. Prior to Linux 2.5.41, this includes IO-wait time.

空閑的CPU的時間(百分比),在Linux 2.5.41之前,這部分包含IO等待時間。

wa: Time spent waiting for IO. Prior to Linux 2.5.41, shown as zero.

等待IO的CPU時間,在Linux 2.5.41之前,這個值為0 .這個指標意味着CPU在等待硬盤讀寫操作的時間,用百分比表示。wait越大則機器io性能就越差。說明IO等待比較嚴重,這可能由於磁盤大量作隨機訪問造成,也有可能磁盤出現瓶頸(塊操作)。

st: Time stolen from a virtual machine. Prior to Linux 2.6.11, unknown.

以上參數中,我們經常關注r列,b列,和wa列,三列代表的意義已經在上邊描述清楚。IO部分的bi、bo也需要參考,如果磁盤io壓力較大,這兩列的數值會比較高。

3.1 vmstat示例

每秒鍾打印一次,共打印五次

Linux:/ # vmstat 1 5

或者

每秒鍾打印一次,一直打印

Linux:/ # vmstat 1

按ctrl + c 可結束


4.top顯示進程所占系統資源

image

這個命令用於動態的監控進程所占資,每3秒鍾刷新一次,這個命令的特點是把所占用的系統資源(CPU、內存、磁盤IO)最高的進程放到前面,在top狀態下,按下“shift+m”可以按照內存使用大小排序,按數字1可以列出各顆CPU的使用狀態。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM