天天看點

Linux伺服器性能資料收集 - Sysstat介紹

從http://pagesperso-orange.fr/sebastien.godard/download.html下載下傳最新版本,解壓,安裝

 wget http://pagesperso-orange.fr/sebastien.godard/sysstat-8.1.2.tar.gz

 tar zxvf sysstat-8.1.2.tar.gz

 cd sysstat-8.1.2

 ./configure

 make

 su

 <enter root password>

 make install

通過ps指令找到相應程序的PID: 

Linux伺服器性能資料收集 - Sysstat介紹

ps -e

pidstat 2 5 

//每隔2秒,顯示5次,所有活動程序的CPU使用情況

pidstat -p 3132 2 5 

//每隔2秒,顯示5次,PID為1643的程序的CPU使用情況顯示

pidstat -p 3132 2 5 -r

//每隔2秒,顯示5次,PID為1643的程序的記憶體使用情況顯示

很可惜的是,pidstat指令沒有儲存性能資料的功能。

在sysstat工具包中,sar是最強大的了,通過sar幾乎可以監視所有的性能資料,同時,sar還支援将性能資料儲存起來。

檢視CPU使用情況 

Linux伺服器性能資料收集 - Sysstat介紹

sar 2 5

Linux伺服器性能資料收集 - Sysstat介紹

//每隔2秒,顯示5次,CPU使用的情況

檢視記憶體使用情況 

Linux伺服器性能資料收集 - Sysstat介紹

sar -r 2 5

Linux伺服器性能資料收集 - Sysstat介紹

//每隔2秒,顯示5次,記憶體使用的情況

檢視網絡吞吐量 

Linux伺服器性能資料收集 - Sysstat介紹

sar -n DEV 2 5

Linux伺服器性能資料收集 - Sysstat介紹

//每隔2秒,顯示5次,網絡吞吐量情況

sar支援儲存成兩種格式的檔案,一種是文本檔案,一種是二進制檔案(隻有通過sar自己的指令才能檢視)。

儲存為文本檔案

結合上面的檢視指令,加入 > filename 參數即可儲存文本檔案,下面列出幾個有用的指令:

Linux伺服器性能資料收集 - Sysstat介紹

sar 1 10 > data.txt

Linux伺服器性能資料收集 - Sysstat介紹

//每隔1秒,寫入10次,把CPU使用資料儲存到data.txt檔案中。

Linux伺服器性能資料收集 - Sysstat介紹

sar 1 0 -e 15:00:00 > data.txt

Linux伺服器性能資料收集 - Sysstat介紹

//每隔1秒記錄CPU的使用情況,直到15點,資料将儲存到data.txt檔案中。(-e 參數表示結束時間,注意時間格式:必須為hh:mm:ss格式)

Linux伺服器性能資料收集 - Sysstat介紹

sar 1 0 -r -e 15:00:00 > data.txt

Linux伺服器性能資料收集 - Sysstat介紹

//每隔1秒記錄記憶體使用情況,直到15點,資料将儲存到data.txt檔案中。

Linux伺服器性能資料收集 - Sysstat介紹

sar 1 0 -n DEV -e 15:00:00 > data.txt

Linux伺服器性能資料收集 - Sysstat介紹

//每隔1秒記錄網絡使用情況,直到15點,資料将儲存到data.txt檔案中。

用WinSCP工具從Linux伺服器上取下data.txt檔案,内容如下:

Linux伺服器性能資料收集 - Sysstat介紹

Linux 2.6.18-53.el5 (Performancesvr5)  2008年05月05日     _x86_64_

Linux伺服器性能資料收集 - Sysstat介紹
Linux伺服器性能資料收集 - Sysstat介紹

 11時04分05秒     CPU     %user     %nice   %system   %iowait    %steal     %idle

Linux伺服器性能資料收集 - Sysstat介紹

 11時04分06秒     all      0.25      0.00      0.00      0.00      0.00     99.75

Linux伺服器性能資料收集 - Sysstat介紹

 11時04分07秒     all      0.00      0.00      0.25      0.00      0.00     99.75

Linux伺服器性能資料收集 - Sysstat介紹

 11時04分08秒     all      0.25      0.00      0.25      1.50      0.00     98.00

Linux伺服器性能資料收集 - Sysstat介紹

 11時04分09秒     all      0.25      0.00      0.00      0.50      0.00     99.25

Linux伺服器性能資料收集 - Sysstat介紹

 11時04分10秒     all      0.00      0.00      0.00      0.00      0.00    100.00

Linux伺服器性能資料收集 - Sysstat介紹

 11時04分11秒     all      0.25      0.00      0.25      0.00      0.00     99.50

Linux伺服器性能資料收集 - Sysstat介紹

 11時04分12秒     all      0.00      0.00      0.25      0.00      0.00     99.75

Linux伺服器性能資料收集 - Sysstat介紹

 11時04分13秒     all      0.50      0.00      0.50      0.99      0.00     98.01

Linux伺服器性能資料收集 - Sysstat介紹

 11時04分14秒     all      0.00      0.00      0.00      1.25      0.00     98.75

Linux伺服器性能資料收集 - Sysstat介紹

 11時04分15秒     all      0.50      0.00      0.00      0.00      0.00     99.50

Linux伺服器性能資料收集 - Sysstat介紹

 平均時間:     all      0.20      0.00      0.15      0.42      0.00     99.23

有了這份資料,就可以輕松的使用WPS表格來統計CPU的使用情況了。

儲存為二進制檔案

由于儲存的二進制檔案隻有sar通過-f參數才能打開,不利于我們分析和統計資料,是以不推薦使用這個方法。儲存二進制檔案的參數是-o,如:

Linux伺服器性能資料收集 - Sysstat介紹

sar 1 5 -r -o data

Linux伺服器性能資料收集 - Sysstat介紹

//每隔1秒,寫入5次,将記憶體使用的資料寫入二進制檔案data中。

Linux伺服器性能資料收集 - Sysstat介紹

sar -f data

Linux伺服器性能資料收集 - Sysstat介紹

//檢視data檔案

        官方資料:http://pagesperso-orange.fr/sebastien.godard/documentation.html

本文轉自CoderZh部落格園部落格,原文連結:http://www.cnblogs.com/coderzh/archive/2008/05/05/1183125.html,如需轉載請自行聯系原作者

繼續閱讀