淘寶開源系統監控工具Tsar

Tsar是淘寶開發的一個很是好用的系統監控工具,在淘寶內部大量使用

   它不只能夠監控CPU、IO、內存、TCP等系統狀態,也能夠監控Apache,Nginx/Tengine,Squid等服務器狀態
   值得一提的是、Tsar 支持將數據存儲到 MySQL 中,也能夠將數據發送到 Nagios 報警服務器

㈠ 部署

      ① tsar因爲定時採集數據,須要crond服務正常。不依賴額外的庫
      ② 得到tsar源代碼:(svn checkout http://code.taobao.org/svn/tsar/trunk/ tsar)
      ③ 編譯安裝tsar

         進入tsar的根文件夾
         運行 ./configure,注意tsar並不支持prefix
         運行 make 進行編譯
         運行 make install 進行安裝

㈡ 經常使用例子

      好比、以1秒鐘爲間隔,實時打印tsar的概述數據mysql


      [root@localhost tsar-2.1.0]# tsar -i 1 -l  ios

  1. Time        ---cpu-- ---mem-- ---tcp-- -----traffic---- --hda---  ---load-   
  2. Time          util     util   retran    pktin  pktout     util     load1     
  3. 14/04-13:05   98.0     14.9      0.0      2.0     0.0     32.8      0.4     
  4. 14/04-13:05   85.1     14.6      0.0      2.0     0.0     15.6      0.4     
  5. 14/04-13:05    0.0     14.6      0.0     10.0     2.0      0.0      0.4     
  6. 14/04-13:05    4.0     14.6      0.0      2.0     0.0      1.6      0.4     
  7. 14/04-13:05    5.0     14.6      0.0      2.0     0.0      0.4      0.3     
  8. 14/04-13:05    7.0     14.6      0.0      0.0     0.0      0.8      0.3     
  9. 14/04-13:05    2.0     14.6      0.0      0.0     0.0      0.0      0.3     
  10. 14/04-13:05    1.0     14.6      0.0      0.0     2.0      0.0      0.3     

      再好比:
      tsar 顯示1天內的歷史彙總(summury)信息,以默認5分鐘爲間隔
      tsar --cpu -i 1 顯示一天內cpu的歷史信息,以1分鐘爲間隔
      tsar --live --mem -i 2 以2秒鐘爲間隔,實時打印mem的數據。
      tsar --cpu --mem -i 1 顯示一天內的cpu和內存歷史數據,以1分鐘爲間隔nginx


更多用法、請諮詢 http://code.taobao.org/p/tsar/wiki/index/git

簡介

tsar是淘寶本身開發的一個採集工具,主要用來收集服務器的系統信息(如cpu,io,mem,tcp等),以及應用數據(如squid haproxy nginx等)。github

收集到的數據存儲在磁盤上,能夠隨時查詢歷史信息,輸出方式靈活多樣,另外支持將數據存儲到mysql中,也能夠將數據發送到nagios報警服務器。sql

tsar在展現數據時,能夠指定模塊,而且能夠對多條信息的數據進行merge輸出,帶--live參數能夠輸出秒級的實時信息。數據庫

整體架構

Tsar是基於模塊化設計的程序,程序有兩部分組成:框架和模塊。服務器

框架程序源代碼主要在src目錄,而模塊源代碼主要在modules目錄中。架構

框架提供對配置文件的解析,模塊的加載,命令行參數的解析,應用模塊的接口對模塊原始數據的解析與輸出。 模塊提供接口給框架調用。框架

tsar依賴與cron每分鐘執行採集數據,所以它須要系統安裝並啓用crond,安裝後,tsar每分鐘會執行tsar --cron來定時採集信息,而且記錄到原始日誌文件。

tsar的運行流程圖以下:

主要執行流程有:

1.解析輸入

根據用戶的輸入,初始化一些全局信息,如間隔時間,是否merge,是否指定模塊,運行模式

2.讀取配置文件信息

主要解析tsar的配置文件,若是include生效,則會解析include的配置文件

配置文件用來得到tsar須要加載的模塊,輸出方式,每一類輸出方式包含的模塊,和此輸出方式的接收信息

如mod_cpu on表明採集cpu的信息

output_interface file,nagios表示向文件和nagios服務器發送採集信息和報警信息

3.加載相應模塊

根據配置文件的模塊開啓關閉狀況,將模塊的動態庫load到系統

4.tsar的三種運行模式

tsar在運行的時候有三種模式:

print模式僅僅輸出指定的模塊信息,默認顯示最近一天的;

live模式是輸出當前信息,能夠精確到秒級

cron模式,此通常是crontab定時執行,每一分鐘採集一次全部配置的模塊信息,並將數據寫入原始文件,在cron運行的時候 會判斷是否配置輸出到db或者nagios,若是配置則將相應格式的數據輸出到對應接口。

5.釋放資源

程序最後,釋放動態庫,程序結束

下載: https://github.com/alibaba/tsar

如何安裝

從github上檢出代碼:

$git clone  git://github.com/kongjian/tsar.git

$cd tsar

$make

$make install

或者直接從github上下載源碼

$wget -O tsar.zip  https://github.com/alibaba/tsar/archive/master.zip

$unzip tsar.zip

$cd tsar

$make

$make install

如何配置tsar

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

#debug_level(INFO DEBUG WARN ERROR FATAL)
debug_level FATAL
#[module] on/off to enable mod
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

#output type:file,nagios,db
output_interface file

#[output_file] original data to store
output_file_path /var/log/tsar.data

#[output_stdio] these mod will be show as using tsar
output_stdio_mod mod_swap,mod_partition,mod_cpu,mod_mem,mod_traffic,mod_load,mod_tcp,mod_udp,mod_tcpx,mod_pcsw,mod_io

#[output_nagios] the alert will be report to nagios server
#output_nagios_mod #mod_swap,mod_partition,mod_cpu,mod_mem,mod_traffic,mod_load,mod_tcp,mod_udp,mod_tcpx,mod_pcsw,mod_io

#[output_db]
#output_db_mod #mod_swap,mod_partition,mod_cpu,mod_mem,mod_traffic,mod_load,mod_tcp,mod_udp,mod_tcpx,mod_pcsw,mod_io
#output_db_addr console2:56677

#support include other mod conf
include /etc/tsar/conf.d/*.conf

debug_level 指定tsar的運行級別,主要用來調試使用

mod_xxx on/off 開啓指定模塊

out_interface 設置輸出類型,支持file,nagios,db

out_stdio_mod 設置用戶終端默認顯示的模塊

output_db_mod 設置哪些模塊輸出到數據庫

output_db_addr 數據庫的ip和端口

output_nagios_mod 設置哪些模塊輸出到nagios

include 支持include配置,主要用來加載用戶的自定義模塊

2.配置文件/etc/tsar/nagios.conf

#The IP address of the host running the NSCA daemon
server_addr mmdev4.corp.alimama.com
#The port on which the daemon is running - default is 5667
server_port 8086
#The cycle of send alert to nagios
cycle_time 300
#nsca client program
send_nsca_cmd /usr/bin/send_nsca
send_nsca_conf /home/a/conf/amon/send_nsca.conf

#tsar mod alert config file
#threshold [hostname.]servicename.key;w-min;w-max;c-min;cmax;
threshold cpu.util;N;N;N;N;
threshold mem.util;N;N;N;N;
threshold load.load1;N;N;N;N;
threshold load.load5;N;N;N;N;
threshold load.load15;N;N;N;N;
threshold traffic.bytin;N;N;N;N;
threshold traffic.bytout;N;N;N;N;
threshold tcp.retran;N;N;N;N;

這個文件主要是nagios服務器的配置

cycle_time 指定上報的間隔時間,因爲tsar每一分鐘採集一次,上報時會判斷是否符合時間間隔,如設置300的話,則在0,5等整點分鐘會上報nagios

threshold 設置某個要報警項的閥值,前面是模塊和要監控的具體名稱,後面的四個數據表明報警的範圍,warn和critical的範圍

3./etc/tsar/conf.d/*

這個目錄下是用戶的自定義模塊配置文件

配置基本在用戶開發自定義模塊時肯定,主要包含模塊的開啓,輸出類型和報警範圍

相關文章
相關標籤/搜索