Zabbix 历史数据存储到 Elasticsearch


Zabbix 历史数据存储到 Elasticsearch

Zabbix 3.4.6 版本开始支持历史数据存储到 Elasticsearch, 早就想测试这个功能,最近有个需求需保存 zabbix 的历史数据上达十亿条,因此决定测试这功能的实用性,事实证明确实效果挺好。从今以后 zabbix 也支持大量的历史数据。

安装 elasticsearch

这里就不说明安装教程了,详情请参考以前的教程

添加 Elasticsearch mapping

Elasticsearch 支持 Zabbix 的监控项类型:uint,dbl,str,log,text,对应如下

Zabbix 监控项数据类型 对应 Zabbix 表 对应 Elasticsearch 类型
Numeric(unsigned)(无符号整型) history_uint uint
Numeric(float)(浮点型) history dbl
Character(字符) history_str str
Log(日志) history_log log
Text history_text text
# curl -H "Content-Type:application/json" -XPUT http://192.168.1.231:9200/uint -d ' { "settings" : { "index" : { "number_of_replicas" : 1, "number_of_shards" : 5 } }, "mappings" : { "values" : { "properties" : { "itemid" : { "type" : "long" }, "clock" : { "format" : "epoch_second", "type" : "date" }, "value" : { "type" : "long" } } } } } ' # curl -H "Content-Type:application/json" -XPUT http://192.168.1.231:9200/dbl -d ' { "settings" : { "index" : { "number_of_replicas" : 1, "number_of_shards" : 5 } }, "mappings" : { "values" : { "properties" : { "itemid" : { "type" : "long" }, "clock" : { "format" : "epoch_second", "type" : "date" }, "value" : { "type" : "double" } } } } } ' # curl -H "Content-Type:application/json" -XPUT http://192.168.1.231:9200/log -d ' { "settings" : { "index" : { "number_of_replicas" : 1, "number_of_shards" : 5 } }, "mappings" : { "values" : { "properties" : { "itemid" : { "type" : "long" }, "clock" : { "format" : "epoch_second", "type" : "date" }, "value" : { "fields" : { "analyzed" : { "index" : true, "type" : "text", "analyzer" : "standard" } }, "index" : false, "type" : "text" } } } } } ' # curl -H "Content-Type:application/json" -XPUT http://192.168.1.231:9200/text -d ' { "settings" : { "index" : { "number_of_replicas" : 1, "number_of_shards" : 5 } }, "mappings" : { "values" : { "properties" : { "itemid" : { "type" : "long" }, "clock" : { "format" : "epoch_second", "type" : "date" }, "value" : { "fields" : { "analyzed" : { "index" : true, "type" : "text", "analyzer" : "standard" } }, "index" : false, "type" : "text" } } } } } ' # curl -H "Content-Type:application/json" -XPUT http://192.168.1.231:9200/str -d ' { "settings" : { "index" : { "number_of_replicas" : 1, "number_of_shards" : 5 } }, "mappings" : { "values" : { "properties" : { "itemid" : { "type" : "long" }, "clock" : { "format" : "epoch_second", "type" : "date" }, "value" : { "fields" : { "analyzed" : { "index" : true, "type" : "text", "analyzer" : "standard" } }, "index" : false, "type" : "text" } } } } } ' 

配置 zabbix 服务器

Zabbix 安装过程忽略

配置 zabbix_server.conf 文件

在 /etc/zabbix/zabbix_server.conf 文件下添加 elasticsearch 配置,指定历时数据使用 elasticsearch。 vim /etc/zabbix/zabbix_server.conf

HistoryStorageURL=http://192.168.1.231:9200 HistoryStorageTypes=uint,dbl,str,log,text 

配置 zabbix.conf.php 文件 在 /etc/zabbix/web/zabbix.conf.php 文件下添加 elasticsearch 配置 vim /etc/zabbix/zabbix_server.conf

// Elasticsearch url (can be string if same url is used for all types). $HISTORY['url'] = 'http://192.168.1.231:9200'; // Value types stored in Elasticsearch. $HISTORY['types'] = ['uint', 'text', 'log', 'str', 'dbl']; 

多台 elasticsearch 集群可按以下格式配置

$HISTORY['url'] = [ 'uint' => 'http://192.168.1.230:9200 ', 'text' => 'http://192.168.1.234:9200', 'log' => 'http://192.168.1.235:9200']; $HISTORY['types'] = ['uint', 'text','log']; 

验证数据

启动 zabbix 后,使用 kibana 查看 es 集群是否有相关索引,方法这里就忽略。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM