天天看點

Linux伺服器性能資料收集

Linux中的top,free等指令不能完全滿足我們性能資料收集的要求,我們需要一個更加強大的工具來收集性能資料。

經過考察和對比,發現 Sysstat是一個非常強大的工具,是以下載下傳了試了下,效果不錯。Sysstat是一個工具集,

包括sar、pidstat、iostat、mpstat、sadf、sadc。 其中sar是其中最強大,也是最能符合我們測試要求的工具,

同時pidstat也是非常有用的東東,是以本文結合性能測試重點介紹這兩個工具。

Sysstat的安裝

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

wget http://pagesperso-orange.fr/sebastien.godard/sysstat-9.1.7.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:

ps - e

使用pidstat指令監視程序 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指令沒有儲存性能資料的功能。

檢視性能資料

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

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

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

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

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

sar 1 0 - e 15 : 00 : 00 > data.txt// 每隔1秒記錄CPU的使用情況,直到15點,資料将儲存到data.txt檔案中。

(-e 參數表示結束時間,注意時間格式: 必須為 hh:mm:ss格式)

sar 1 0 - r - e 15 : 00 : 00 > data.txt // 每隔1秒記錄記憶體使用情況,直到15點,資料将儲存到data.txt檔案中。

sar 1 0 - n DEV - e 15 : 00 : 00 > data.txt  // 每隔1秒記錄網絡使用情況,直到15點,資料将儲存到data.txt檔案中。

儲存為二進制檔案

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

儲存二進制檔案的參數是-o,如:

sar 1 5 - r - o data

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

sar - f data

// 檢視data檔案

Sar能工作,/proc目錄必須被mount上來

CPU

-u

-P

記憶體

-r

-R

Block device情況 -d
I/O -b
頁交換情況 -B
程序 -c
網絡 -n
機器負載 -q
Swap -W
全部的資訊 -A

CPU使用率 – 預設

Report CPU utilization

-u

%user: Percentage of CPU utilization that occurred while exe cuting at the user level (application).

%nice:at the user level with nice priority

%system:at the system level (kernel).

%iowait:Percentage of time that the CPU or CPUs were idle during which the system had an outstanding disk I/O request

%idle: Percentage of time that the CPU or CPUs were idle and the system did not have an outstanding disk I/O request

CPU情況 -P cpu | ALL

統計單個或多個cpu的情況

ALL:再加上整體統計情況

-u 和–I SUM 2個參數跟着-P有意義。

記憶體使用率

Report memory and swap space utilization statistics

-r

所有的數量機關: kbytes

Kbmemfree、Kbmemused、%memused:

記憶體空閑、使用了,使用的%

Kbbuffers:核心當作buffer使用的記憶體

Kbcached::核心當作cache data使用的記憶體

Kbswpfree、Kbswpused、%swpused

Swap使用的3個值

Kbswpcad:緩存的swap空間。這個意思是:記憶體被swap out,又立即swap back in,但是還存在swap中,(如果memory需要,memory不需要再次swap out了,它在swap已經存在,節省了I/O)

記憶體使用統計

Report memory statistics

-R

frmpg/s:系統釋放的記憶體頁數量,如果是負數表示被系統配置設定的數量。記憶體頁時4k或8k和系統架構有關。

bufpg/s:系統用作buffer的增量記憶體頁

campg/s:系統用作cache的增量記憶體頁

I/O和傳輸統計

I/O and tranfer statistics

-b

隻在Kernal2.5以前的版本中才有效

Tps:實體磁盤每秒總的傳輸量。多個邏輯的請求可能被合并成一個單獨的磁盤請求。

Rtps:讀的請求

Wtps:寫的請求

Bread/s:每秒從磁盤讀的塊數

Wread/s:每秒寫的塊數

頁的統計消息

Paging statistics

-B

Pgpgin/s: 每秒磁盤page in的數量(kbytes)

Pgpgout/s:每秒磁盤page out的量(kbytes)

Fault/s:系統每秒page faults(major+minor)的數量(2.5以上kernal)

majflt/s:系統每秒産生的major faults數量(2.5以上kernel)

程序

Process creation

-c Proc/s:每秒産生的程序數量
Block device性能 -d

2.4或以上版本有

Devm-n: m:device的major number

n: device的 minor number(kernal 2.5)

tps: 裝置的每秒傳輸量

rd_sec/s:裝置的讀的扇區數量(512k/sector)

wr_sec/s : 裝置寫的扇區數量(512k/sector)

采用檔案

-f : 從。。讀

-o: 寫入。。。

從檔案中擷取資料(由-o産生的檔案)

預設值是current daily data file(/var/log/sa/sadd)

-f排斥-o參數

改變間隔時間 -i interval 機關是秒
網絡情況

-n

-n DEV | EDEV | SOCK | FULL

DEV參數:

Network devices 的統計資訊被報告

IFACE:裝置名字

rxpck/s:每秒收到的包(package)

txpck/s:每秒傳輸的包

rxbyt/s:每秒收到的位元組

txbyt/s:每秒傳輸的位元組

rxcmp/s:每秒收到的壓縮包(如cslip..)

txcmp/s:

rxmcst/s: 每秒收到的廣播包

EDEV:

錯誤的統計資訊

rxerr/s, txerr/s

coll/s: 傳輸過程中遇到的沖突包

rxdrop/s, txdrop/s:由于缺少Linux緩存區,被丢棄的接收/傳輸包

txcarr/s: 傳輸包時候遇到的carrier-errors數量

rxfram/s:接收frame對列錯誤數量

rxfifo/s:接收FIFO overrun錯誤數量

txfifo/s:傳輸的FIFO overrun錯誤數量

SOCK:

使用中的socket統計

Totsck: 使用中的socket

Tcpsck: tcp socket

Udpsck:

Rawsck:

ip-frag: Number of IP fragments currently in use.

機器負載

Report queue length and load averages

-q

runq-sz:運作的隊列長度(number of processes waiting for run time)

plist-sz: (Number of processes in the process list)

ldavg-1、ldavg-5、ldavg-15:

1、5、15分鐘平均負載

檔案

Report status of inode, file and other kernel tables

-v

Dentunusd:Number of unused cache entries in the directory cache

file-sz:Number of used file handles

inode-sz:Number of used file handles

super-sz、%super-sz: Number of super block handlers allocated by the kerne。(regard to the maximum number of super block handlers that Linux can allocate)

dquot-sz、%dquot-sz:Number of allocated disk quota entries (regard to the maximum number of cached disk quota entries that can be allocated)

rtsig-sz、%rtsig-sz:Number of queued RT signals.(regard to the maxi mum number of RT signals that can be queued)

Report system switching activity -w cswch/s:Total number of context switches per second.

Swap:

Report swapping statistics

-W

pswpin/s: Total number of swap pages the system brought in per second

pswpout/s:Total number of swap pages the system brought out per second

Process相關

-x

-X

改變格式

-h

-H

設定時間

-e hh:mm:ss:結束時間

-s 開始時間

設定報告的截止時間。預設的截止時間是18:00:00, 給出的時間必須24小時制。

這個參數隻有當資料從檔案中讀寫時候才有效(-f / -o 參數)。

如果同時使用-h參數,給出的時間是UTC時間