Tsar是淘寶的一個用來收集服務器系統和應用信息的采集報告工具,如收集服務器的系統信息(cpu,mem等),以及應用數據(nginx、swift等),收集到的數據存儲在服務器磁盤上,可以隨時查詢歷史信息,也可以將數據發送到nagios報警。
Tsar能夠比較方便地增加模塊,只需要按照 tsar 的要求編寫數據的采集函數和展現函數,就可以把自定義的模塊加入到tsar中。
安裝
Tsar目前托管在GitHub上,下載編譯安裝步驟:
[azureuser@mono tsar-master]$sudo wget -O tsar.zip https://github.com/alibaba/tsar/archive/master.zip --no-check-certificate
[azureuser@mono tsar-master]$ sudo unzip tsar.zip
[azureuser@mono tsar-master]$ cd tsar
[azureuser@mono tsar-master]$ sudo make
[azureuser@mono tsar-master]# sudo make install
- 定時任務配置:
/etc/cron.d/tsar
,負責每分鐘調用tsar執行采集任務; - 日志文件輪轉配置:
/etc/logrotate.d/tsar
,每個月會把tsar的本地存儲進行輪轉; - Tsar配置文件路徑:
/etc/tsar/tsar.conf
,tsar的采集模塊和輸出的具體配置; - 模塊路徑:
/usr/local/tsar/modules
,各個模塊的動態庫so文件;
Tsar配置
Tsar剛安裝完,還沒有歷史數據,想要check是否正常,執行tsar -l,查看是否有實時信息輸出:
[azureuser@mono tsar-master]$ tsar -l
Time ---cpu-- ---mem-- ---tcp-- -----traffic---- --sda--- --sdb--- ---load-
Time util util retran pktin pktout util util load1
17/08/13-02:52:11 0.20 19.78 0.00 0.00 0.00 0.40 0.00 0.00
Tsar的配置主要都在/etc/tsar/tsar.conf
中,常用的有:
- 增加一個模塊,添加
mod_<yourmodname> on
到配置文件中 - 打開或者關閉一個模塊,修改
mod_<yourmodname> on/off
output_stdio_mod
能夠配置執行tsar時的輸出模塊output_file_path
采集到的數據默認保存到的文件(如果修改的話需要對應修改輪轉的配置/etc/logrotate.d/tsar
)output_interface
指定tsar的數據輸出目的,默認file保存本地,nagios/db輸出到監控中心/數據庫中,這兩個功能還需要結合其它配置
Tsar使用
- 查看歷史數據,tsar
- -l/–list 查看可用的模塊列表
- -l/–live 查看實時數據,tsar -l –cpu
- -i/–interval 指定間隔,歷史,tsar -i 1 –cpu
- –modname 指定模塊,tsar –cpu
- -s/–spec 指定字段,tsar –cpu -s sys,util
- -d/–date 指定日期,YYYYMMDD或者n代表n天前
- -C/–check 查看最后一次的采集數據
- -d/–detail 能夠指定查看主要字段還是模塊的所有字段
- -h/–help 幫助功能
高級功能
- 輸出到nagios
配置: 首先配置output_interface file,nagios
,增加nagios輸出
然后配置nagios服務器和端口,以及發送的間隔時間
####The IP address or the host running the NSCA daemon
server_addr nagios.server.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
由于是nagios的被動監控模式,需要制定nsca的位置和配置文件位置
####nsca client program
send_nsca_cmd
/usr/bin/send_nsca
send_nsca_conf
/home/a/conf/amon/send_nsca
.conf
接下來制定哪些模塊和字段需要進行監控,一共四個閥值對應nagios中的不同報警級別
####tsar mod alert config file
####threshold [hostname.]servicename.key;w-min;w-max;c-min;cmax;
threshold cpu.util;50;60;70;80;
- 輸出到mysql
配置: 首先配置output_interface file,db
,增加db輸出
然后配置哪些模塊數據需要輸出
output_db_mod mod_cpu,mod_mem,mod_traffic,mod_load,mod_tcp,mod_udpmod_io
然后配置sql語句發送的目的地址和端口
output_db_addr console2:56677
目的地址在該端口監聽tcp數據,并且把數據入庫即可,可以參照tsar2db:https://github.com/kongjian/tsar2db
文章列表