If you have a Linux server running at your office or at a data center for which you are responsible, you want to maintain an uptime of as close to a hundred percent.如果您有一個Linux服務器運行在您的辦公室或在數據中心,您有責任,要保持正常運行時間接近百分之百。 In such a case you want to make sure you keep an eye on how the system is running.在這種情況下要確保您留意系統如何運行。 To be precise you want to monitor all the system resources that contribute to the system running fine which then results in a high uptime.要準確要監控所有的系統資源,有助於該系統運行良好的結果,然後在一個高的正常運行時間。 Memory, CPU, disk usage… are some of the things you want to observe.內存,處理器,磁盤使用...有一些事情要觀察。 We would usually use a combination of the tools that come with a Linux or UNIX installation, such as “free”, “top”, “vmstat”… I’ll introduce you to a tool that gives you just about all the info that the other tools combined give you, all under one roof - Dstat.我們通常會結合使用的工具,來了一個Linux或UNIX安裝,如“自由” , “頂級” , “ vmstat ” ...我會向您介紹一個工具,讓您剛才的所有信息的其他工具結合起來給你,所有的同一個屋簷下-D stat。 The developer of this command line tool, Dag Wieers, calls it “a versatile replacement for vmstat, iostat, netstat and ifstat”.開發商的這一命令行工具,達格哈馬Wieers ,將其稱為“多面手更換vmstat , iostat , netstat和ifstat ” 。 He adds that “Dstat overcomes some of their limitations and adds some extra features…” To me Dstat is the mother of all command line system monitoring tools.他補充說, “ Dstat克服了它們的某些限制,並增加了一些額外的功能... ”對我來說Dstat是母親的所有命令行系統監測工具。 It’s simple to install, easy to use, can be tweaked with ease, and it generates reports that you can plot as a graph to impress your boss.它安裝簡單,易於使用,可以輕鬆地調整,並生成報告,可以作為一個陰謀圖你的老闆留下深刻的印象。
Installing Dstat安裝Dstat
Start by downloading the Dstat installer.開始下載Dstat安裝。 Point your web browser to the Dstat project’s homepage -點你的網絡瀏覽器的Dstat項目的主頁- http://dag.wieers.com/home-made/dstat/ . 。 Scroll down to the section of the page where the downloads are listed.向下滾動到部分的網頁下載列。 Pick the flavor of Linux on which you want to install the application and click on the download link.挑選風味的Linux要安裝的應用,並點擊下載鏈接。 Now download the latest version of Dstat for the version of the Linux distribution you are running.現在下載最新版本的Dstat的版本的Linux分佈您正在運行。 I’ll show you how to do it for a Red Hat Enterprise Linux version 4 machine:我會告訴您如何做到這一點的紅帽企業Linux第4版機:
# wget http://dag.wieers.com/rpm/packages/dstat/dstat-0.6.6-1.el4.rf.noarch.rpm # wget http://dag.wieers.com/rpm/packages/dstat/dstat-0.6.6-1.el4.rf.noarch.rpm
Now install Dstat:現在安裝Dstat :
# rpm -Uvh dstat-0.6.6-1.el4.rf.noarch.rpm #更高Uvh dstat - 0.6.6 - 1.el4.rf.noarch.rpm
If the installation went though without errors, that’s it, you have Dstat installed and ready for use.如果安裝了但沒有錯誤,就是這樣,你Dstat安裝好且可以使用。 If there were some dependencies that came up during the installation just install the required packages and try again.如果有一些相依來到了在安裝過程中只安裝所需的軟件包,然後再試一次。 I don’t think that Dstat has too many dependencies, so you should not face any problems.我不認為Dstat有太多依賴,所以你不應該遇到任何問題。
Using Dstat使用Dstat
With Dstat installed on your system you should be good to go.隨著Dstat安裝在您的系統你要善於去。 Begin by launching the command from a terminal:首先啟動的命令從一個終端:
# dstat # dstat
The output would be something like the following.輸出將類似於以下。 Hit the key combination of ctrl+c to exit.命中關鍵結合按Ctrl + C退出。
# dstat # dstat
—-total-cpu-usage—- -disk/total -net/total- —paging– —system– -總的C PU使用率- -d isk/total-n et/total-,傳呼,系統
usr sys idl wai hiq siq|_read write|_recv _send|__in_ _out_|_int_ _csw_系統語言遭圍hiq siq | _read寫| _recv _send | __in_ _out_ | _int_ _csw_
7 1 91 1 0 0| 0 0 | 0 0 | 0 0 | 0 0 7條1 91 1 0 0 | 0 0 | 0 0 | 0 0 | 0 0
1 0 99 0 0 0| 0 0 | 0 0 | 0 0 |1051 1945 1 0 99 0 0 0 | 0 0 | 0 0 | 0 0 | 1051年1945年
0 0 100 0 0 0| 0 12k|2269B 11.2k| 0 0 |1031 1923 0 0 100 0 0 0 | 0 12,000 | 2269B 11.2k | 0 0 | 1031年1923年
1 0 99 0 0 0| 0 40k| 0 0 | 0 0 |1078 2235 1 0 99 0 0 0 | 0 40K的| 0 0 | 0 0 | 1078 2235
0 0 100 0 0 0| 0 16k|6027B 21.5k| 0 0 |1008 2219 0 0 100 0 0 0 | 0最大16K | 6027B 21.5k | 0 0 | 1008年2219年
There are a number of options available for Dstat.有一些可供選擇Dstat 。 As I mentioned earlier Dstat is quite easy to tweak.正如我前面提到Dstat很容易調整。 So if you want to limit the data reading to the CPU, disk, and network, run the following command:所以,如果你想限制數據讀的CPU ,硬盤和網絡,運行下面的命令:
# dstat -CDN # dstat -原價
-disk/total -net/total- —paging– —system– -disk/total -net/total- ,傳呼,系統
_read write|_recv _send|__in_ _out_|_int_ _csw_ _read寫| _recv _send | __in_ _out_ | _int_ _csw_
0 0 | 0 0 | 0 0 | 0 0 0 0 | 0 0 | 0 0 | 0 0
0 12k|2295B 9603B| 0 0 |1053 1957 0 12,000 | 2295B 9603B | 0 0 | 1053年1957年
0 0 | 594B 0 | 0 0 |1002 1893 0 0 | 594B 0 | 0 0 | 1002年1893年
0 960k| 292B 3346B| 0 0 |1072 2012 0 960k | 292B 3346B | 0 0 | 1072年2012年
0 4096B| 64B 0 | 0 0 |1031 1939 0 4096B |個64 0 | 0 0 | 1031年1939年
You can find more options in the application’s help document which you can access by entering the following:您可以找到更多的選擇的應用程序的幫助文件,您可以通過輸入以下內容:
# dstat -h # dstat小時
Play with the options a little so you get comfortable with them.播放的選項一點,讓您獲得舒適與他們。 The default interval between data reads is two seconds.預設的間隔讀取數據是2秒。 You can change that interval if you need to.你可以改變這一區間如果您需要。 To increase the interval to ten seconds enter the following:為了增加間隔十秒輸入以下內容:
# dstat 10 # dstat 10個
Another useful feature is to get aggregated updates for each entry.另一個有用的功能就是要更新匯總每個條目。 So you can have Dstat give you an update every ten seconds in a new line, but as the data changes your line itself gets updated every second.所以,你可以有Dstat給你一個更新每10秒一個新行,但作為數據變化的路線本身更新一次獲得第二。
You might optionally want Dstat to give you five updates with a frequency of three seconds.你可能會選擇想要Dstat給你5個更新的頻率3秒。 Here’s how you would go about doing that:以下是如何你會去這樣做:
# dstat 3 5 # dstat 3月5日
—-total-cpu-usage—- -disk/total -net/total- —paging– —system– -總的C PU使用率- -d isk/total-n et/total-,傳呼,系統
usr sys idl wai hiq siq|_read write|_recv _send|__in_ _out_|_int_ _csw_系統語言遭圍hiq siq | _read寫| _recv _send | __in_ _out_ | _int_ _csw_
3 1 95 2 0 0| 0 0 | 0 0 | 0 0 | 0 0 1月3日95 2 0 0 | 0 0 | 0 0 | 0 0 | 0 0
2 11 87 1 0 0| 0 180k|2581B 3239B| 0 0 |1136 697 2月11日87 1 0 0 | 0 180,000 | 2581B 3239B | 0 0 | 1136 697
7 8 85 0 0 0| 0 0 | 115k 106k| 0 0 |1603 3985 7月8日85 0 0 0 | 0 0 | 115k 106k | 0 0 | 1603年3985
2 1 98 0 0 0| 0 0 |77.5k 170k| 0 0 |1744 3856 2月1日98 0 0 0 | 0 0 | 77.5k 82 | 0 0 | 1744 3856
1 0 100 0 0 0| 0 0 |3451B 9993B| 0 0 |1045 149 1 0 100 0 0 0 | 0 0 | 3451B 9993B | 0 0 | 10時45分149
2 1 94 4 0 0| 0 276k|20.4k 31.1k| 0 0 |1219 804 2月1日94 4 0 0 | 0 276k | 20.4k 31.1k | 0 0 | 1219 804
The feature that I find most useful is the output.這項功能,我認為最有用的是輸出。 Dstat allows you to have the output of a session written into a comma separated file which can later be imported into a spreadsheet application such as Microsoft Excel and the data can be plotted into a graph. Dstat可以讓你的輸出寫入會議逗號分隔文件,該文件可以在以後導入到電子表格應用程序,如Microsoft Excel中的數據可以繪製成圖表。 Here is how it can be used.下面是它如何被使用。
# dstat –output /tmp/dstat_data.csv -CDN # dstat輸出/ tmp的/ dstat_data.csv -原價
Let the above command run while you run your applications or do your testing on this machine.讓執行上述命令時,運行您的應用程序或做您的測試本機上。 Hit the key combination of ctrl+c when you are done.命中關鍵結合按Ctrl + C當你做。 Open the file dstat_data.csv with a spreadsheet application such as Microsoft Excel or Open Office.打開文件dstat_data.csv與試算表應用程式如Microsoft Excel或開放式辦公。 You can then select the columns you want plotted into a graph and let your spreadsheet application do the magic.然後,您可以選擇您想要欄繪製成圖表,讓您的電子表格應用程序做的魔力。
Get a Report by Mail收到郵件的報告
There may be cases wherein you want to observe how your server is performing over a period of time.有可能出現這樣的情況,其中你想觀察一下您的服務器正在執行一段時間。 You can setup a background process in Linux that will give you a reading with a certain interval, generate a report, and mail out the file to you.您可以設置一個後台進程在Linux中,將讓您閱讀具有一定的間隔,產生了一份報告,並郵寄出的檔案給你。 This can be especially useful during a stress-test.這可能是特別有用在應力測試。 Here’s how you could do that.以下是你可以做到這一點。 The following script will run Dstat for three hours, reading the data every 30 seconds, and will mail out the report to me@myemailid.com.下面的腳本將運行Dstat了三個小時,閱讀的數據,每30秒,並將郵件的報告me@myemailid.com 。
#!/bin/bash # ! /斌/慶祝
dstat –output /tmp/dstat_data_mail.csv -CDN 30 360 dstat輸出/ tmp的/ dstat_data_mail.csv - 30原價360
mutt -a /tmp/dstat_data_mail.csv -s “Dstat Report for 3 hour run” me@myemailid.com < /dev/null傻子一個/ tmp的/ dstat_data_mail.csv比較“ Dstat報告3小時運行” me@myemailid.com “的/ dev /無效
Save the above script in a file called dstat_script.sh on your server, give it executable permission and then run it as a background process:除上述腳本在一個名為dstat_script.sh在您的服務器上,給它可執行權限,然後運行它作為背景的過程:
# chmod +x dstat_script.sh #屬性+ x的dstat_script.sh
# nohup ./dstat_script.sh & # nohup 。 / dstat_script.sh &
Done.做完。 Yes, it’s that simple.是啊,這麼簡單。 You will now be mailed this report after it’s done running.現在,您將寄出這份報告後的工作運行。 You can optionally schedule this script as a daily cron job so that you can receive this data every day.您可以選擇這個劇本的時間表作為日常作業,讓您可以收到這個數據每天都在。
As you may already have realized Dstat is a wonderful tool when applied to performance monitoring and debugging.正如你可能已經意識到Dstat是一種非常棒的工具,當適用於執行情況的監測和調試。 The granularity, frequency, and nature of the data collected are completely up to you.粒度,頻率和性質,所收集的數據是完全取決於您。 Dstat empowers you to know what is going on on your server. Dstat賦予你知道是怎麼回事就在您的服務器上。 Used wisely this power can result in a lot less sleepless nights for you.明智地使用這種權力會導致少很多不眠之夜你。






















{ 0 comments… ( 0評論... add one now現在添加一個 } )
Leave a Comment發表您的評論