作者:流水无痕8676 | 来源:互联网 | 2023-05-26 11:32
zabbix监控elk的es值(线上)1、es服务器、192.168.1.**服务器(agent端)首先通过curl-s-XGEThttp:localhost:
zabbix监控elk的es值(线上)
1、es服务器、192.168.1.**服务器(agent端)
-
首先通过curl -s -XGET http://localhost:9200/_cat/indices?bytes=G获取数据
-
安装zabbix-agent
-
通过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
-
vim /etc/zabbix/elk.index.sh #取值的脚本 192.168.1.**服务器(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
-
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
-
zabbix-server端测试
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
2、配置zabbix—server端web界面
-
配置模版
![es1](https://img1.php1.cn/3cd4a/24d65/78c/c223e8c935936f2c.jpeg)
![es2](https://img1.php1.cn/3cd4a/24d65/78c/f25a6c8a9ed3accb.jpeg)
然后点击保存
![es3](https://img1.php1.cn/3cd4a/24d65/78c/197dd3224a76302d.jpeg)
-
创建create discovery rule
![es4](https://img1.php1.cn/3cd4a/24d65/78c/aa1020abb423a10f.jpeg)
![es5](https://img1.php1.cn/3cd4a/24d65/78c/54b5117389be713c.jpeg)
-
点击item prototypes
![es6](https://img1.php1.cn/3cd4a/24d65/78c/77f7b4c2aede56cd.jpeg)
![es7](https://img1.php1.cn/3cd4a/24d65/78c/c7f45cd4e25f8c92.jpeg)
-
点击Trigger prototypes
![es8](https://img1.php1.cn/3cd4a/24d65/78c/a3125510790f0393.jpeg)
![es9](https://img1.php1.cn/3cd4a/24d65/78c/222d14af965a687a.jpeg)
![es10](https://img1.php1.cn/3cd4a/24d65/78c/7ce619edb1b21587.jpeg)
-
给主机添加模版
![es11](https://img1.php1.cn/3cd4a/24d65/78c/869b737569d0ee51.jpeg)
![es12](https://img1.php1.cn/3cd4a/24d65/78c/3552916cb01eb2c0.jpeg)
-
添加图形
![es13](https://img1.php1.cn/3cd4a/24d65/78c/6d961079cc791397.jpeg)
![es14](https://img1.php1.cn/3cd4a/24d65/78c/2d9daf065052fd1f.jpeg)
把所有图形整合到一个图
![es15](https://img1.php1.cn/3cd4a/24d65/78c/d83b56d51fa70aaa.jpeg)
3、查看成功后的图形
![es16](https://img1.php1.cn/3cd4a/24d65/78c/2fb8895fa1a26fb9.jpeg)