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 集群是否有相關索引,方法這里就忽略。
