Opentsdb
OpenTSDB介绍
openTSDB使用hbase作为存储中心,它无须采样,可以完整的收集和存储上亿的数据点,支持秒级别的数据监控,得益于hbase的分布式列式存储,hbase可以灵活的支持metrics的增加,可以支持上万机器和上亿数据点的采集。在openTSDB中,TSD是hbase对外通信的daemon程序,没有master/slave之分,也没有共享状态,因此利用这点和hbase集群的特点就可以消除单点。用户可以通过telnet或者http协议直接访问TSD接口,也可以通过rpc访问TSD。每一个需要获取metrics的Servers都需要设置一个Collector用来收集时间序列数据。这个Collector就是你收集数据的脚本。
- http://opentsdb.net/
- OpenTSDB监控系统的研究和介绍
- OpenTSDB 造成 Hbase 整点压力过大问题的排查和解决
- Writing Data:http://www.cnblogs.com/gsblog/p/4029987.html
OpenTSDB安装
用rpm包安装
yum -y install lzo lzo-devel gnuplot rpm -ivh opentsdb-2.1.0RC1.noarch.rpm
编译安装opentsdb
-
依赖软件安装
yum -y install gcc gcc-c++ autoconf automake make yum -y install lzo lzo-devel yum -y install gnuplot wget curl
-
编译安装
# git clone git://github.com/OpenTSDB/opentsdb.git opentsdb.git # cd opentsdb.git # 访问: https://github.com/OpenTSDB/opentsdb/releases/tag/v2.0.0RC2 # 下载: opentsdb-2.0.0.tar.gz tar zxvf opentsdb-2.0.0.tar.gz \ && cd opentsdb-2.0.0 \ && sed -i.bak 's;\(test -f Makefile || \.\./configure "$@"\);\1 --prefix=/opt/opentsdb-2.0.0;' build.sh ./build.sh cd build && make install # make clean # make distclean
create_table.sh
#若需指定hbase中的表名,先export如下变更 #export TSDB_TABLE='pre_tsdb' #export UID_TABLE='pre_tsdb-uid' #export TREE_TABLE='pre_tsdb-tree' #export META_TABLE='pre_tsdb-meta' env COMPRESSION=LZO HBASE_HOME=/opt/hbase/ ./src/create_table.sh
# opentsdb 2.0.0 tsdb {NAME => 'tsdb', FAMILIES => [{NAME => 't', BLOOMFILTER => 'ROW', VERSIONS => '1', COMPRESSION => 'LZO'}]} tsdb-meta {NAME => 'tsdb-meta', FAMILIES => [{NAME => 'name', BLOOMFILTER => 'ROW', COMPRESSION => 'LZO'}]} tsdb-tree {NAME => 'tsdb-tree', FAMILIES => [{NAME => 't', BLOOMFILTER => 'ROW', VERSIONS => '1', COMPRESSION => 'LZO'}]} tsdb-uid {NAME => 'tsdb-uid', FAMILIES => [{NAME => 'id', COMPRESSION => 'LZO'}, {NAME => 'name', COMPRESSION => 'LZO'}]}
配置文件
配置:bin/opentsdb.conf,若使用rpm包安装,则配置文件是/etc/opentsdb/opentsdb.conf。
编译安装配置
tsd.network.port = 4242 tsd.network.bind = 0.0.0.0 tsd.http.staticroot = /opt/opentsdb/share/opentsdb/static tsd.http.cachedir = tsd.core.auto_create_metrics = true tsd.core.meta.enable_realtime_ts=true tsd.storage.hbase.zk_quorum = yunwei2.myit:2181 # 使用以下配置项指定hbase中的表名称 # Name of the HBase table where data points are stored, default is "tsdb" #tsd.storage.hbase.data_table = pre_tsdb # Name of the HBase table where UID information is stored, default is "tsdb-uid" #tsd.storage.hbase.uid_table = pre_tsdb-uid #tsd.storage.hbase.meta_table = pre_tsdb-meta #tsd.storage.hbase.tree_table = pre_tsdb-tree
rpm包安装配置
-
/etc/opentsdb/opentsdb.conf
tsd.network.port = 4242 tsd.network.bind = 0.0.0.0 tsd.http.staticroot = /usr/share/opentsdb/static/ tsd.http.cachedir = /tmp/opentsdb tsd.core.plugin_path = /usr/share/opentsdb/plugins tsd.core.auto_create_metrics = true tsd.core.meta.enable_realtime_ts=true tsd.storage.hbase.zk_quorum = tsdb.tyunwei:2181
-
/etc/sysconfig/opentsdb
#JVMXMX=-Xmx6000m JVMXMX=-Xmx1024m
- 精简日志输出
opentsdb.log和opentsdb-tsdb.tyunwei-opentsdb.out中同时输出详细请求记录,浪废存储和磁盘I/O,可修改/etc/opentsdb/logback.xml如下内容屏蔽FILE输出:
<root level="INFO"> <appender-ref ref="STDOUT"/> <appender-ref ref="CYCLIC"/> <!--appender-ref ref="FILE"/--> </root>
启动脚本
- opentsdb rpm安装后自带启脚本
/etc/init.d/opentsdb {start|stop|status|restart|condrestart|try-restart|reload|force-reload}
-
增加环境变量$JAVA:/etc/profile.d/java.sh
export JAVA_HOME=/opt/java/jdk echo "$PATH"|grep "${JAVA_HOME}/bin" > /dev/null || export PATH="${JAVA_HOME}/bin:${JAVA_HOME}/jre/bin:$PATH" export CLASSPATH=.:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar export JAVA=/opt/java/jdk/bin/java
-
/etc/init.d/opentsdb脚本PID处理出错bug修改
# 修改pgrep匹配规则 findproc() { if [ -z "$JAVA" ];then pgrep -f "^java .* net.opentsdb.tools.TSDMain .*${NAME}" else pgrep -f "^${JAVA} .* net.opentsdb.tools.TSDMain .*${NAME}" fi }
-
设置自启动
chkconfig --add opentsdb chkconfig opentsdb on chkconfig --list opentsdb
-
单机启动两个tsdb
#/etc/init.d/opentsdb4243: CONFIG=/etc/opentsdb4243/${NAME}.conf export configdir=/etc/opentsdb4243 # /usr/bin/tsdb #configdir='/usr/share/opentsdb/etc/opentsdb' configdir=${configdir:-/usr/share/opentsdb/etc/opentsdb} # 生成4243配置 cd /usr/share/opentsdb/etc cp -R opentsdb opentsdb4243 cd opentsdb4243;mv opentsdb.conf opentsdb4243.conf # 并修改opentsdb4243.conf和logback.xml中相应配置。 ln -sfT /usr/share/opentsdb/etc/opentsdb4243 /etc/opentsdb4243
日志截断
# opentsdb.log自动回滚设置 cat > /etc/logrotate.d/opentsdb <<EOF /var/log/opentsdb/opentsdb*.out /var/log/opentsdb/opentsdb*.err { copytruncate daily rotate 20 compress missingok size 200M } EOF
访问tsdb及配置
- http://172.17.19.80:4242
- http://172.17.19.80:4242/api/config
- http://opentsdb.net/docs/build/html/api_http/
其它
-
手工添加指标
tsdb mkmetric proc.loadavg.1m proc.loadavg.5m
-
采集脚本范例:系统负载loadavg
#!/bin/bash # loadavg-collector.sh # /proc/loadavg # 0.00 0.00 0.00 1/173 30545 # The first three fields in this file are load average figures giving the number of jobs in the run queue (state R) or waiting # for disk I/O (state D) averaged over 1, 5, and 15 minutes. They are the same as the load average numbers given by uptime(1) # and other programs. # The fourth field consists of two numbers separated by a slash (/). The first of these is the number of currently executing # kernel scheduling entities (processes, threads); this will be less than or equal to the number of CPUs. # The value after the slash is the number of kernel scheduling entities that currently exist on the system. # The fifth field is the PID of the process that was most recently created on the system. # 该脚本每15秒输出如下格式内容,并直接通过nc提交给open-tsdb: # put proc.loadavg.1m 1398245238 0.00 host=tyunwei2.tsptest # put proc.loadavg.5m 1398245238 0.00 host=tyunwei2.tsptest set -e while true;do awk -v now=`date +%s` -v host=`hostname` \ '{ print "put proc.loadavg.1m "now " "$1" host="host;print "put proc.loadavg.5m "now " "$2" host="host }' /proc/loadavg sleep 15 done | nc -w 30 192.168.0.75 4242
通过nginx负载调度
# Update: 2014-04-23 upstream tsdb_dev_backends { #ip_hash; server 127.0.0.1:4243 max_fails=3 fail_timeout=10s; server 127.0.0.1:4242 max_fails=3 fail_timeout=10s; } server { listen 14242; #server_name 172.17.19.80; charset utf-8; client_max_body_size 20M; access_log /var/log/nginx/opentsdb.access.log main; error_log /var/log/nginx/opentsdb.error.log warn; location / { proxy_read_timeout 30; proxy_connect_timeout 10; proxy_pass_header Server; proxy_set_header Host $http_host; #proxy_redirect off; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Scheme $scheme; proxy_pass http://tsdb_dev_backends; } } #End server