tsar

Tsar是淘宝的一个用来收集服务器系统和应用信息的采集报告工具,如收集服务器的系统信息(cpu,mem等),以及应用数据(nginx、swift等),收集到的数据存储在服务器磁盘上,可以随时查询历史信息,也可以将数据发送到nagios报警。
Tsar能够比较方便地增加模块,只需要按照 tsar 的要求编写数据的采集函数和展现函数,就可以把自定义的模块加入到tsar中。
安装:
1:sudo wget -O tsar.zip https://github.com/alibaba/tsar/archive/master.zip --no-check-certificate
2:sudo unzip tsar.zip
3:cd tsar-master
4:sudo make
5:sudo make install

安装完成后,会自动配置文件:
  ● 定时任务配置:/etc/cron.d/tsar(内容如下),负责每分钟调用tsar执行采集任务;
# cron tsar collect once per minute
MAILTO=""
* * * * * root /usr/bin/tsar --cron > /dev/null 2>&1

  ● 日志文件轮转配置:/etc/logrotate.d/tsar(内容如下),每个月会把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配置文件路径:/etc/tsar/tsar.conf,tsar的采集模块和输出的具体配置;
 sudo cat /etc/tsar/tsar.conf 
####debug_level(INFO DEBUG WARN ERROR FATAL)
debug_level ERROR
####[module]
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_nginx_multiport off
mod_nginx_live off
#mod_nginx_sys_mport on 80 8080
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
#mod_erpc on /etc/tsar/erpc.conf
#mod_search on

####output_interface file,db,nagios
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 command
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

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

####[output_tcp]
#output_tcp_mod mod_swap,mod_cpu
#output_tcp_addr localhost:9666
#output_tcp_merge on

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

####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
####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 servicename.key;w-min;w-max;c-min;cmax;
#threshold cpu.util;N;N;N;N;

  ● 模块路径(默认被监控的模块):/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

猜你喜欢

转载自sunshinebjzhenglq.iteye.com/blog/2334994
tar
sar