這里參考的文章:
http://dl528888.blog.51cto.com/2382721/1366309
http://www.cnblogs.com/mushroom/p/4738170.html
一:客戶端配置
1.自動發(fā)現(xiàn)redis端口的腳本,腳本要給755權(quán)限,屬主是zabbix
chmod 755??/etc/zabbix/alertscripts/zabbix_discovery_redis.sh
chown zabbix.zabbix /etc/zabbix/alertscripts/zabbix_discovery_redis.sh
#!/bin/bash
#Fucation:mysql low-level discovery
#Script_name zabbix_discovery_redis.sh
redis() {
port=($(sudo netstat -tpln | awk -F "[ :]+" '/redis/ && /0.0.0.0/ {print $5}'))
printf '{\n'
printf '\t"data":[\n'
for key in ${!port[@]}
do
if [[ "${#port[@]}" -gt 1 && "${key}" -ne "$((${#port[@]}-1))" ]];then
socket=`ps aux|grep ${port[${key}]}|grep -v grep|awk -F '=' '{print $10}'|cut -d ' ' -f 1`
printf '\t {\n'
printf "\t\t\t\"{#REDISPORT}\":\"${port[${key}]}\"},\n"
else [[ "${key}" -eq "((${#port[@]}-1))" ]]
socket=`ps aux|grep ${port[${key}]}|grep -v grep|awk -F '=' '{print $10}'|cut -d ' ' -f 1`
printf '\t {\n'
printf "\t\t\t\"{#REDISPORT}\":\"${port[${key}]}\"}\n"
fi
done
printf '\t ]\n'
printf '}\n'
}
$1
因為要在模板里面套用redis端口冯键。所以腳本檢測出來的端口格式必須是json
其他問題:
zabbix_agentd是zabbix用戶啟動的,默認(rèn)不能執(zhí)行netstat -p等命令唤反,因此可以配置sudo解決,也可以使用chmod +s /bin/netstat進(jìn)行解決鸭津。
這里我使用了sudo
vim/etc/sudoers
#Defaults????requiretty
Defaults:zabbix????!requiretty
zabbix??ALL=(root)??????NOPASSWD:/bin/netstat
2.添加zabbix_agent配置文件
[root@testzabbix_agentd.conf.d]#?cat?/etc/zabbix/zabbix_agentd.conf.d/check_redis.conf
UserParameter=redis.discovery[*],/etc/zabbix/alertscripts/zabbix_discovery_redis.sh?$1
UserParameter=redis_stats[*],(echoinfo;sleep1)?|?telnet?127.0.0.1?$1?2>&1?|grep$2|cut-d?:?-f2
測試zabbix_get是否能獲取到redis數(shù)據(jù)
[root@testalertscripts]#?/usr/local/zabbix/bin/zabbix_get?-s?127.0.0.1?-k?redis_stats[6379,connected_clients]
3.重啟zabbix_agent
service zabbix_agentd restart
二.服務(wù)器端配置
1彤侍、創(chuàng)建模板
模板名稱:?Template_Redis_Monitor,創(chuàng)建應(yīng)用check_redis
2逆趋、創(chuàng)建自動發(fā)現(xiàn)規(guī)則
給已創(chuàng)建好的模板Template_Redis_Monitor添加自動發(fā)現(xiàn)規(guī)則盏阶。
創(chuàng)建自動發(fā)現(xiàn)監(jiān)控項
3.配置正則
4、添加監(jiān)控項原型
5.再來看看主機(jī)關(guān)聯(lián)模板后的監(jiān)控項:
6.查看監(jiān)控數(shù)據(jù)圖
這里我只是監(jiān)控了一個項闻书。其他的請自行拓展般哼,如有問題請留言
本文出自 “不拋棄吴汪!不放棄” 博客,請務(wù)必保留此出處http://thedream.blog.51cto.com/6427769/1868574