OpenTSDB安装与使用
来源:互联网 发布:青岛少儿编程培训班 编辑:程序博客网 时间:2024/06/06 14:15
1. 安装环境
1. 系统版本
('centos', '6.4', 'Final')
2. 内核版本
Linux localhost.localdomain 2.6.32-358.el6.x86_64 #1 SMP Fri Feb 22 00:31:26 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
3. 依赖安装
1. java安装
1.yum install java-1.6.0-openjdk-devel.x86_64
2. java环境变量设置
在~/.bash_profile文件中添加以下行。
# java
export JAVA_HOME=/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
2 gnuplot安装
yum install libotf
yum install gnuplot-common.x86_64
yum install gnuplot.x86_64
2. hbase 安装
1. 源码下载
wget http://mirror.bit.edu.cn/apache/hbase/hbase-0.94.27/hbase-0.94.27.tar.gz
2. 配置修改
1.修改hbase-env.sh中的如下属性
export JAVA_HOME=/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/
export HBASE_MANAGES_ZK=true
2.单机配置修改hbase-site.xml:
<configuration>
<property>
<name>hbase.rootdir</name>
<value>/root/guochunyang/hbase_fs/</value>
</property>
</configuration>
3. 启动hbase
./bin/start-hbase.sh
4. 关闭hbase
./bin/stop-hbase.sh
3. opentsdb 安装
1. 下载源码
git clone https://github.com/OpenTSDB/opentsdb.git
2.编译
./build.sh
3. 建表
env COMPRESSION=NONE HBASE_HOME=../hbase-0.94.27 src/create_table.sh
4. 配置文件 opentsdb.conf
[root@10.77.51.10 opentsdb]# cat /etc/opentsdb.conf
# --------- NETWORK ----------
# The TCP port TSD should use for communications
# *** REQUIRED ***
tsd.network.port = 4242
# The IPv4 network address to bind to, defaults to all addresses
# tsd.network.bind = 0.0.0.0
# Enables Nagel's algorithm to reduce the number of packets sent over the
# network, default is True
#tsd.network.tcpnodelay = true
# Determines whether or not to send keepalive packets to peers, default
# is True
#tsd.network.keepalive = true
# Determines if the same socket should be used for new connections, default
# is True
#tsd.network.reuseaddress = true
# Number of worker threads dedicated to Netty, defaults to # of CPUs * 2
#tsd.network.worker_threads = 8
# Whether or not to use NIO or tradditional blocking IO, defaults to True
#tsd.network.async_io = true
# ----------- HTTP -----------
# The location of static files for the HTTP GUI interface.
# *** REQUIRED ***
tsd.http.staticroot = build/staticroot
# Where TSD should write it's cache files to
# *** REQUIRED ***
tsd.http.cachedir = /tmp/tsd
# --------- CORE ----------
# Whether or not to automatically create UIDs for new metric types, default
# is False
#tsd.core.auto_create_metrics = false
tsd.core.auto_create_metrics = true
# --------- STORAGE ----------
# Whether or not to enable data compaction in HBase, default is True
#tsd.storage.enable_compaction = true
# How often, in milliseconds, to flush the data point queue to storage,
# default is 1,000
# tsd.storage.flush_interval = 1000
# Name of the HBase table where data points are stored, default is "tsdb"
#tsd.storage.hbase.data_table = tsdb
# Name of the HBase table where UID information is stored, default is "tsdb-uid"
#tsd.storage.hbase.uid_table = tsdb-uid
# Path under which the znode for the -ROOT- region is located, default is "/hbase"
#tsd.storage.hbase.zk_basedir = /hbase
# A comma separated list of Zookeeper hosts to connect to, with or without
# port specifiers, default is "localhost"
#tsd.storage.hbase.zk_quorum = localhost
5.启动
带参数模式
./build/tsdb tsd --port=4242 --staticroot=build/staticroot --cachedir="$tsdtmp" --zkquorum=127.0.0.1:2181
使用配置文件
./build/tsdb tsd
6. 创建指标
1. 手动创建指标
[root@10.77.51.10 opentsdb]# ./build/tsdb mkmetric mysql.bytes_received mysql.bytes_sent
metrics mysql.bytes_received: [0, 0, 1]
metrics mysql.bytes_sent: [0, 0, 2]
2.自动创建指标
需要修改配置文件中tsd.core.auto_create_metrics = true,默认为false。
需要向tsdb的监听端口发送消息。比如:
put tsd.connectionmgr.connections 1443170747 6 type=open host=localhost.localdomain
3.向OpenTSDB添加数据
(1)telnet或者nc
语法:
put <metric> <timestamp> <value> <tagk1=tagv1[ tagk2=tagv2 ...tagkN=tagvN]>
例如:
put sys.cpu.user 1356998400 42.5 host=webserver01 cpu=0
[root@10.77.51.10 ~]# telnet 127.0.0.1 4242
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
put proc.test.telnet 1443426262 12 telnet_host=localhost
[root@10.77.51.10 ~]# nc 127.0.0.1 4242
put proc.test.nc 1443426262 3 nc_host=localhost
(2)HTTP API
curl -H "Content-Type: application/json" -X POST http://127.0.0.1:4242/api/put/ -d '{"metic":"proc.test.curlpost","timestamp":1443427323,"value":18,"tags":{"host":"web01","dc":"lga"}}'
或者通过以下python脚本
[root@10.77.51.10 opentsdb_test]# cat test_post.py #!/usr/bin/env python# -*- coding:utf-8 -*-import httplibimport urllibimport urllib2import jsonimport timeimport randomdef my_post(): base_url = '10.77.51.10' headerdata = {'Content-type':'application/json'} time_cur = int(time.time()) va = random.randint(1,100) values = { "metric": "proc.test.httppost", "timestamp": time_cur, "value": va, "tags": { "host": "web01", "dc": "lga" } } jdata = json.dumps(values) conn = httplib.HTTPConnection(base_url,4242) conn.request(method="POST",url="/api/put/",body=jdata,headers=headerdata) res = conn.getresponse() res.read() # get response /api/put?details conn.request(method="POST",url="/api/put?details",body=jdata,headers=headerdata) res = conn.getresponse() return res.read()while(True): try: resp = my_post() print(resp) time.sleep(1) except Exception as e: exit(0) except KeyboardInterrupt as e: exit(0)[root@10.77.51.10 opentsdb_test]# python test_post.py {"errors":[],"failed":0,"success":1}{"errors":[],"failed":0,"success":1}{"errors":[],"failed":0,"success":1}{"errors":[],"failed":0,"success":1}^C[root@10.77.51.10 opentsdb_test]#
参考http://opentsdb.net/docs/build/html/api_http/put.html
(3)批量导入
参考http://opentsdb.net/docs/build/html/user_guide/cli/import.html
3. tcollector安装
1. 下载源码
https://github.com/OpenTSDB/tcollector
2. 启动
[root@10.77.51.10 tcollector]# pwd
/root/guochunyang/tcollector
[root@10.77.51.10 tcollector]# python tcollector.py
4. opentsdb_test
1. 启动opentsdb,配置支持tsd.core.auto_create_metrics = true,启动hbase,启动tcollector。用浏览器打开,打开后如图
2. 测试
Metric:test1.test1.test1
测试程序:
[root@10.77.51.10 opentsdb_test]# cat test2.py
import subprocess
import time
import logging
import random
logging.basicConfig(level=logging.DEBUG,filename="test.log")
def put_data(metric,value,**kw):
t = int(time.time())
cmd = "echo put %s %d %d host=test1 tag_k1=tag_v1 | nc -w 30 127.0.0.1 4242" %(metric,t,value)
subp = subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE)
random.seed()
while(True):
i = random.randint(1,100)
time.sleep(1)
put_data("test1.test1.test1",i)
i += 1
监控结果如图:
- OpenTSDB安装与使用
- OPENTSDB 安装与运行
- opentsdb部署与安装
- opentsdb安装
- OpenTsdb的eclipse配置与 linux安装
- openTSDB的分布式集群的安装和使用
- OpenTSDB配置安装
- OpenTSDB安装HBase
- opentsdb+grafana安装配置
- OpenTSDB研究---安装过程
- opentsdb研究--安装tcollector
- opentsdb 编译和安装
- openTSDB安装步骤
- openTSDB安装,部署
- Ubuntu安装OpenTSDB
- OpenTSDB-2.0.0安装布署
- OpenTSDB安装——Ubuntu
- OpenTSDB安装极简备忘
- git commit 运行时提示错误
- 控制器之间的数据传递——storyboard中控制器的数据传递
- POJ1308——并查集
- 先序后序中序非递归算法
- Mysql Long类型时间 当日数据查询
- OpenTSDB安装与使用
- 第二周项目0-宣告“主权”
- 企业战略管理笔记
- redis3.0.0 集群安装详细步骤
- 阅读Android官方教程 Google Training 1.3 ----- Manage the Activity Lifecycle
- 欢迎使用Markdown编辑器写博客
- Find the Difference
- java的位运算符(>>,<<,>>>,&,|)
- 2016 UESTC Training for Data Structures