Linux系統性能監控工具介紹之-tsar

Linux系統性能監控工具介紹之-tsar

 

Linux系統性能監控工具介紹之-tsarpython

 分類:
 

目錄(?)[+]mysql

 

性能監控工具

在使用Linux過程當中,比較頭疼的就是系統提供了不少Linux系統監控工具,如何充分合理的使用這些工具,找出系統運行的性能瓶頸,包括CPU,內存,磁盤,網絡瓶頸。相似的網上有不少管理員不得不學的20個基本工具。這裏就不一一 介紹。這裏額外補充幾個使用且所見即所得的監控工具,幫助你們能更快的發現問題所在。linux

系統資源細分

談到系統性能監控和分析工具,就不得不提Brendan Gregg的系統分析,他的圖很是系統化的展現了應用程序,系統調用,內核,協議棧,硬件等各塊之間的交互。有興趣的朋友能夠根據這張圖裏的命令進行組合進行系統問題的監控,分析,定位。 
系統資源各塊調度ios

監控工具:tsar

簡介 
tsar是淘寶本身開發的一個採集工具,主要用來收集服務器的系統信息(如cpu,io,mem,tcp等),以及應用數據(如squid haproxy nginx等)。收集到的數據存儲在磁盤上,能夠隨時查詢歷史信息,輸出方式靈活多樣,另外支持將數據存儲到MySQL中,也能夠將數據發送到nagios報警服務器。tsar在展現數據時,能夠指定模塊,而且能夠對多條信息的數據進行merge輸出,帶–live參數能夠輸出秒級的實時信息。nginx

整體架構 
Tsar是基於模塊化設計的程序,程序有兩部分組成:框架和模塊。 
框架程序源代碼主要在src目錄,而模塊源代碼主要在modules目錄中。 
框架提供對配置文件的解析,模塊的加載,命令行參數的解析,應用模塊的接口對模塊原始數據的解析與輸出。 模塊提供接口給框架調用。 
tsar依賴與cron每分鐘執行採集數據,所以它須要系統安裝並啓用crond,安裝後,tsar每分鐘會執行tsar –cron來定時採集信息,而且記錄到原始日誌文件。git

tsar 環境安裝指南:github

$ wget -O tsar.zip https://github.com/alibaba/tsar/archive/master.zip --no-check-certificate $ unzip tsar.zip $ cd tsar $ make # make install

tsar配置介紹

前面介紹了tsar的介紹,如今你們來看看tsar的配置。算法

定時任務配置:/etc/cron.d/tsarsql

$cat /etc/cron.d/tsar # cron tsar collect once per minute MAILTO="" * * * * * root /usr/bin/tsar --cron > /dev/null 2>&1

 

如上所示,/etc/cron.d/tsar裏面負責每分鐘以root用戶的角色調用tsar命令來執行數據採集。apache

日誌文件輪轉 : /etc/logrotate.d/tsar

$ cat /etc/logrotate.d/tsar /var/log/tsar.data { monthly rotate 120 create nocompress nodateext notifempty prerotate /usr/bin/chattr -a /var/log/tsar.data endscript postrotate /usr/bin/chattr +a /var/log/tsar.data endscript }

 

在日誌文件輪轉配置中,每月會把tsar的本地存儲進行輪轉,此外這裏也設定了數據在/var/log/tsar.data下

配置文件:/etc/tsar/tsar.conf

[root@localhost ~]# cat /etc/tsar/tsar.conf debug_level ERROR mod_cpu on mod_mem on mod_swap on mod_tcp on mod_udp on mod_traffic on mod_io on mod_pcsw on mod_partition on mod_tcpx on mod_load on mod_apache off mod_lvs off mod_haproxy off mod_squid off mod_nginx off mod_swift off mod_swift_code off mod_swift_domain off mod_swift_esi off mod_swift_fwd off mod_swift_store off mod_swift_swapdir off mod_swift_purge off mod_swift_sys off mod_swift_tcmalloc off mod_tmd off mod_percpu off mod_tcprt off mod_proc off pidname mod_pharos off mod_tmd4 off mod_keyserver off output_interface file output_file_path /var/log/tsar.data output_stdio_mod mod_swap,mod_partition,mod_cpu,mod_mem,mod_lvs,mod_haproxy,mod_traffic,mod_squid,mod_load,mod_tcp,mod_udp,mod_tcpx,mod_apache,mod_pcsw,mod_io,mod_percpu include /etc/tsar/conf.d/*.conf

 

/etc/tsar/tsar.conf負責tsar的採集模塊和輸出的具體配置;在這裏配置啓用哪些模塊,輸出等內容。

tsar 模塊庫

[root@localhost modules]# ls -lt total 1136 -rwxr-xr-x 1 root root 15472 Jul 3 22:06 mod_ts_err.so -rwxr-xr-x 1 root root 14747 Jul 3 22:06 mod_ts_os.so -rwxr-xr-x 1 root root 14772 Jul 3 22:06 mod_ts_storage.so -rwxr-xr-x 1 root root 10606 Jul 3 22:06 mod_udp.so -rwxr-xr-x 1 root root 15215 Jul 3 22:06 mod_ts_client.so -rwxr-xr-x 1 root root 16195 Jul 3 22:06 mod_ts_codes.so -rwxr-xr-x 1 root root 15241 Jul 3 22:06 mod_ts_conn.so -rwxr-xr-x 1 root root 14633 Jul 3 22:06 mod_tcpx.so -rwxr-xr-x 1 root root 16708 Jul 3 22:06 mod_tmd4.so -rwxr-xr-x 1 root root 15627 Jul 3 22:06 mod_tmd.so -rwxr-xr-x 1 root root 11658 Jul 3 22:06 mod_traffic.so -rwxr-xr-x 1 root root 14969 Jul 3 22:06 mod_ts_cache.so -rwxr-xr-x 1 root root 22694 Jul 3 22:06 mod_swift_swapdir.so -rwxr-xr-x 1 root root 25332 Jul 3 22:06 mod_swift_sys.so -rwxr-xr-x 1 root root 20436 Jul 3 22:06 mod_swift_tcmalloc.so -rwxr-xr-x 1 root root 14065 Jul 3 22:06 mod_tcprt.so -rwxr-xr-x 1 root root 13409 Jul 3 22:06 mod_tcp.so

模塊路徑:/usr/local/tsar/modules,各個模塊的動態庫so文件;

tsar使用介紹

在tsar的使用中,能夠參考下面的幫助信息,完成對應的監控。

$tsar -h Usage: tsar [options] Options: -check 查看最後一次的採集數據 --check/-C 查看最後一次tsar的提醒信息,如:tsar --check / tsar --check --cpu --io --cron/-c 使用crond模式來進行tsar監控 --interval/-i 指明tsar的間隔時間,默認單位分鐘,帶上--live參數則單位是秒 --list/-L 列出啓用的模塊 --live/-l 查看實時數據 --file/-f 指定輸入文件 --ndays/-n 指定過去的數據天數,默認1天 --date/-d 指定日期,YYYYMMDD或者n表明n天前 --detail/-D 可以指定查看主要字段仍是模塊的全部字段 --spec/-s 指定字段,tsar –cpu -s sys,util Modules Enabled: --cpu 列出cpu相關的監控計數 --mem 物理內存的使用狀況 --swap 虛擬內存的使用狀況 --tcp TCP 協議 IPV4的使用狀況 --udp UDP 協議 IPV4的使用狀況 --traffic 網絡傳出的使用狀況 --io Linux IO的狀況 --pcsw 進程和上下文切換 --partition 磁盤使用狀況 --tcpx TCP 鏈接相關的數據參數 --load 系統負載狀況 

 

tsar cpu監控:

以下所示,使用參數–cpu能夠監控系統的cpu,參數user表示用戶空間cpu, sys內核空間cpu使用狀況,wait是IO對應的cpu使用狀況,hirq,sirq分別是硬件中斷,軟件中斷的使用狀況,util是系統使用cpu的總計狀況。下表的數據能夠看出,當前系統已使用大約30%的cpu。

$tsar --cpu Time -----------------------cpu---------------------- Time user sys wait hirq sirq util 23/08/15-21:25 23.59 1.71 0.11 0.00 2.68 27.98 23/08/15-21:30 24.11 1.62 0.12 0.00 2.72 28.46 23/08/15-21:35 25.34 1.84 0.09 0.00 2.95 30.13 23/08/15-21:40 23.67 1.64 0.20 0.00 2.59 27.91 23/08/15-21:45 26.20 1.90 0.26 0.00 2.94 31.04 

 

tsar監控虛存和load狀況

下圖列出了對應的系統swap使用,load的使用狀況。

$tsar --swap --load Time ---------------swap------------- -------------------load----------------- Time swpin swpout total util load1 load5 load15 runq plit 23/08/15-21:30 0.00 0.00 1.9G 0.00 1.32 1.37 1.38 2.00 12.4K 23/08/15-21:35 0.00 0.00 1.9G 0.00 1.20 1.29 1.34 21.00 12.4K 23/08/15-21:40 0.00 0.00 1.9G 0.00 1.28 1.25 1.31 2.00 12.4K 23/08/15-21:45 0.00 0.00 1.9G 0.00 1.44 1.26 1.29 3.00 12.4K 23/08/15-21:50 0.00 0.00 1.9G 0.00 1.54 1.30 1.29 3.00 12.4K 23/08/15-21:55 0.00 0.00 1.9G 0.00 0.94 1.36 1.34 4.00 12.4K 23/08/15-22:00 0.00 0.00 1.9G 0.00 1.10 1.32 1.33 4.00 12.5K 

 

tsar 內存使用狀況

下圖列出了系統內存的使用狀況

$tsar  --mem
Time           -----------------------mem---------------------- 
Time             free    used    buff    cach   total    util   
23/08/15-21:25 2.1G 5.7G 0.00 164.0M 8.0G 71.44 23/08/15-21:30 2.1G 5.7G 0.00 181.4M 8.0G 71.43 23/08/15-21:35 2.1G 5.7G 0.00 213.9M 8.0G 71.42 23/08/15-21:40 2.1G 5.7G 0.00 233.8M 8.0G 71.43 23/08/15-21:45 1.4G 5.7G 0.00 924.6M 8.0G 71.43 23/08/15-21:50 1.4G 5.7G 0.00 889.4M 8.0G 71.42 

下圖列出了使用tsar來監控系統IO狀況

$tsar --io Time ------------------------------------------sda------------------------------------------- Time rrqms wrqms rs ws rsecs wsecs rqsize qusize await svctm util 23/08/15-21:25 0.28 3.4K 184.40 389.25 4.9K 15.0K 35.47 3.00 6.35 0.29 16.44 23/08/15-21:30 0.00 3.2K 109.71 382.74 2.5K 14.5K 35.27 3.00 7.33 0.30 14.68 23/08/15-21:35 0.15 3.1K 156.91 342.16 3.8K 13.8K 36.15 3.00 6.60 0.29 14.37 23/08/15-21:40 0.86 3.3K 234.00 371.43 6.9K 14.6K 36.43 3.00 5.93 0.28 16.83 23/08/15-21:45 0.72 3.4K 376.80 357.13 11.7K 14.8K 37.03 3.00 4.84 0.25 18.50 

 

tsar 網絡監控統計

$tsar --traffic Time ---------------------traffic-------------------- Time bytin bytout pktin pktout pkterr pktdrp 23/08/15-21:30 548.5K 353.4K 1.0K 1.2K 0.00 0.00 23/08/15-21:35 762.4K 440.4K 1.2K 1.4K 0.00 0.00 23/08/15-21:40 540.2K 344.0K 1.0K 1.1K 0.00 0.00 23/08/15-21:45 640.3K 365.0K 1.1K 1.2K 0.00 0.00 23/08/15-21:50 564.4K 364.1K 1.1K 1.2K 0.00 0.00 23/08/15-21:55 599.8K 327.6K 1.1K 1.1K 0.00 0.00 
$tsar --tcp --udp -d 1 Time -------------------------------tcp------------------------------ ---------------udp-------------- Time active pasive iseg outseg EstRes AtmpFa CurrEs retran idgm odgm noport idmerr 23/08/15-00:05 0.79 1.52 1.6K 2.1K 0.00 0.03 3.4K 0.02 0.00 2.00 0.00 0.00 23/08/15-00:10 0.73 1.40 884.25 921.56 0.00 0.03 3.4K 0.01 0.00 3.00 0.00 0.00 23/08/15-00:15 0.77 1.46 959.62 1.0K 0.00 0.03 3.4K 0.01 0.00 3.00 0.00 0.00 23/08/15-00:20 0.69 1.43 1.0K 1.0K 0.00 0.03 3.4K 0.01 0.00 3.00 0.00 0.00 23/08/15-00:25 0.72 1.42 1.2K 1.1K 0.00 0.03 3.4K 0.00 0.00 3.00 0.00 0.00 

 

tsar 檢查告警信息

查看最後一次tsar的提醒信息,這裏包括了系統的cpu,io的告警狀況。

$tsar --check --cpu --io localhost.localdomain tsar cpu:user=25.0 cpu:sys=2.1 cpu:wait=0.1 cpu:hirq=0.0 cpu:sirq=0.2 cpu:util=27.4 io:sda:rrqms=0.0 io:sda:wrqms=4172.4 io:sda:rs=80.3 io:sda:ws=493.0 io:sda:rsecs=1664.0 io:sda:wsecs=18661.7 io:sda:rqsize=35.5 io:sda:qusize=4.0 io:sda:await=7.7 io:sda:svctm=0.3 io:sda:util=18.5 

 

tsar 歷史數據回溯

經過參數-d 2 能夠查出兩天前到如今的數據,-i 1 表示以每次1分鐘做爲採集顯示。

$tsar -d 2 -i 1 Time ---cpu-- ---mem-- ---tcp-- -----traffic---- --sda--- ---load- Time util util retran bytin bytout util load1 22/08/15-00:02 ------ 71.40 0.03 754.2K 421.4K 14.38 1.59 22/08/15-00:03 34.55 71.41 0.01 773.7K 400.9K 13.39 1.42 22/08/15-00:04 31.80 71.41 0.03 708.6K 391.9K 12.88 1.54 22/08/15-00:05 28.70 71.40 0.00 544.5K 305.9K 11.32 1.68 22/08/15-00:06 25.83 71.41 0.02 521.1K 280.4K 13.32 1.48 22/08/15-00:07 25.68 71.42 0.00 495.0K 265.2K 12.08 1.21 22/08/15-00:08 30.89 71.41 0.01 811.0K 280.1K 14.92 0.92 22/08/15-00:09 23.83 71.41 0.03 636.7K 349.4K 11.81 1.47 

參考連接:

管理員必讀的20個監控工具

tsar wiki手冊

tsar安裝使用手冊

tsar 的使用說明

 

系統模塊

cpu

字段含義

  • user: 表示CPU執行用戶進程的時間,一般指望用戶空間CPU越高越好.
  • sys: 表示CPU在內核運行時間,系統CPU佔用率高,代表系統某部分存在瓶頸.一般值越低越好.
  • wait: CPU在等待I/O操做完成所花費的時間.系統部應該花費大量時間來等待I/O操做,不然就說明I/O存在瓶頸.
  • hirq: 系統處理硬中斷所花費的時間百分比
  • sirq: 系統處理軟中斷所花費的時間百分比
  • util: CPU總使用的時間百分比
  • nice: 系統調整進程優先級所花費的時間百分比
  • steal: 被強制等待(involuntary wait)虛擬CPU的時間,此時hypervisor在爲另外一個虛擬處理器服務
  • ncpu: CPU的總個數

採集方式

 

CPU的佔用率計算,都是根據/proc/stat計數器文件而來,stat文件的內容基本格式是:

cpu  67793686 1353560 66172807 4167536491 2705057 0 195975 609768
cpu0 10529517 944309 11652564 835725059 2150687 0 74605 196726
cpu1 14380773 127146 13908869 832565666 150815 0 31780 108418

cpu是總的信息,cpu0,cpu1等是各個具體cpu的信息,共有8個值,單位是ticks,分別是

User time, 67793686 Nice time, 1353560 System time, 66172807 Idle time, 4167536491 Waiting time, 2705057 Hard Irq time, 0 SoftIRQ time, 195975 Steal time, 609768

CPU總時間=user+system+nice+idle+iowait+irq+softirq+Stl
各個狀態的佔用=狀態的cpu時間%CPU總時間*100%
比較特殊的是CPU總使用率的計算(util),目前的算法是:
util = 1 - idle - iowait - steal

mem

字段含義

  • free: 空閒的物理內存的大小
  • used: 已經使用的內存大小
  • buff: buff使用的內存大小,buffer is something that has yet to be "written" to disk.
  • cach: 操做系統會把常常訪問的東西放在cache中加快執行速度,A cache is something that has been "read" from the disk and stored for later use
  • total: 系統總的內存大小
  • util: 內存使用率

採集方法

內存的計數器在/proc/meminfo,裏面有一些關鍵項

MemTotal:      7680000 kB
    MemFree:        815652 kB
    Buffers:       1004824 kB
    Cached:        4922556 kB

含義就不解釋了,主要介紹一下內存使用率的計算算法:
util = (total - free - buff - cache) / total * 100%

load

字段含義

  • load1: 一分鐘的系統平均負載
  • load5: 五分鐘的系統平均負載
  • load15:十五分鐘的系統平均負載
  • runq: 在採樣時刻,運行隊列的任務的數目,與/proc/stat的procs_running表示相贊成思
  • plit: 在採樣時刻,系統中活躍的任務的個數(不包括運行已經結束的任務)

採集方法

/proc/loadavg文件中保存的有負載相關的數據
0.00 0.01 0.00 1/271 23741
分別是1分鐘負載,五分鐘負載,十五分鐘負載,運行進程/總進程 最大的pid
只須要採集前五個數據既可獲得全部信息
注意:只有當系統負載除cpu核數>1的時候,系統負載較高

traffic

字段含義

  • bytin: 入口流量byte/s
  • bytout: 出口流量byte/s
  • pktin: 入口pkt/s
  • pktout: 出口pkt/s

採集方法

流量的計數器信息來自:/proc/net/dev

face |bytes    packets errs drop fifo frame compressed multicast|bytes    packets errs drop fifo colls carrier compressed
    lo:1291647853895 811582000    0    0    0     0          0         0 1291647853895 811582000    0    0    0     0       0          0
    eth0:853633725380 1122575617    0    0    0     0          0         0 1254282827126 808083790    0    0    0     0       0          0

字段的含義第一行已經標示出來,每一行表明一個網卡,tsar主要採集的是出口和入口的bytes/packets
注意tsar只對以eth和em開頭的網卡數據進行了採集,像lo這種網卡直接就忽略掉了,流量的單位是byte

tcp

字段含義

  • active:主動打開的tcp鏈接數目
  • pasive:被動打開的tcp鏈接數目
  • iseg: 收到的tcp報文數目
  • outseg:發出的tcp報文數目
  • EstRes:Number of resets that have occurred at ESTABLISHED
  • AtmpFa:Number of failed connection attempts
  • CurrEs:當前狀態爲ESTABLISHED的tcp鏈接數
  • retran:系統的重傳率

採集方法

tcp的相關計數器文件是:/proc/net/snmp

Tcp: RtoAlgorithm RtoMin RtoMax MaxConn ActiveOpens PassiveOpens AttemptFails EstabResets CurrEstab InSegs OutSegs RetransSegs InErrs OutRsts
    Tcp: 1 200 120000 -1 31702170 14416937 935062 772446 16 1846056224 1426620266 448823 0 5387732

咱們主要關注其中的ActiveOpens/PassiveOpens/AttemptFails/EstabResets/CurrEstab/InSegs/OutSegs/RetransSegs
主要關注一下重傳率的計算方式:
retran = (RetransSegs-last RetransSegs) / (OutSegs-last OutSegs) * 100%

udp

字段含義

  • idgm: 收到的udp報文數目
  • odgm: 發送的udp報文數目
  • noport:udp協議層接收到目的地址或目的端口不存在的數據包
  • idmerr:udp層接收到的無效數據包的個數

採集方法

UDP的數據來源文件和TCP同樣,也是在/proc/net/snmp

Udp: InDatagrams NoPorts InErrors OutDatagrams
    Udp: 31609577 10708119 0 159885874

io

字段含義

  • rrqms: The number of read requests merged per second that were issued to the device.
  • wrqms: The number of write requests merged per second that were issued to the device.
  • rs: The number of read requests that were issued to the device per second.
  • ws: The number of write requests that were issued to the device per second.
  • rsecs: The number of sectors read from the device per second.
  • wsecs: The number of sectors written to the device per second.
  • rqsize:The average size (in sectors) of the requests that were issued to the device.
  • qusize:The average queue length of the requests that were issued to the device.
  • await: The average time (in milliseconds) for I/O requests issued to the device to be served. This includes the time spent by the requests in queue and the time spent servicing them.
  • svctm: The average service time (in milliseconds) for I/O requests that were issued to the device.
  • util: Percentage of CPU time during which I/O requests were issued to the device (bandwidth utilization for the device).Device saturation occurs when this value is close to 100%.

採集方法

IO的計數器文件是:/proc/diskstats,好比:

202    0 xvda 12645385 1235409 416827071 59607552 193111576 258112651 3679534806 657719704 0 37341324 717325100
    202    1 xvda1 421 2203 3081 9888 155 63 421 1404 0 2608 11292

每一行字段的含義是:

  • major: 主設備號
  • minor: 次設備號,設備號是用來區分磁盤的類型和廠家信息
  • name: 設備名稱
  • rd_ios: 讀完成次數,number of issued reads. This is the total number of reads completed successfully
  • rd_merges: 合併讀完成次數,爲了效率可能會合並相鄰的讀和寫.從而兩次4K的讀在它最終被處理到磁盤上以前可能會變成一次8K的讀,才被計數(和排隊),所以只有一次I/O操做
  • rd_sectors: 讀扇區的次數,number of sectors read. This is the total number of sectors read successfully.
  • rd_ticks: 讀花費的毫秒數,number of milliseconds spent reading. This is the total number of milliseconds spent by all reads
  • wr_ios: 寫完成次數,number of writes completed. This is the total number of writes completed successfully
  • wr_merges: 合併寫完成次數,number of writes merged Reads and writes which are adjacent to each other may be merged for efficiency. Thus two 4K reads may become one 8K read before it is ultimately handed to the disk, and so it will be counted (and queued) as only one I/O.
  • wr_sectors: 寫扇區次數,number of sectors written. This is the total number of sectors written successfully
  • wr_ticks: 寫花費的毫秒數,number of milliseconds spent writing. This is the total number of milliseconds spent by all writes.
  • cur_ios: 正在處理的輸入/輸出請求數,number of I/Os currently in progress. The only field that should go to zero. Incremented as requests are given to appropriate request_queue_t and decremented as they finish.
  • ticks: 輸入/輸出操做花費的毫秒數
  • aveq: 輸入/輸出操做花費的加權毫秒數

經過這些計數器能夠算出來上面的每一個字段的值

double n_ios = rd_ios + wr_ios;
double n_ticks = rd_ticks + wr_ticks;
double n_kbytes = (rd_sectors + wr_sectors) / 2;
st_array[0] = rd_merges / (inter * 1.0);
st_array[1] = wr_merges / (inter * 1.0);
st_array[2] = rd_ios / (inter * 1.0);
st_array[3] = wr_ios / (inter * 1.0);
st_array[4] = rd_sectors / (inter * 2.0);
st_array[5] = wr_sectors / (inter * 2.0);
st_array[6] = n_ios ? n_kbytes / n_ios : 0.0;
st_array[7] = aveq / (inter * 1000);
st_array[8] = n_ios ? n_ticks / n_ios : 0.0;
st_array[9] = n_ios ? ticks / n_ios : 0.0;
st_array[10] = ticks / (inter * 10.0);

注意:

扇區通常都是512字節,所以有的地方除以2了 ws是指真正落到io設備上的寫次數, wrqpms是指系統調用合併的寫次數, 它們之間的大小關係沒有可比性,由於不知道多少請求可以被合併,好比發起了100個read系統調用,每一個讀4K,假如這100個都是連續的讀,因爲硬盤一般容許最大的request爲256KB,那麼block層會把這100個讀請求合併成2個request,一個256KB,另外一個144KB,rrqpm/s爲100,由於100個request都發生了合併,無論它最後合併成幾個;r/s爲2,由於最後的request數爲2

paritition

字段含義

  • bfree: 分區空閒的字節
  • bused: 分區使用中的字節
  • btotl: 分區總的大小
  • util: 分區使用率

採集方法

首先經過/etc/mtab獲取到分區信息,而後經過statfs訪問該分區的信息,查詢文件系統相關信息,包含:

struct statfs {
    long f_type; 
    long f_bsiz
    e; 
    long f_blocks; 
    long f_bfree; 
    long f_bavail; 
    long f_files; 
    long f_ffree; 
    fsid_t f_fsid; 
    long f_namelen; 
    };

而後就能夠計算出tsar須要的信息,分區的字節數=塊數*塊大小=f_blocks * f_bsize

pcsw

字段含義

  • cswch: 進程切換次數
  • proc: 新建的進程數

採集方法

計數器在/proc/stat:

ctxt 19873315174
    processes 296444211

分別表明進程切換次數,以及進程數

tcpx

字段含義

recvq sendq est twait fwait1 fwait2 lisq lising lisove cnest ndrop edrop rdrop pdrop kdrop
分別表明
tcprecvq tcpsendq tcpest tcptimewait tcpfinwait1 tcpfinwait2 tcplistenq tcplistenincq tcplistenover tcpnconnest tcpnconndrop tcpembdrop tcprexmitdrop tcppersistdrop tcpkadrop

採集方法

計數器來自:/proc/net/netstat /proc/net/snmp 裏面用到的數據有:

TcpExt: SyncookiesSent SyncookiesRecv SyncookiesFailed EmbryonicRsts PruneCalled RcvPruned OfoPruned OutOfWindowIcmps LockDroppedIcmps ArpFilter TW TWRecycled TWKilled PAWSPassive PAWSActive PAWSEstab DelayedACKs DelayedACKLocked DelayedACKLost ListenOverflows ListenDrops TCPPrequeued TCPDirectCopyFromBacklog TCPDirectCopyFromPrequeue TCPPrequeueDropped TCPHPHits TCPHPHitsToUser TCPPureAcks TCPHPAcks TCPRenoRecovery TCPSackRecovery TCPSACKReneging TCPFACKReorder TCPSACKReorder TCPRenoReorder TCPTSReorder TCPFullUndo TCPPartialUndo TCPDSACKUndo TCPLossUndo TCPLoss TCPLostRetransmit TCPRenoFailures TCPSackFailures TCPLossFailures TCPFastRetrans TCPForwardRetrans TCPSlowStartRetrans TCPTimeouts TCPRenoRecoveryFail TCPSackRecoveryFail TCPSchedulerFailed TCPRcvCollapsed TCPDSACKOldSent TCPDSACKOfoSent TCPDSACKRecv TCPDSACKOfoRecv TCPAbortOnSyn TCPAbortOnData TCPAbortOnClose TCPAbortOnMemory TCPAbortOnTimeout TCPAbortOnLinger TCPAbortFailed TCPMemoryPressures
    TcpExt: 0 0 0 80 539 0 0 0 0 0 3733709 51268 0 0 0 80 5583301 5966 104803 146887 146887 6500405 39465075 2562794034 0 689613557 2730596 540646233 234702206 0 44187 2066 94 240 0 114 293 1781 7221 60514 185158 2 2 3403 400 107505 5860 24813 174014 0 2966 7 168787 106151 40 32851 2 0 2180 9862 0 15999 0 0 0

具體字段找到而且獲取便可

percpu ncpu

字段含義

字段含義等同cpu模塊,只不過可以支持採集具體的每個cpu的信息

採集方法

等同於cpu模塊

pernic

字段含義

字段含義等同traffic模塊,只不過可以支持採集具體的每個網卡的信息

採集方法

等同於traffic模塊

應用模塊

proc

字段含義

  • user: 某個進程用戶態cpu消耗
  • sys: 某個進程系統態cpu消耗
  • total:某個進程總的cpu消耗
  • mem: 某個進程的內存消耗百分比
  • RSS: 某個進程的虛擬內存消耗,這是駐留在物理內存的一部分.它沒有交換到硬盤.它包括代碼,數據和棧
  • read: 進程io讀字節
  • write:進程的io寫字節

採集方法

計數器文件

/proc/pid/stat:獲取進程的cpu信息
/proc/pid/status:獲取進程的mem信息
/proc/pid/io:獲取進程的讀寫IO信息

注意,須要將採集的進程名稱配置在/etc/tsar/tsar.conf總的mod_proc on procname,這樣就會找到procname的pid,並進行數據採集

nginx

字段含義

  • Accept:總共接收的新鏈接數目
  • Handle:總共處理的鏈接數目
  • Reqs:總共產生請求數目
  • Active:活躍的鏈接數,等於read+write+wait
  • Read:讀取請求數據的鏈接數目
  • Write:向用戶寫響應數據的鏈接數目
  • Wait:長鏈接等待的鏈接數目
  • Qps:每秒處理的請求數
  • Rt:平均響應時間ms

採集方法

經過nginx的採集模塊配置,訪問特定地址,具體參見:https://github.com/taobao/tsar-mod_nginx

location = /nginx_status {
        stub_status on;
    }

請求到的數據是:

Active connections: 1
    server accepts handled requests request_time
    24 24 7 0
    Reading: 0 Writing: 1 Waiting: 0

須要確保nginx配置該location,而且可以訪問curl http://localhost/nginx_status獲得上面的數據
若是nginx的端口不是80,則須要在配置文件中指定端口,配置文件是/etc/tsar/tsar.conf,修改mod_nginx on爲mod_nginx on 8080

相似的有nginx_code, nginx_domain模塊,相應的配置是:

req_status_zone server "$host" 20M;
    req_status server;
    location /traffic_status {
            req_status_show;
    }

經過訪問curl http://localhost/traffic_status可以獲得以下字段的數據
localhost,0,0,2,2,2,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0

請求到的數據每一個字段的含義是:

  • kv 計算獲得的req_status_zone指令定義變量的值,此時爲domain字段
  • bytes_in_total 從客戶端接收流量總和
  • bytes_out_total 發送到客戶端流量總和
  • conn_total 處理過的鏈接總數
  • req_total 處理過的總請求數
  • 2xx 2xx請求的總數
  • 3xx 3xx請求的總數
  • 4xx 4xx請求的總數
  • 5xx 5xx請求的總數
  • other 其餘請求的總數
  • rt_total rt的總數
  • upstream_req 須要訪問upstream的請求總數
  • upstream_rt 訪問upstream的總rt
  • upstream_tries upstram總訪問次數
  • 200 200請求的總數
  • 206 206請求的總數
  • 302 302請求的總數
  • 304 304請求的總數
  • 403 403請求的總數
  • 404 404請求的總數
  • 416 416請求的總數
  • 499 499請求的總數
  • 500 500請求的總數
  • 502 502請求的總數
  • 503 503請求的總數
  • 504 504請求的總數
  • 508 508請求的總數
  • detail_other 非以上13種status code的請求總數

若是domain數量太多,或者端口不是80,須要進行專門的配置,配置文件內容以下:
port=8080 #指定nginx的端口
top=10 #指定最多采集的域名個數,按照請求總個數排列
domain=a.com b.com #指定特定須要採集的域名列表,分隔符爲空格,逗號,或者製表符
在/etc/tsar/tsar.conf中指定配置文件的路徑:mod_nginx_domain on /tmp/my.conf

squid

字段含義

  • qps: 每秒請求數
  • rt: 訪問平均相應時間
  • r_hit: 請求命中率
  • b_hit: 字節命中率
  • d_hit: 磁盤命中率
  • m_hit: 內存命中率
  • fdused: Number of file desc currently in use
  • fdque: Files queued for open
  • objs: StoreEntries
  • inmem: StoreEntries with MemObjects
  • hot: Hot Object Cache Items
  • size: Mean Object Size

採集方法

訪問squid的mgrinfo信息獲取,有些字段通過了一些patch,可能不適用外部版本

haproxy

字段含義

  • stat: 狀態,1正常
  • uptime:啓動持續時間
  • conns: 總的鏈接數
  • qps: 每秒請求數
  • hit: haproxy開啓cache時的命中率
  • rt: 平均響應時間ms

採集方法

haproxy通過了patch,可以在多進程模式下進行統計信息的彙總,而後經過haproxy的本地訪問其狀態頁面admin分析獲得

lvs

字段含義

  • stat: lvs狀態,1正常
  • conns: 總的鏈接數
  • pktin: 收到的包數
  • pktout:發出的包數
  • bytin: 收到的字節數
  • bytout:發出的字節數

採集方法

訪問lvs的統計文件:/proc/net/ip_vs_stats

apache

參見:https://github.com/kongjian/tsar-apache

tcprt

私有應用,略

swift

私有應用,略

cgcpu/cgmem/cgblkio

私有應用,略

trafficserver

待補充

tmd

私有應用,略

相關文章
相關標籤/搜索