學習如何使用Dstat工具監控Linux伺服器效能?
Dstat是一個多功能的資源統計工具。它結合了iostat、vmstat、netstat和ifstat的功能。Dstat允許我們即時監控伺服器資源。當您需要即時收集這些資訊時,Dstat將滿足您的需求。本文解釋瞭如何使用Dstat工具監控Linux伺服器效能。
特性
- 它結合了vmstat、iostat、ifstat、netstat的資訊以及更多
- 它以完全相同的時間間隔顯示統計資料
- 它能夠啟用/排序計數器,使其在評估/故障排除期間最有意義
- 它採用模組化設計
- 這是一個Python程式,因此很容易根據手頭的任務進行擴充套件
- 它非常易於擴充套件,可以新增您自己的計數器(請貢獻這些計數器)
- 它包含許多外部外掛,以展示新增計數器的簡易性
- 它可以彙總分組的塊/網路裝置並提供總數
- 它顯示每個裝置的中斷次數
安裝Dstat
要安裝Dstat,請使用以下命令:
$ sudo apt install dstat
示例輸出應如下所示:
Reading package lists... Done Building dependency tree Reading state information... Done The following NEW packages will be installed: dstat 0 upgraded, 1 newly installed, 0 to remove and 284 not upgraded. Need to get 41.7 kB of archives. After this operation, 351 kB of additional disk space will be used. Get:1 http://in.archive.ubuntu.com/ubuntu xenial/universe amd64 dstat all 0.7.2-4 [41.7 kB] Fetched 41.7 kB in 0s (87.5 kB/s) Selecting previously unselected package dstat. (Reading database ... 174827 files and directories currently installed.) Preparing to unpack .../archives/dstat_0.7.2-4_all.deb ... Unpacking dstat (0.7.2-4) ... Processing triggers for man-db (2.7.5-1) ... Setting up dstat (0.7.2-4) ...
要獲取有關Dstat的更多資訊,請使用以下命令:
$ dstat -h
示例輸出應如下所示:
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 ...................................................................................
Dstat的使用
要執行Dstat,請使用以下命令:
$ dstat
示例輸出應如下所示:
----total-cpu-usage---- -dsk/total- -net/total- ---paging-- ---system-- usr sys idl wai hiq siq| read writ| recv send| in out | int csw 21 5 68 6 0 0| 14M 90k| 0 0 | 64B 1840B|1108 2264 3 4 93 0 0 0| 0 0 | 0 0 | 0 0 | 246 278 1 1 98 0 0 0| 0 0 | 369B 132B| 0 0 | 225 280 12 5 83 0 0 0| 0 100k|1099B 6597B| 0 0 | 719 1593 30 6 63 1 0 0| 0 24k| 303B 0 | 0 0 |1639 4309 4 2 91 3 0 0| 0 180k| 920B 65B| 0 0 | 728 1105 3 1 96 0 0 0| 0 0 | 126B 66B| 0 0 | 335 467 2 1 97 0 0 0| 0 0 | 60B 0 | 0 0 | 239 303 2 1 98 0 0 0| 0 72k| 568B 0 | 0 0 | 244 283 3 3 95 0 0 0| 0 0 | 304B 0 | 0 0 | 535 790 9 2 89 0 0 0| 0 0 | 60B 0 | 0 0 | 789 1431 14 6 79 2 0 0| 0 52k| 60B 0 | 0 0 |1243 2266 35 8 57 0 0 0| 0 0 | 180B 0 | 0 0 |1351 4002 11 2 87 1 0 0| 0 0 | 180B 0 | 0 0 | 674 1326 11 3 86 0 0 0| 0 0 | 60B 0 | 0 0 | 661 1563 8 2 90 0 0 0| 0 0 | 60B 0 | 0 0 | 625 1278 6 2 92 0 0 0| 0 0 | 120B 0 | 0 0 | 423 825 14 3 82 1 0 0| 0 16k| 180B 0 | 0 0 | 807 1789 18 4 78 0 0 0| 0 0 | 263B 81B| 0 0 |1310 2984 17 4 80 0 0 0| 0 0 | 186B 66B| 0 0 |1047 2489 19 5 77 0 0 0| 0 0 | 970B 1969B| 0 0 |1124 2647 16 7 77 0 0 0| 0 0 | 120B 0 | 0 0 |1146 2532 19 6 75 0 0 0| 0 0 | 120B 0 | 0 0 |1099 2657 ...............................................................................
CPU使用率
要獲取CPU使用率,請使用以下命令:
$ dstat -c
示例輸出應如下所示:
----total-cpu-usage---- usr sys idl wai hiq siq 21 5 68 6 0 0 3 0 97 0 0 0 2 1 97 0 0 0 3 3 93 2 0 0 5 2 93 0 0 0 9 5 86 0 0 0 19 8 71 2 0 0 37 8 54 0 0 0 11 3 86 0 0 0 13 3 83 0 0 0 16 5 78 1 0 0 17 5 77 1 0 0 16 4 80 0 0 0 ............................................
記憶體使用率
要獲取伺服器的記憶體使用率,請使用以下命令:
$ dstat -m
示例輸出應如下所示:
------memory-usage----- used buff cach free 2249M 89.2M 800M 238M 2248M 89.2M 801M 238M 2249M 89.2M 798M 240M 2249M 89.2M 798M 240M 2248M 89.2M 798M 241M 2248M 89.2M 798M 241M 2248M 89.2M 798M 241M 2248M 89.2M 798M 241M 2248M 89.3M 798M 241M 2248M 89.3M 798M 241M ............................................
網路統計資訊
要獲取網路統計資訊,請使用以下命令:
$ dstat -n
示例輸出應如下所示:
-net/total- recv send 0 0 120B 0 360B 0 120B 0 0 0 428B 0 304B 0 120B 0 184B 0 194B 65B ....................................................
閱讀完本文後,您將能夠理解如何使用Dstat工具監控Linux伺服器效能。在我們的下一篇文章中,我們將介紹更多基於Linux的技巧和提示。繼續閱讀!
廣告
資料結構
網路
關係型資料庫管理系統 (RDBMS)
作業系統
Java
iOS
HTML
CSS
Android
Python
C語言程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP