## zabbix監控elk的es值(線上) ### 1、es伺服器、192.168.**.**伺服器(agent端)1. > 首先通過curl -s -XGET http://localhost:9200/_cat/indices?bytes=G獲取數據 1. > 安裝zabbix-agent 1 ...
## zabbix監控elk的es值(線上)
### 1、es伺服器、192.168.**.**伺服器(agent端)
1. > 首先通過curl -s -XGET http://localhost:9200/_cat/indices?bytes=G獲取數據
1. > 安裝zabbix-agent
1. > 通過shell腳本將值名以json的格式輸出
vim elk.discovery.sh
```腳本路徑:/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”
```
腳本授權:
```
chmod +x elk.discovery.sh
```
4. > vim /etc/zabbix/elk.index.sh #取值的腳本 192.168.**.**伺服器(agent端)
```
#!/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
```
腳本授權:
```
chmod +x elk.discovery.sh
```
5. > zabbix_agent設置
```
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
```
6. > zabbix-server端測試
zabbix_server服務端,進行取名測試:
```
zabbix_get -s 192.168.**.** -k elk.discovery #腳本試行
{
"data":[
{"{#ELKINDEX}":"logstash-nginx-access"},
{"{#ELKINDEX}":".kibana"}
]
}
```
取值測試:zabbix_get -s 192.168.**.** -k elk.index[.kibana]
```
25.1
```
### 2、配置zabbix—server端web界面
1. > 配置模版
![es1](http://on7oqnlte.bkt.clouddn.com/es1.png)
---
![es2](http://on7oqnlte.bkt.clouddn.com/es2.png)
> 然後點擊保存
![es3](http://on7oqnlte.bkt.clouddn.com/es3.png)
2. > 創建create discovery rule
![es4](http://on7oqnlte.bkt.clouddn.com/es4.png)
---
![es5](http://on7oqnlte.bkt.clouddn.com/es5.png)
3. > 點擊item prototypes
![es6](http://on7oqnlte.bkt.clouddn.com/es6.png)
---
![es7](http://on7oqnlte.bkt.clouddn.com/es7.png)
4. > 點擊Trigger prototypes
![es8](http://on7oqnlte.bkt.clouddn.com/es8.png)
---
![es9](http://on7oqnlte.bkt.clouddn.com/es9.png)
---
![es10](http://on7oqnlte.bkt.clouddn.com/es10.png)
5. > 給主機添加模版
![es11](http://on7oqnlte.bkt.clouddn.com/es11.png)
---
![es12](http://on7oqnlte.bkt.clouddn.com/es12.png)
6. > 添加圖形
![es13](http://on7oqnlte.bkt.clouddn.com/es13.png)
---
![es14](http://on7oqnlte.bkt.clouddn.com/es14.png)
> 把所有圖形整合到一個圖
![es15](http://on7oqnlte.bkt.clouddn.com/es14)
### 3、查看成功後的圖形
![es16](http://on7oqnlte.bkt.clouddn.com/es15)
![]()
![]()