首先經過curl -s -XGET http://localhost:9200/_cat/indices?bytes=G獲取數據nginx
安裝zabbix-agentes6
經過shell腳本將值名以json的格式輸出
vim elk.discovery.shweb
腳本路徑:/opt/sbin #!/bin/bash indexarray=(`curl -s -XGET -k -u manager:eMBPVpeumhdiewgz https://localhost:9200/_cat/indices\?bytes\=G |sort -rnk8 |awk '{print $3}'|egrep 「^[^b]|boxfish.*$(date +%Y.%m.%d)」|sed 's/$(date +%Y%m%d)'//g`) length=${#indexarray[@]} printf "{\n" printf '\t'"\"data\":[" for ((i=0;i<$length;i++)) do printf '\n\t\t{' printf "\"{#ELKINDEX}\":\"${indexarray[$i]}\"}" if [ $i -lt $[$length-1] ];then printf ',' fi done printf "\n\t]\n" printf "}\n」
腳本受權:shell
chmod +x elk.discovery.sh
vim /etc/zabbix/elk.index.sh #取值的腳本 192.168.1.**服務器(agent端)json
#!/bin/bash if [ ${1:0:7} == boxfish ];then a=`curl -s -XGET -k -u manager:eMBPVpeumhdiewgz https://localhost:9200/_cat/indices\?bytes\=G |sort -rnk8 |egrep "$1-$(date +%Y.%m.%d)"` else a=`curl -s -XGET -k -u manager:eMBPVpeumhdiewgz https://localhost:9200/_cat/indices\?bytes\=G |sort -rnk8 |egrep "$1"` fi b=`echo $a |awk '{print $9}'` c=`echo $b|egrep -o "..$"` size=`echo $b|sed -rn 's#(.*)..\$#\1#gp'` case $c in gb) s=`echo | awk "{print $size*1024}"` ;; kb) #s=`scale=3 echo "$size/1024"|bc` s=`echo "$size"| awk '{printf("%.3f\n",$1/1024)}'` #s=`echo | awk "{print $size/1024}"` ;; *) s=$size esac echo $s
腳本受權:vim
chmod +x elk.discovery.sh
zabbix_agent設置bash
mkdir -p /etc/zabbix/zabbix_agentd.d/userparameter_elk.conf
/etc/zabbix/zabbix_agentd.d# cat userparameter_elk.conf服務器
UserParameter=elk.discovery,/etc/zabbix/elk.discovery.sh UserParameter=elk.index[*],/bin/bash /etc/zabbix/elk.index.sh $1
zabbix-server端測試curl
zabbix_server服務端,進行取名測試:測試
zabbix_get -s 192.168.1.** -k elk.discovery #腳本試行 { "data":[ {"{#ELKINDEX}":"logstash-nginx-access"}, {"{#ELKINDEX}":".kibana"} ] }
取值測試:zabbix_get -s 192.168.1.** -k elk.index[.kibana]
25.1
配置模版
而後點擊保存
建立create discovery rule
點擊item prototypes
點擊Trigger prototypes
給主機添加模版
添加圖形
把全部圖形整合到一個圖