tsar是淘宝自己开发的一个采集工具(类似于sar工具),主要用来收集服务器的系统信息(如cpu,io,mem,tcp等),以及应用数据(如squid haproxy nginx等)。
收集到的数据存储在磁盘上,可以随时查询历史信息,输出方式灵活多样,另外支持将数据存储到mysql中,也可以将数据发送到nagios报警服务器。
一、使用zip包安装
wget -O tsar.zip https://github.com/alibaba/tsar/archive/master.zip --no-check-certificate
unzip tsar.zip
cd tsar
make
make install
二、目录说明
/etc/tsar/tsar.conf,这是tsar的主要配置文件;
/etc/cron.d/tsar,用于每分钟运行tsar收集信息;
/etc/logrotate.d/tsar 将每个月轮询tsar的日志文件;
/usr/local/tsar/modules 是所有模块库(* .so)所在的目录;
/usr/local/man/man8/ 帮助文件
三、配置文件
[root@192 tsar]# cat /etc/tsar/tsar.conf
####debug_level(INFO DEBUG WARN ERROR FATAL)
debug_level ERROR #指定tsar的运行级别,主要用来调试使用
####[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
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 #设置输出类型,支持file,nagios,db
####[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 #数据库的ip和端口
####[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 #指定上报的间隔时间,由于tsar每一分钟采集一次,上报时会判断是否符合时间间隔,如设置300的话,则在0,5等整点分钟会上报
####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;
#设置某个要报警项的阀值,前面是模块和要监控的具体名称,后面的四个数据代表报警的范围,warn和critical的范围。
四、常用命令
#以1秒钟为间隔,实时打印tsar的概述数据
[root@192 tsar]# tsar -i 1 -l
Time ---cpu-- ---mem-- ---tcp-- -----traffic---- --sda--- --sr0--- --dm-0-- --dm-1-- ---load-
Time util util retran bytin bytout util util util util load1
12/10/23-22:38:48 0.50 7.16 0.00 60.00 102.00 0.00 0.00 0.00 0.00 0.00
12/10/23-22:38:49 0.00 7.16 0.00 60.00 118.00 0.30 0.00 0.30 0.00 0.00
12/10/23-22:38:50 0.50 7.16 0.00 60.00 118.00 0.00 0.00 0.00 0.00 0.00
12/10/23-22:38:51 0.00 7.16 0.00 60.00 118.00 0.00 0.00 0.00 0.00 0.00
12/10/23-22:38:52 0.50 7.16 0.00 60.00 118.00 0.00 0.00 0.00 0.00 0.00
#检查io使用
[root@192 tsar]# tsar -io --check
master tsar cpu:util=0.1 mem:util=7.1 tcp:retran=0.0 traffic:bytin=52.0 traffic:bytout=34.0 io:sda:util=0.0 io:sr0:util=0.0 io:dm-0:util=0.0 io:dm-1:util=0.0 load:load1=0.0
#显示一天内cpu使用情况
[root@192 tsar]# tsar --cpu -i 1
Time -----------------------cpu----------------------
Time user sys wait hirq sirq util
12/10/23-22:14 0.03 0.17 0.01 0.00 0.01 0.21
12/10/23-22:15 0.02 0.08 0.02 0.00 0.01 0.11
12/10/23-22:16 0.03 0.08 0.02 0.00 0.00 0.10
12/10/23-22:17 0.03 0.08 0.01 0.00 0.00 0.11
12/10/23-22:18 0.03 0.08 0.02 0.00 0.00 0.11
12/10/23-22:19 0.01 0.09 0.02 0.00 0.01 0.11
12/10/23-22:20 0.03 0.10 0.02 0.00 0.00 0.13
12/10/23-22:21 0.03 0.08 0.01 0.00 0.01 0.12
12/10/23-22:22 0.02 0.08 0.01 0.00 0.01 0.11
12/10/23-22:23 0.03 0.07 0.02 0.00 0.00 0.09
12/10/23-22:24 0.03 0.08 0.02 0.00 0.01 0.11
12/10/23-22:25 0.03 0.08 0.02 0.00 0.00 0.11
12/10/23-22:26 0.02 0.08 0.01 0.00 0.01 0.10
12/10/23-22:27 0.02 0.09 0.02 0.00 0.00 0.11
12/10/23-22:28 0.03 0.08 0.01 0.00 0.01 0.12
12/10/23-22:29 0.02 0.07 0.02 0.00 0.00 0.08
12/10/23-22:30 0.03 0.11 0.01 0.00 0.01 0.15
12/10/23-22:31 0.02 0.08 0.01 0.00 0.00 0.09
12/10/23-22:32 0.03 0.08 0.02 0.00 0.00 0.11
Time -----------------------cpu----------------------
Time user sys wait hirq sirq util
12/10/23-22:33 0.02 0.08 0.01 0.00 0.01 0.10
12/10/23-22:34 0.02 0.08 0.01 0.00 0.00 0.09
12/10/23-22:35 0.03 0.07 0.02 0.00 0.00 0.09
12/10/23-22:36 0.03 0.09 0.01 0.00 0.01 0.13
12/10/23-22:37 0.03 0.08 0.02 0.00 0.01 0.13
12/10/23-22:38 0.02 0.07 0.01 0.00 0.00 0.08
12/10/23-22:39 0.03 0.12 0.01 0.00 0.01 0.15
12/10/23-22:40 0.03 0.10 0.02 0.00 0.00 0.13
MAX 0.03 0.17 0.01 0.00 0.01 0.21
MEAN 0.02 0.08 0.01 0.00 0.00 0.11
MIN 0.03 0.07 0.01 0.00 0.01 0.11
#以3秒为间隔实时打印内存信息
[root@192 tsar]# tsar --live --mem -i 3
Time -----------------------mem----------------------
Time free used buff cach total util
12/10/23-22:42:11 1.1G 270.1M 2.1M 2.3G 3.7G 7.16
12/10/23-22:42:14 1.1G 270.1M 2.1M 2.3G 3.7G 7.16
12/10/23-22:42:17 1.1G 270.1M 2.1M 2.3G 3.7G 7.16
#显示一天内cpu和内存历史信息
[root@192 tsar]# tsar --cpu --mem -i 1
Time -----------------------cpu---------------------- -----------------------mem----------------------
Time user sys wait hirq sirq util free used buff cach total util
12/10/23-22:14 0.03 0.17 0.01 0.00 0.01 0.21 1.1G 267.7M 2.1M 2.3G 3.7G 7.10
12/10/23-22:15 0.02 0.08 0.02 0.00 0.01 0.11 1.1G 267.6M 2.1M 2.3G 3.7G 7.10
12/10/23-22:16 0.03 0.08 0.02 0.00 0.00 0.10 1.1G 267.7M 2.1M 2.3G 3.7G 7.10
12/10/23-22:17 0.03 0.08 0.01 0.00 0.00 0.11 1.1G 268.1M 2.1M 2.3G 3.7G 7.11
12/10/23-22:18 0.03 0.08 0.02 0.00 0.00 0.11 1.1G 268.1M 2.1M 2.3G 3.7G 7.11
12/10/23-22:19 0.01 0.09 0.02 0.00 0.01 0.11 1.1G 268.0M 2.1M 2.3G 3.7G 7.11
12/10/23-22:20 0.03 0.10 0.02 0.00 0.00 0.13 1.1G 268.3M 2.1M 2.3G 3.7G 7.12
12/10/23-22:21 0.03 0.08 0.01 0.00 0.01 0.12 1.1G 268.3M 2.1M 2.3G 3.7G 7.11
12/10/23-22:22 0.02 0.08 0.01 0.00 0.01 0.11 1.1G 267.9M 2.1M 2.3G 3.7G 7.10
12/10/23-22:23 0.03 0.07 0.02 0.00 0.00 0.09 1.1G 267.9M 2.1M 2.3G 3.7G 7.10
12/10/23-22:24 0.03 0.08 0.02 0.00 0.01 0.11 1.1G 267.6M 2.1M 2.3G 3.7G 7.10
12/10/23-22:25 0.03 0.08 0.02 0.00 0.00 0.11 1.1G 268.4M 2.1M 2.3G 3.7G 7.12
12/10/23-22:26 0.02 0.08 0.01 0.00 0.01 0.10 1.1G 268.2M 2.1M 2.3G 3.7G 7.11
12/10/23-22:27 0.02 0.09 0.02 0.00 0.00 0.11 1.1G 268.1M 2.1M 2.3G 3.7G 7.11
12/10/23-22:28 0.03 0.08 0.01 0.00 0.01 0.12 1.1G 267.7M 2.1M 2.3G 3.7G 7.10
12/10/23-22:29 0.02 0.07 0.02 0.00 0.00 0.08 1.1G 267.8M 2.1M 2.3G 3.7G 7.10
12/10/23-22:30 0.03 0.11 0.01 0.00 0.01 0.15 1.1G 268.6M 2.1M 2.3G 3.7G 7.12
12/10/23-22:31 0.02 0.08 0.01 0.00 0.00 0.09 1.1G 267.9M 2.1M 2.3G 3.7G 7.10
12/10/23-22:32 0.03 0.08 0.02 0.00 0.00 0.11 1.1G 268.3M 2.1M 2.3G 3.7G 7.12
Time -----------------------cpu---------------------- -----------------------mem----------------------
Time user sys wait hirq sirq util free used buff cach total util
12/10/23-22:33 0.02 0.08 0.01 0.00 0.01 0.10 1.1G 267.8M 2.1M 2.3G 3.7G 7.10
12/10/23-22:34 0.02 0.08 0.01 0.00 0.00 0.09 1.1G 268.3M 2.1M 2.3G 3.7G 7.12
12/10/23-22:35 0.03 0.07 0.02 0.00 0.00 0.09 1.1G 267.8M 2.1M 2.3G 3.7G 7.10
12/10/23-22:36 0.03 0.09 0.01 0.00 0.01 0.13 1.1G 267.8M 2.1M 2.3G 3.7G 7.10
12/10/23-22:37 0.03 0.08 0.02 0.00 0.01 0.13 1.1G 267.7M 2.1M 2.3G 3.7G 7.10
12/10/23-22:38 0.02 0.07 0.01 0.00 0.00 0.08 1.1G 267.8M 2.1M 2.3G 3.7G 7.10
12/10/23-22:39 0.03 0.12 0.01 0.00 0.01 0.15 1.1G 268.5M 2.1M 2.3G 3.7G 7.12
12/10/23-22:40 0.03 0.10 0.02 0.00 0.00 0.13 1.1G 269.1M 2.1M 2.3G 3.7G 7.14
12/10/23-22:41 0.04 0.16 0.01 0.00 0.01 0.21 1.1G 267.9M 2.1M 2.3G 3.7G 7.10
12/10/23-22:42 0.03 0.08 0.02 0.00 0.01 0.12 1.1G 268.2M 2.1M 2.3G 3.7G 7.11
12/10/23-22:43 0.02 0.09 0.01 0.00 0.00 0.11 1.1G 268.0M 2.1M 2.3G 3.7G 7.11
MAX 0.03 0.17 0.01 0.00 0.01 0.21 1.1G 269.1M 2.1M 2.3G 3.7G 7.10
MEAN 0.02 0.09 0.01 0.00 0.00 0.11 1.1G 268.1M 2.1M 2.3G 3.7G 7.11
MIN 0.03 0.07 0.01 0.00 0.01 0.11 1.1G 267.6M 2.1M 2.3G 3.7G 7.10