opentsdb+grafana监控系按使用总结,opentsdbgrafana


一、OpenTSDB简介

开源监控系统OpenTSDB,用hbase存储所有的时序(无须 采样)来构建一个分布式、可伸缩的时间序列数据库。它支持秒级数据采集所有metrics,支持永久存储,可以做容量规划,并很容易的接入到现有的报警系 统里。OpenTSDB可以从大规模的集群(包括集群中的网络设备、操作系统、应用程序)中获取相应的metrics并进行存储、索引以及服务,从而使得这些数据更容易让人理解,如web化,图形化等。 对于运维工程师而言,OpenTSDB可以获取基础设施和服务的实时状态信息,展示集群的各种软硬件错误,性能变化以及性能瓶颈。对于管理者而言,OpenTSDB可以衡量系统的SLA,理解复杂系统间的相互作用,展示资源消耗情况。集群的整体 作业情况,可以用以辅助预算和集群资源协调。对于开发者而言,OpenTSDB可以展示集群的主要性能瓶颈,经常出现的错误,从而可以着力重点解决重要问题。 这里有几篇文字对于OpenTSDB的介绍非常详细: http://liubin.org/blog/2016/03/05/tsdb-opentsdb/ http://www.jianshu.com/p/0bafd0168647 https://yq.aliyun.com/articles/54785 这个是对表结构的详细介绍 https://zhengheng.me/2016/03/07/opentsdb-hbase-tuning/ 优化

 

二、OpenTSDB的安装配置

1、基本环境搭建 首先确保你的系统有以下条件满足:   jdk 1.6 以上 并配置好环境变量   hbase 0.92 或更高版本   gnuplot 4.2 或更高(yum安装吧)   autotools(好像只需要其中的autoconf和automake即可)
#1. 重新安装新版本autoconf/automake
#删除旧版本
yum erase autoconf
#安装新版本autoconf
wget http://mirrors.ustc.edu.cn/gnu/autoconf/autoconf-2.68.tar.gz
tar -zxvf autoconf-2.68.tar.gz
cd autoconf-2.68
./configure
make
make install
ln -s /usr/local/bin/autoconf /usr/bin/autoconf

#安装新版本automake
wget http://mirrors.ustc.edu.cn/gnu/automake/automake-1.11.2.tar.gz
tar -zxvf automake-1.11.2.tar.gz
cd automake-1.11.2
./configure
make
make install
ln -s /usr/local/bin/automake /usr/bin/automake
ln -s /usr/local/bin/aclocal /usr/bin/aclocal


#2.安装gnuplot-4.4.0
wget http://nchc.dl.sourceforge.net/project/gnuplot/gnuplot/4.4.0/gnuplot-4.4.0.tar.gz
tar -zxvf gnuplot-4.4.0.tar.gz
cd gnuplot-4.4.0
./configure
make
make install
ln -s /usr/local/bin/gnuplot /usr/bin/gnuplot
2、OpenTSDB的安装 然后下面是我通过源码安装的过程,希望能够有借鉴意义:
1 git clone https://github.com/OpenTSDB/opentsdb.git
2 cd opentsdb
3 ./build.sh
4 #当build.sh运行完毕的时候 你应该在opentsdb/build文件夹下看到opentsdb.jar
  最后安装成功了,这里总结一下: 首先,java要安装好,各变量也要配置好; 其次,autotools的那几个工具也要安装好; opentsdb必须的gnuplot也要安装好;   额外:因为OpenTSDB的后端是hbase,所以这里也加上我配置的hbase的简单介绍: 1、hbase的安装配置,解压完后,在/etc/profile中加上 HBASE_HOME=path/to/hbase-0.94.X 不加的话,后面命令需要自己手动加上 完成后source /etc/profile生效; 然后,配置hbase的zookeeper属性,这与 hbase-env.sh 文件相关,文件中 HBASE_MANAGES_ZK 环境变量用来设置是使用hbase默认自带的 Zookeeper还是使用独立的ZooKeeper。HBASE_MANAGES_ZK=false 时使用独立的,为true时使用默认自带的。 手动启动hbase: ./start-hbase cd opentsdb的build目录 && HBASE_HOME=/home/xxx/hbase-1.2.5 ./src/create_table.sh ./tsdb tsd

 

3、配置文件

配置文件及参数:

zookeeper(hbase依赖于zookeeper所以保证有hbase的同时就保证了有zookeeper)
在opentsdb/src文件夹下有一个opentsdb.conf的配置文件,内有3个主要属性需要配置:   tsd.http.cachedir opentsdb的缓存数据存放目录,找个路径配置好   tsd.http.staticroot opentsdb web 静态文件的root路径,一般在opentsdb/build/staticroot   tsd.network.port 绑定的端口 下面配置为常用可选配置   tsd.network.bind = 0.0.0.0 web 页面绑定IP,一般配置为0.0.0.0 保证其他IP可以访问opentsdb的web页面。   tsd.storage.hbase.zk_quorum = localhost 这个为zookeeper的地址。一般单机版hbase不需要配置 默认在本机。如果zookeeper是独立的或者分布式在其他机器上请指定IP 多个IP逗号分隔. 还有一些其他配置,请参见官网文档: http://opentsdb.net/docs/build/html/user_guide/configuration.html   配置文件填写好了之后将其复制至/etc/下 启动opentsdb会从以下几个地方搜索配置文件: ./opentsdb.conf /etc/opentsdb.conf /etc/opentsdb/opentsdb.conf /opt/opentsdb/opentsdb.conf 如果你多个地方都有配置文件,请确保这些多个配置文件的内容一致。也就是说修改一个要同步所有,不然根据你启动命令执行的路径不同可能会搜索到不同的配置文件。 建议只弄一个 放在/etc/下就好了。   注意! 若要将opentsdb的tag_values()函数获得的结果自动更新,需要设置四个参数在配置文件中
  • tsd.core.meta.enable_realtime_uid
  • tsd.core.meta.enable_tsuid_tracking
  • tsd.core.meta.enable_tsuid_incrementing
  • tsd.core.meta.enable_realtime_ts
opentsdb配置文件说明: http://opentsdb.net/docs/build/html/user_guide/stats.html
参数名 类型 是否必选 默认值 详细介绍
tsd.core.auto_create_metrics Boolean Optional false 新metric的数据点是否被指定UID。 当为false时,数据库中不具有metric的数据点将被拒绝并将抛出异常。
tsd.core.auto_create_tagks (2.1) Boolean Optional true 带有新标签名称的数据点是否会将一个UID分配给tagk。 当为false时,具有不在数据库中的标签名称的数据点将被拒绝并将抛出异常。
tsd.core.auto_create_tagvs (2.1) Boolean Optional true 是否具有新标签值的数据点将分配给tagv的UID。 当为false时,具有不在数据库中的标记值的数据点将被拒绝并将抛出异常。
4、启动OPENTSDB: 首先先创建hbase表: 在opentsdb/src下有个create_tab.sh的脚本 执行: env COMPRESSION=NONE HBASE_HOME=path/to/hbase-0.94.X ./src/create_table.sh COMPRESSION=NONE指定hbase表的压缩方式,可选:NONE, LZO, GZIP or SNAPPY HBASE_HOME不多说,如果配置好了在环境变量中可以不写这个。 最后一个就是执行建表脚本了。 建表完成后就可以启动了: 在opentsdb/build文件夹下有个tsdb的脚本 执行 ./tsdb tsd 即可启动opentsdb 打开对应ip和port的页面即可看到页面,如要后台执行:nohup ./tsdb tsd & 即可   5、OpenTSDB的简单使用 telnet客户端发送数据至opentsdb 创建metric:./tsdb mkmetric metricName telnet ip port 连接到opentsd 语法如下:    put 如:put sys.cpu.user 1356998400 42.5 host=webserver01 cpu=0         post方式发送数据:发送post请求至 ip:port/api/put,参数为json数据,如下:
Name Data Type Required Description QS
metric String Required The name of the metric you are storing sys.cpu.nice
timestamp Integer Required A Unix epoch style timestamp in seconds or milliseconds. The timestamp must not contain non-numeric characters. 1365465600
value Integer, Float, String Required The value to record for this data point. It may be quoted or not quoted and must conform to the OpenTSDB value rules: Writing
Data
42.5
tags Map Required A map of tag name/tag value pairs. At least one pair must be supplied. {"host":"web01"}
示例: { "metric": "sys.cpu.nice", "timestamp": 1346846400, "value": 18, "tags": { "host": "web01", "dc": "lga" }} 发送成功会返回204状态 详细请参见: http://opentsdb.net/docs/build/html/api_http/put.html ------------------------------------------- scan命令 扫描命令对于调试和导出数据点很有用。 提供开始时间,可选的结束时间和一个或多个查询,响应将是可接受用于导入命令的文本格式的存储或数据点的原始字节数据。 扫描还提供删除数据的基本方法。 scan命令接受常见的CLI参数。 数据被发送到标准输出。 请注意,虽然查询需要聚合器,但却被有效地忽略。 如果查询包含许多时间序列,则扫描输出可能非常大,因此在制作查询时要小心。   scan [--delete|--import] START-DATE [END-DATE] query [queries...]
Name Data Type Description Default Example
--delete Flag Optional flag that deletes data in any row that matches the query. See warning below.
可选标记,用于删除与查询匹配的任何行中的数据。
Not set --delete
--import flag Optional flag that outputs results in a text format useful for importing or storing as a backup. Not set --import
START-DATE String or Integer Starting time for the query. This may be an absolute or relative time. See Dates and Times for details   1h-ago
END-DATE String or Integer Optional end time for the query. If not provided, the current time is used. This may be an absolute or relative time. See Dates and Times for details Current timestamp 2014/01/01-00:00:00
query String One or more command line queries   sum tsd.hbase.rpcs type=put
example ./tsdb scan 2014/05/01 sum test_uid ed=endp --delete ./tsdb scan 2014/05/01 sum TcpExt.ArpFilter --delete  

三、grafana安装(grafana的具体介绍及使用方法会单独开一篇文章介绍)

  Grafana 安装 1, 在官网下载grafana 安装包,安装好了之后,根据安装输出日志的提示 启动 grafana 即可(grafana-server start) 2,启动 grafana 后 打开机器 IP:3000端口 即可登录 grafana 界面,初始密码 admin admin 3,在 datasource 中添加一个数据源,选择 opentsdb 填入 ip+端口 即可。opentsdb 默认为4242端口。    

相关内容