使用Dstat來進行Linux綜合效能診斷

realkid4發表於2015-12-24

 

效能測試、評估和優化一直是系統管理維護人員工作的重點。當我們針對一臺生產應用進行分析的時候,獲取如CPU、記憶體、IO、網路吞吐和程式負載的基礎資料,對於後續的效能評測和優化是至關重要的。

 

Linux作為目前應用最廣泛的伺服器作業系統,為了應對各種效能問題,已經發展出很多原生的效能檢測工具。從topvmstatiostatmpstat,已經可以對作業系統主要效能方面進行詳細的分析。

 

面對越來越複雜的分析情況,我們在實踐中往往需要那種全域性綜合性的效能工具。在一個工具裡面,將所有的資料收集展現在一起。本篇主要介紹一下基於開源架構的dstat效能分析工具。

 

1Dstat下載與安裝

 

Dstat是一個自由開放團體開發的開源軟體,可以從作者網站上下載到,網址為:http://dag.wiee.rs/home-made/dstat/

 

根據不同的作業系統版本,Dstat提供了不同版本的安裝RPM或者其他格式安裝包。筆者系統為紅帽6.5,所以選擇適合版本進行安裝。

 

 

[root@xxx-MIGPC-DB uploads]# uname -a

Linux xxx-MIGPC-DB 2.6.32-358.el6.x86_64 #1 SMP Tue Jan 29 11:47:41 EST 2013 x86_64 x86_64 x86_64 GNU/Linux

 

 

[root@xxx-MIGPC-DB uploads]# ls -l

total 164

-rw-r--r-- 1 root root 164276 Dec  3 09:25 dstat-0.7.2-1.el6.rfx.noarch.rpm

 

 

安裝Dstat及其簡單,藉助rpm工具可以直接安裝。

 

 

[root@xxx-MIGPC-DB uploads]# rpm -ivh dstat-0.7.2-1.el6.rfx.noarch.rpm

warning: dstat-0.7.2-1.el6.rfx.noarch.rpm: Header V3 DSA/SHA1 Signature, key ID 6b8d79e6: NOKEY

Preparing...                ########################################### [100%]

   1:dstat                  ########################################### [100%]

 

 

[root@xxx-MIGPC-DB uploads]# rpm -qa | grep dstat

dstat-0.7.2-1.el6.rfx.noarch

 

 

2Dstat使用方法

 

從官方途徑上,我們可以找到正式的dstathtml格式說明文件。在實際中,我們可以通過help引數來顯示功能引數。

 

 

[root@xxx-MIGPC-DB uploads]# dstat --help

Usage: dstat [-afv] [options..] [delay [count]]

Versatile tool for generating system resource statistics

 

Dstat options:

  -c, --cpu              enable cpu stats

     -C 0,3,total           include cpu0, cpu3 and total

  -d, --disk             enable disk stats

     -D total,hda           include hda and total

  -g, --page             enable page stats

  -i, --int              enable interrupt stats

     -I 5,eth2              include int5 and interrupt used by eth2

  -l, --load             enable load stats

  -m, --mem              enable memory stats

  -n, --net              enable network stats

     -N eth1,total          include eth1 and total

  -p, --proc             enable process stats

  -r, --io               enable io stats (I/O requests completed)

  -s, --swap             enable swap stats

     -S swap1,total         include swap1 and total

  -t, --time             enable time/date output

  -T, --epoch            enable time counter (seconds since epoch)

  -y, --sys              enable system stats

 

  --aio                  enable aio stats

  --fs, --filesystem     enable fs stats

  --ipc                  enable ipc stats

  --lock                 enable lock stats

  --raw                  enable raw stats

  --socket               enable socket stats

  --tcp                  enable tcp stats

  --udp                  enable udp stats

  --unix                 enable unix stats

  --vm                   enable vm stats

 

  --plugin-name          enable plugins by plugin name (see manual)

  --list                 list all available plugins

 

  -a, --all              equals -cdngy (default)

  -f, --full             automatically expand -C, -D, -I, -N and -S lists

  -v, --vmstat           equals -pmgdsc -D total

 

  --float                force float values on screen

  --integer              force integer values on screen

 

  --bw, --blackonwhite   change colors for white background terminal

  --nocolor              disable colors (implies --noupdate)

  --noheaders            disable repetitive headers

  --noupdate             disable intermediate updates

  --output file          write CSV output to file

 

delay is the delay in seconds between each update (default: 1)

count is the number of updates to display before exiting (default: unlimited)

 

 

從引數型別上,我們可以看到Dstat對於作業系統的監控支援是比較全面的,包括CPU、記憶體、磁碟和網路等多個方面。針對不同的監控需要,使用者只需要輸入不同的控制引數,就可以在一個結果集合中進行持續性監控。

 

預設情況下,Dstat監控行為如下:

 

 

[root@xxx-MIGPC-DB uploads]# dstat

You did not select any stats, using -cdngy by default.

----total-cpu-usage---- -dsk/total- -net/total- ---paging-- ---system--

usr sys idl wai hiq siq| read  writ| recv  send|  in   out | int   csw

  1   0  98   0   0   0|1395B   41k|   0     0 |   0    11B| 410  2134

 25   0  75   0   0   0|   0     0 |  60B  378B|   0     0 |2058  2057

 25   0  75   0   0   0|   0    32k| 401B  635B|   0     0 |2112  2128

 26   0  75   0   0   0|   0     0 |  60B  170B|   0     0 |2075  2067

 25   1  75   0   0   0|   0     0 | 303B  170B|   0     0 |2069  2091

 25   0  75   0   0   0|   0    64k| 120B  170B|   0     0 |2042  2052

 25   0  75   0   0   0|   0     0 |  60B  170B|   0     0 |2121  2102

 25   0  75   0   0   0|   0     0 |  60B  170B|   0     0 |2055  2075

 25   1  74   0   0   0|   0    32k| 120B  170B|   0     0 |2091  2094

 

 

預設情況下,採用cdngy引數,監控CPU、磁碟、網路、記憶體分頁和系統統計量。

 

如果需要單項監控,只需要輸入單個引數即可。

 

 

[root@xxx-MIGPC-DB dev]# dstat -c

----total-cpu-usage----

usr sys idl wai hiq siq

  1   0  98   0   0   0

 16   1  83   0   0   0

 16   1  83   0   0   0

 17   2  78   4   0   0

 16   1  83   0   0   0

 

 

如果需要顯示時間,可以通過-t引數來指定。

 

 

[root@xxx-MIGPC-DB dev]# dstat -a -t

----total-cpu-usage---- -dsk/total- -net/total- ---paging-- ---system-- ----system----

usr sys idl wai hiq siq| read  writ| recv  send|  in   out | int   csw |     time    

  1   0  98   0   0   0|1403B   41k|   0     0 |   0    11B| 410  2134 |03-12 10:18:34

 16   1  80   3   0   0|   0  2280k|  53k   99k|   0     0 |2855  3135 |03-12 10:18:35

 16   1  83   0   0   0|   0    32k|  53k  100k|   0     0 |2539  2842 |03-12 10:18:36

 16   1  83   0   0   0|   0     0 |  53k   98k|   0     0 |2504  2799 |03-12 10:18:37

 

 

預設情況是每秒鐘收集一次,如果希望和vmstat類似指定時間間隔和取樣數量,可以直接在後面輸入引數。

 

 

[root@xxx-MIGPC-DB dev]# dstat -at 3 10

----total-cpu-usage---- -dsk/total- -net/total- ---paging-- ---system-- ----system----

usr sys idl wai hiq siq| read  writ| recv  send|  in   out | int   csw |     time    

  1   0  98   0   0   0|1404B   41k|   0     0 |   0    11B| 410  2134 |03-12 10:24:42

 16   1  83   0   0   0|   0    11k|  54k   97k|   0     0 |2513  2828 |03-12 10:24:45

 17   1  83   0   0   0|   0    19k|  53k   96k|   0     0 |2493  2807 |03-12 10:24:48

 17   1  82   0   0   0|   0    16k|  47k   93k|   0     0 |2460  2727 |03-12 10:24:51

 17   1  82   0   0   0|   0    17k|  45k   92k|   0     0 |2423  2683 |03-12 10:24:54

 

 

從經驗看,推薦使用的一種引數是-cdlmnpsy,可以比較充分的顯示系統全貌。

 

 

[root@xxx-MIGPC-DB dev]# dstat -cdlmnpsy

----total-cpu-usage---- -dsk/total- ---load-avg--- ------memory-usage----- -net/total- ---procs--- ----swap--- ---system--

usr sys idl wai hiq siq| read  writ| 1m   5m  15m | used  buff  cach  free| recv  send|run blk new| used  free| int   csw

  1   0  98   0   0   0|1404B   41k|0.12 0.19 0.18|1458M  125M 13.6G  611M|   0     0 |0.0   0 0.4| 286M 7730M| 410  2134

 17   1  82   0   0   0|   0    32k|0.19 0.21 0.18|1458M  125M 13.6G  611M|  51k   98k|  0   0   0| 286M 7730M|2540  2828

 16   1  83   0   0   0|   0     0 |0.19 0.21 0.18|1458M  125M 13.6G  611M|  57k  103k|  0   0   0| 286M 7730M|2530  2862

 17   1  82   0   0   0|   0     0 |0.19 0.21 0.18|1458M  125M 13.6G  611M|  52k   96k|  0   0   0| 286M 7730M|2498  2810

 

 

Dstat還支援將收集結果匯出csv檔案中。

 

 

[root@xxx-MIGPC-DB ~]# dstat -c --output res.csv

----total-cpu-usage----

usr sys idl wai hiq siq

  1   0  98   0   0   0

 18   1  82   0   0   0

 17   1  82   0   0   0

 17   1  82   0   0   0

 18   1  82   0   0   0

 16   1  83   0   0   0

 16   1  83   0   0   0

 16   1  83   0   0   0

 15   1  84   0   0   0

 17   1  83   0   0   0

 

[root@xxx-MIGPC-DB ~]# ls -l | grep res.csv

-rw-r--r--  1 root root  1955 Dec  3 10:28 res.csv

 

 

csv還是比較規整的型別。

 

使用Dstat來進行Linux綜合效能診斷

 

3、結論

 

當我們進行作業系統層面全面監控的時候,Dstat作為一個開源工具,還是比較有實際價值的。


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/17203031/viewspace-1956068/,如需轉載,請註明出處,否則將追究法律責任。

相關文章