工具 |
功能描述
|
uptime
|
系統平均負載率
|
dmesg
|
硬件/系統信息
|
top
|
進程進行狀態
|
iostat
|
CPU和磁盤平均使用率
|
vmstat
|
系統運行狀態
|
sar
|
實時收集系統使用狀態
|
KDE System Guard
|
圖形監控工具
|
free
|
內存使用率
|
traffic-vis
|
網絡監控(只有SUSE有)
|
pmap
|
進程內存佔用率
|
strace
|
追蹤程序運行狀態
|
ulimit
|
系統資源使用限制
|
mpstat
|
多處理器使用率
|
load average的最佳值是1,說明每個進程都可以馬上處理並且沒有CPU cycles被丟失。對於單CPU的機器,1或者2是可以接受的值;對於多路CPU的機器,load average值可能在8到10之間。
也可以使用uptime命令來判斷網絡性能。例如,某個網絡應用性能很低,通過運行uptime查看服務器的負荷是否很高,如果不是,那麼問題應該是網絡方面造成的。
以下是uptime的運行實例:
9:24am up 19:06, 1 user, load average: 0.00, 0.00, 0.00
也可以查看/proc/loadavg和/proc/uptime兩個文件,注意不能編輯/proc中的文件,要用cat等命令來查看,如:
liyawei:~ # cat /proc/loadavg
0.00 0.00 0.00 1/55 5505
2、dmesg
另外,使用dmesg可以確定您的服務器安裝了那些硬件。每次系統重啓,系統都會檢查所有硬件並將信息記錄下來。執行/bin/dmesg命令可以查看該記錄。
dmesg輸入實例:
ReiserFS: hda6: checking transaction log (hda6)
ReiserFS: hda6: Using r5 hash to sort names
Adding 1044184k swap on /dev/hda5. Priority:-1 extents:1 across:1044184k
parport_pc: VIA 686A/8231 detected
parport_pc: probing current configuration
parport_pc: Current parallel port base: 0x378
parport0: PC-style at 0x378 (0x778), irq 7, using FIFO [PCSPP,TRISTATE,COMPAT,ECP]
parport_pc: VIA parallel port: io=0x378, irq=7
lp0: using parport0 (interrupt-driven).
e100: Intel(R) PRO/100 Network Driver, 3.5.10-k2-NAPI
e100: Copyright(c) 1999-2005 Intel Corporation
ACPI: PCI Interrupt 0000:00:0d.0[A] -> GSI 17 (level, low) -> IRQ 169
e100: eth0: e100_probe: addr 0xd8042000, irq 169, MAC addr 00:02:55:1E:35:91
usbcore: registered new driver usbfs
usbcore: registered new driver hub
hdc: ATAPI 48X CD-ROM drive, 128kB Cache, UDMA(33)
Uniform CD-ROM driver Revision: 3.20
USB Universal Host Controller Interface driver v2.3
3、top
Process priority的數值決定了CPU處理進程的順序。LIUNX內核會根據需要調整該數值的大小。nice value侷限於priority。priority的值不能低於nice value(nice value值越低,優先級越高)。您不可以直接修改Process priority的值,但是可以通過調整nice level值來間接地改變Process priority值,然而這一方法並不是所有時候都可用。如果某個進程運行異常的慢,可以通過降低nice level爲該進程分配更多的CPU。
Linux 支持的 nice levels 由19 (優先級低)到-20 (優先級高),缺省值爲0。
執行/bin/ps命令可以查看到當前進程的情況。
4、iostat
執行iostat命令可以從系統啓動之後的CPU平均時間,類似於uptime。除此之外,iostat還對創建一個服務器磁盤子系統的活動報告。該報告包含兩部分:CPU使用情況和磁盤使用情況。
iostat顯示實例:
avg-cpu: %user %nice %system %iowait %steal %idle
0.16 0.01 0.03 0.10 0.00 99.71
hda 0.31 4.65 4.12 327796 290832
1.00 0.00 0.00 0.00 0.00 100.00
hda 0.00 0.00 0.00 0 0
0.00 0.00 0.00 0.00 0.00 99.01
hda 0.00 0.00 0.00 0 0
CPU佔用情況包括四塊內容
%user:顯示user level (applications)時,CPU的佔用情況。
%nice:顯示user level在nice priority時,CPU的佔用情況。
%sys:顯示system level (kernel)時,CPU的佔用情況。
%idle: 顯示CPU空閒時間所佔比例。
Device: 塊設備的名字
tps: 該設備每秒I/O傳輸的次數。多個I/O請求可以組合爲一個,每個I/O請求傳輸的字節數不同,因此可以將多個I/O請求合併爲一個。
Blk_read/s, Blk_wrtn/s: 表示從該設備每秒讀寫的數據塊數量。塊的大小可以不同,如1024, 2048 或 4048字節,這取決於partition的大小。
dumpe2fs -h /dev/sda1 |grep -F "Block size"
dumpe2fs 1.34 (25-Jul-2003)
Block size: 1024
也可以查看這幾個文件/proc/stat,/proc/partitions,/proc/diskstats的內容。
5、vmstat
procs -----------memory---------- ---swap-- -----io---- -system-- -----cpu------
r b swpd free buff cache si so bi bo in cs us sy id wa st
1 0 0 513072 52324 162404 0 0 2 2 261 32 0 0 100 0 0
0 0 0 513072 52324 162404 0 0 0 0 271 43 0 0 100 0 0
0 0 0 513072 52324 162404 0 0 0 0 255 27 0 0 100 0 0
0 0 0 513072 52324 162404 0 0 0 28 275 51 0 0 97 3 0
0 0 0 513072 52324 162404 0 0 0 0 255 21 0 0 100 0 0
各輸出列的含義:
Process
– r: The number of processes waiting for runtime.
– b: The number of processes in uninterruptable sleep.
Memory
– swpd: The amount of virtual memory used (KB).
– free: The amount of idle memory (KB).
– buff: The amount of memory used as buffers (KB).
Swap
– si: Amount of memory swapped from the disk (KBps).
– so: Amount of memory swapped to the disk (KBps).
IO
– bi: Blocks sent to a block device (blocks/s).
– bo: Blocks received from 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 (these are percentages of total CPU time)
- us: Time spent running non-kernel code (user time, including nice time).
– sy: Time spent running kernel code (system time).
– id: Time spent idle. Prior to Linux 2.5.41, this included IO-wait time.
– wa: Time spent waiting for IO. Prior to Linux 2.5.41, this appeared as zero.
6、sar
sar用於收集、報告或者保存系統活動信息。sar由三個應用組成:sar顯示數據、sar1和sar2用於收集和保存數據。
使用sar1和sar2,系統能夠配置成自動抓取信息和日誌,以備分析使用。配置舉例:在/etc/crontab中添加如下幾行內容
同樣的,你也可以在命令行方式下使用sar運行實時報告。如圖所示:
從收集的信息中,可以得到詳細的CPU使用情況(%user, %nice, %system, %idle)、內存頁面調度、網絡I/O、進程活動、塊設備活動、以及interrupts/second
liyawei:~ # sar -u 3 10
Linux 2.6.16.21-0.8-default (liyawei) 05/31/07
10:17:19 all 0.00 0.00 0.00 0.00 100.00
10:17:22 all 0.00 0.00 0.00 0.33 99.67
10:17:25 all 0.00 0.00 0.00 0.00 100.00
10:17:28 all 0.00 0.00 0.00 0.00 100.00
10:17:31 all 0.00 0.00 0.00 0.00 100.00
10:17:34 all 0.00 0.00 0.00 0.00 100.00
7、KDE System Guard
8、free
total used free shared buffers cached
Mem: 776492 263480 513012 0 52332 162504
-/+ buffers/cache: 48644 727848
Swap: 1044184 0 1044184
9、Traffic-vis
traffic-collector -i eth0 -s /root/output_traffic-collector
可以使用killall命令來控制該進程。如果要將報告寫入磁盤,可使用如下命令:
killall -9 traffic-collector
要停止對信息的收集,執行如下命令:killall -9 traffic-collector
例如根據主機上packets的收/發數量排序,執行命令:
traffic-sort -i output_traffic-collector -o output_traffic-sort -Hp
traffic-tohtml -i output_traffic-sort -o output_traffic-tohtml.html
如要生成GIF格式(600X600)的報告,請運行命令:
traffic-togif -i output_traffic-sort -o output_traffic-togif.gif -x 600 -y 600
技巧和提示:使用管道,可以只需執行一條命令來產生報告。如生成HTML的報告,執行命令:
cat output_traffic-collector | traffic-sort -Hp | traffic-tohtml -o output_traffic-tohtml.html
如要生成GIF文件,執行命令:
cat output_traffic-collector | traffic-sort -Hp | traffic-togif -o output_traffic-togif.gif -x 600 -y 600
10、pmap
pmap <pid>
1: init
START SIZE RSS DIRTY PERM MAPPING
08048000 484K 244K 0K r-xp /sbin/init
080c1000 4K 4K 4K rw-p /sbin/init
080c2000 144K 24K 24K rw-p [heap]
bfb5b000 84K 12K 12K rw-p [stack]
ffffe000 4K 0K 0K ---p [vdso]
Total: 720K 284K 40K
11、strace
使用該命令需要指明進程的ID(PID),例如:
strace -p <pid>
# strace –p 2582
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
read(7, "\"\\\"\\\\\\\"\\\\\\\\\\\\\\\"\\\\\\\\\\\\\\\\\\\\\\\\"..., 16384) = 321
write(3, "}H\331q\37\275$\271\t\311M\304$\317~)R9\330Oj\304\257\327"..., 360) = 360
select(8, [3 4 7], [3], NULL, NULL) = 2 (in [7], out [3])
rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
read(7, "\"\\\"\\\\\\\"\\\\\\\\\\\\\\\"\\\\\\\\\\\\\\\\\\\\\\\\"..., 16384) = 323
write(3, "\204\303\27$\35\206\\\306VL\370\5R\200\226\2\320^\253\253"..., 360) = 360
select(8, [3 4 7], [3], NULL, NULL) = 2 (in [7], out [3])
rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
read(7, "\"\\\"\\\\\\\"\\\\\\\\\\\\\\\"\\\\\\\\\\\\\\\\\\\\\\\\"..., 16384) = 323
write(3, "\243\207\204\277Cw\0162\2ju=\205\'L\352?0J\256I\376\32"..., 360) = 360
select(8, [3 4 7], [3], NULL, NULL) = 2 (in [7], out [3])
rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
read(7, "\"\\\"\\\\\\\"\\\\\\\\\\\\\\\"\\\\\\\\\\\\\\\\\\\\\\\\"..., 16384) = 320
write(3, "6\270S\3i\310\334\301\253!ys\324\'\234%\356\305\26\233"..., 360) = 360
select(8, [3 4 7], [3], NULL, NULL) = 2 (in [7], out [3])
rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
12、ulimit
liyawei:~ # ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
file size (blocks, -f) unlimited
pending signals (-i) 6143
max locked memory (kbytes, -l) 32
max memory size (kbytes, -m) unlimited
open files (-n) 1024
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) 6143
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
-H和-S選項指明所給資源的軟硬限制。如果超過了軟限制,系統管理員會收到警告信息。硬限制指在用戶收到超過文件句炳限制的錯誤信息之前,可以達到的最大值。
例如可以設置對文件句炳的硬限制:ulimit -Hn 4096
例如可以設置對文件句炳的軟限制:ulimit -Sn 1024
查看軟硬值,執行如下命令:
ulimit -Hn
ulimit -Sn
例如限制Oracle用戶. 在/etc/security/limits.conf輸入以下行:
soft nofile 4096
hard nofile 10240
對於Red Hat Enterprise Linux AS,確定文件/etc/pam.d/system-auth包含如下行
session required /lib/security/$ISA/pam_limits.so
對於SUSE LINUX Enterprise Server,確定文件/etc/pam.d/login 和/etc/pam.d/sshd包含如下行:
session required pam_limits.so
這一行使這些限制生效。
13、mpstat
mpstat用於報告多路CPU主機的每顆CPU活動情況,以及整個主機的CPU情況。
例如,下邊的命令可以隔2秒報告一次處理器的活動情況,執行3次
mpstat 2 3
liyawei:~ # mpstat 2 3
Linux 2.6.16.21-0.8-default (liyawei) 05/31/07
10:23:05 all 0.50 0.00 0.00 1.99 0.00 0.00 0.00 97.51 271.64
10:23:07 all 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00 261.00
10:23:09 all 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00 261.50
Average: all 0.17 0.00 0.00 0.67 0.00 0.00 0.00 99.17 264.73
如下命令每隔1秒顯示一次多路CPU主機的處理器活動情況,執行3次
mpstat -P ALL 1 3
liyawei:~ # mpstat -P ALL 1 10
Linux 2.6.16.21-0.8-default (liyawei) 05/31/07
10:23:32 all 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00 273.00
10:23:32 0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00 272.00
10:23:33 all 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00 254.00
10:23:33 0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00 254.00
10:23:34 all 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00 271.00
10:23:34 0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00 271.00
10:23:35 all 0.00 0.00 0.00 1.98 0.00 0.00 0.00 98.02 254.46
10:23:35 0 0.00 0.00 0.00 1.98 0.00