OpenTSDB的编译、安装、支持中文显示
来源:互联网 发布:零点有数 知乎 编辑:程序博客网 时间:2024/06/03 21:16
解决opentsdb无法写入和显示中文的问题
官网地址http://opentsdb.net/docs/build/html/user_guide/writing.html
The following rules apply to metric and tag values:
Strings are case sensitive, i.e. "Sys.Cpu.User" will be stored separately from "sys.cpu.user"
Spaces are not allowed
Only the following characters are allowed: a to z, A to Z, 0 to 9, -, _, ., / or Unicode letters (as per the specification)
官网这里明确说明了。只支持a to z, A to Z, 0 to 9, -, _, ., /这些以及Unicode的字母,如果修改的话只能修改源码
解决方案
进入opentsdb 的github地址下载2.3.0源码
https://github.com/OpenTSDB/opentsdb/releases
Opentsdb的源码使用的是ISO-8859-1,要支持中文源码要改成UTF-8
解压源码,进入到opentsdb-2.3.0目录下,运行
perl -pi -e 's|ISO-8859-1|UTF-8|g' `find ./ -type f`
进入到opentsdb-2.3.0/src/tsd目录下,查看WordSplitter.java文件
已变成UTF-8
完成这一步,之后编译的话,会解决中文不能写入的问题,但opentsdb的页面上显示仍然会乱码,下面是解决中文乱码的问题
进入到opentsdb-2.3.0/src/graph目录,有个Plot.java文件
在291行处
加上红线那一行
"set term png font '/usr/share/fonts/truetype/chinese/simsun.ttc,12'\n"
/usr/share/fonts/truetype/chinese/simsun.ttc目录下放的是中文字体(宋体),确保这个目录下存在这个字体,如没有,可以在window的字体中拷贝,或者
http://www.font5.com.cn/font_download.php?id=150&part=1237886897
在这个地址中下载,放到对应的目录下即可
操作完成,在opentsdb-2.3.0目录下执行
./build.sh
开始编译,一般不会有问题,编译完成后执行
env COMPRESSION=NONE HBASE_HOME=/home/hadoop/hbase src/create_table.sh
此命令是在hbase里生成四张表(如表已存在,可忽略)
修改src目录下的opentsdb.conf
# 接受请求的端口
tsd.network.port = 4343
# 接受请求的网卡
tsd.network.bind = 0.0.0.0
# HTTP客户端的GUI静态页面,这个使用默认值即可。
tsd.http.staticroot = ./staticroot
# cache 路径,最好提前创建好,保证读写权限。
tsd.http.cachedir = /home/opentsdb/tsdb_cache
# 是否能自动创建统计指标
tsd.core.auto_create_metrics = true
修改完成。
进入到build目录下执行
./tsdb mkmetric sys.batch.test
创建sys.batch.test的metric
运行
./tsdb tsd --port=4343 --staticroot=./staticroot --cachedir=/home/hadoop/app/opentsdb-2.3.0/opentsdb_cache
完成启动,输入数据(tags为中文),在
http://192.168.148.11:4343/
界面可以看见输出
以上为测试结果。有什么问题可以再联系
参考链接
中文入库问题
https://www.zhihu.com/question/63348780
重新编译opentsdb
http://www.codeweblog.com/opentsdb-2-1%E7%89%88%E6%9C%AC%E7%BC%96%E8%AF%91/
中文乱码问题
http://www.ttlsa.com/opentsdb/opentsdb-question/
阅读全文