CentOS系統資源監控軟件四大軟件
一、進程信息
二、ps命令
ps -報告系統進程運行時狀態。
ps [選項]:
選項有三種風格:風格不一樣寫法不一樣,有的加-,有的不加,比較特殊。
UNIX 風格選項, 可以組團選擇,但必須以“-”開頭
BSD 風格選項, 可以組團選擇,但不能以“-”開頭
GNU 風格選項, 必須以兩個“-”開頭
選項1:BSD風格選項
a:所有與終端相關的進程;
x:所有與終端無關的進程;
u:以用戶爲中心組織進程狀態信息顯示;
常用組合之一:aux
# ps aux USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.0 0.1 19364 1588 ? Ss Mar28 0:01 /sbin/init root 2 0.0 0.0 0 0 ? S Mar28 0:00 [kthreadd] root 3 0.0 0.0 0 0 ? S Mar28 0:00 [migration/0] root 4 0.0 0.0 0 0 ? S Mar28 0:00 [ksoftirqd/0] root 5 0.0 0.0 0 0 ? S Mar28 0:00 [stopper/0] root 6 0.0 0.0 0 0 ? S Mar28 0:00 [watchdog/0] root 7 0.0 0.0 0 0 ? S Mar28 0:37 [events/0] root 8 0.0 0.0 0 0 ? S Mar28 0:00 [cgroup] root 9 0.0 0.0 0 0 ? S Mar28 0:00 [khelper] ... ...
顯示結果字段:
%CPU:累計CPU時間比例;
%MEM:佔總內存比例;
VSZ:虛擬內存集;
RSS:Resident Size,常駐內存集;不能被放到交換內存上的部分。
STAT:BSD風格
R:running or runnable
S:interruptable sleeping
D:uninterruptable sleeping
T:Stopped
Z:zombie
+:前臺進程
l:多線程進程
N:低優先級進程
<:高優先級進程
s:session leader 會話主導進程
選項2:unix風格
-e:顯示所有進程
-f:顯示完整格式的進程信息
-F:顯示完整格式的進程信息;
-H:以層級結構顯示進程的相關信息;
常用組合之二:-ef
# ps -eF|head -10 UID PID PPID C SZ RSS PSR STIME TTY TIME CMD root 1 0 0 4841 1588 0 Mar28 ? 00:00:01 /sbin/init root 2 0 0 0 0 0 Mar28 ? 00:00:00 [kthreadd] root 3 2 0 0 0 0 Mar28 ? 00:00:00 [migration/0] root 4 2 0 0 0 0 Mar28 ? 00:00:00 [ksoftirqd/0] root 5 2 0 0 0 0 Mar28 ? 00:00:00 [stopper/0] root 6 2 0 0 0 0 Mar28 ? 00:00:00 [watchdog/0] root 7 2 0 0 0 0 Mar28 ? 00:00:37 [events/0] root 8 2 0 0 0 0 Mar28 ? 00:00:00 [cgroup] root 9 2 0 0 0 0 Mar28 ? 00:00:00 [khelper]
顯示結果字段分析
PSR:運行於哪顆CPU之上
C:cpu utilization
stime:啓動時間
time:總時間
常用組合之三:-eFH
# ps -eFH |head -3 UID PID PPID C SZ RSS PSR STIME TTY TIME CMD root 2 0 0 0 0 0 3月22 ? 00:00:00 [kthreadd] root 3 2 0 0 0 0 3月22 ? 00:00:10 [ksoftirqd/0]
常用組合之四:-eo, axo
-o field1, field2,...:自定義要顯示的字段列表,以逗號分隔;
常用的field:pid, ni, pri, psr, pcpu, stat, comm, tty, ppid, rtprio
ni:nice值;
priority:priority, 優先級;
rtprio:real time priority,實時優先級;
# ps -eo pid,ppid,ni,priority,comm|head -10 PID PPID NI PRI COMMAND 1 0 0 20 init 2 0 0 20 kthreadd 3 2 - -100 migration/0 4 2 0 20 ksoftirqd/0 5 2 - -100 stopper/0 6 2 - -100 watchdog/0 7 2 0 20 events/0 8 2 0 20 cgroup 9 2 0 20 khelper
三、top命令:
top - display Linux tasks,動態排序的,默認以CPU排序
# top -n 1 -d 3 top - 06:38:09 up 11:19, 3 users, load average: 0.00, 0.00, 0.00 Tasks: 149 total, 1 running, 148 sleeping, 0 stopped, 0 zombie Cpu(s): 0.3%us, 0.3%sy, 0.0%ni, 99.0%id, 0.4%wa, 0.0%hi, 0.1%si, 0.0%st Mem: 1004348k total, 901860k used, 102488k free, 54220k buffers Swap: 2031612k total, 0k used, 2031612k free, 631540k cached PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 1 root 20 0 19364 1588 1268 S 0.0 0.2 0:01.95 init 2 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kthreadd 3 root RT 0 0 0 0 S 0.0 0.0 0:00.00 migration/0 4 root 20 0 0 0 0 S 0.0 0.0 0:00.30 ksoftirqd/0 5 root RT 0 0 0 0 S 0.0 0.0 0:00.00 stopper/0 6 root RT 0 0 0 0 S 0.0 0.0 0:00.33 watchdog/0 7 root 20 0 0 0 0 S 0.0 0.0 0:38.21 events/0 8 root 20 0 0 0 0 S 0.0 0.0 0:00.00 cgroup 9 root 20 0 0 0 0 S 0.0 0.0 0:00.00 khelper 10 root 20 0 0 0 0 S 0.0 0.0 0:00.00 netns 11 root 20 0 0 0 0 S 0.0 0.0 0:00.00 async/mgr 12 root 20 0 0 0 0 S 0.0 0.0 0:00.00 pm
top - 21:25:19 up 2 days, 11:38,
2 users, # 在線用戶
load average: 0.00, 0.00, 0.00 # 等待運行隊列長度,長期單個CPU超過3,表明CPU不夠用了
Tasks: 136 total,
1 running, 135 sleeping, 0 stopped, 0 zombie
Cpu(s):
0.0%us, #用戶空間
0.3%sy, #系統空間
0.0%ni, #優先級用戶運行比例
99.7%id, #空閒百分比
0.0%wa, #等待I/O時間
0.0%hi, #硬件中斷時間
0.0%si, #軟件中斷時間
0.0%st #被偷走的時間---虛擬化偷走CPU時間
Mem: 1004348k total, 679264k used, 325084k free, 143004k buffers
Swap: 2031612k total, 0k used, 2031612k free, 222668k cached
首部信息調整:
uptime信息:l鍵開啓或關閉顯示
tasks及cpu信息:t鍵調整顯示
內存信息:m鍵調整顯示
CPU信息分CPU顯示:1鍵開啓或關閉顯示
修改刷新時間間隔:秒爲單位,默認爲3s
終止指定的進程:k
退出命令:q
選項:
-d #:指定刷新時間間隔,默認爲3秒;怎麼退出?q
-b:以批次方式顯示;
-n #:顯示多少批次;
四、htop命令
top升級版,方便好用的top,額外安裝
選項:
-d #:指定延遲時間間隔;
-u UserName:僅顯示指定用戶的進程;
-s COLUME:以指定字段進行排序;
子命令:
l:顯示選定的進程打開的文件列表;
s:跟蹤選定的進程的系統調用;
t:以層級關係顯示各進程狀態;
a:將選定的進程綁定至某指定的CPU核心;
dstat命令:集大成的資源監控原件
- versatile tool for generating system resource statistics
dstat [-afv] [options..] [delay [count]]
常用選項:
-c, --cpu:顯示cpu相關信息;
-C #,#,...,total:顯示CPU某個核心的相關信息
-d, --disk:顯示磁盤的相關信息
-D sda,sdb,...,tobal
-g:顯示page相關的速率數據;
-m:Memory的相關統計數據
-n:Interface的相關統計數據;
-p:顯示process的相關統計數據;
-r:顯示io請求的相關的統計數據;
-s:顯示swapped的相關統計數據;
--tcp
--udp
--raw
--socket
--ipc
--top-cpu:顯示最佔用CPU的進程;
--top-io:最佔用io的進程;
--top-mem:最佔用內存的進程;
--top-lantency:延遲最大的進程;
# dstat -dmnrs
-dsk/total- ------memory-usage----- -net/total- --io/total- ----swap---
read writ| used buff cach free| recv send| read writ| used free
5891B 18k| 273M 0 577M 128M| 0 0 |0.25 0.60 |1176k 1023M