欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

zabbix监控redis的shell脚本

程序员文章站 2022-05-21 12:58:54
...
#! /bin/bash
# Name: redismontior.sh
# From: gaoyh@tingyun.com updn.cn 909012142@qq.com  <2017/11/03>
# Action: Zabbix monitoring redis plug-in

# redis connect info
REDISCLI="/opt/redis/bin/redis-cli"
CLUSTER_HOST=('192.168.10.18 3000' '192.168.10.18 3004' '192.168.10.19 3001' '192.168.10.19 3005' '192.168.10.20 3002' '192.168.10.21 3003')
#CLUSTER_HOST1=(192.168.10.18 3000)
#CLUSTER_HOST2=(192.168.10.18 3004)
#CLUSTER_HOST3=(192.168.10.19 3001)
#CLUSTER_HOST4=(192.168.10.19 3005)
#CLUSTER_HOST5=(192.168.10.20 3002)
#CLUSTER_HOST6=(192.168.10.21 3003)
PASSWD="xxxx"

# zabbix info
ZBX_CONF=/etc/zabbix/zabbix_agentd.d/userparameter_mysql.conf
ZBX_SENDER=/usr/bin/zabbix_sender
function sender()
{
	$ZBX_SENDER -c $ZBX_CONF -s ${HOSTNAME} -k $1 -o $2 &>/dev/null 
}

# do
function getinfo()
{
	result=`$REDISCLI -h $1 -p $2 -a $PASSWD info | grep -w "$3" | awk -F':' '{print $2}'`
	echo $result
}

if [[ $# == 1 ]];then
	for i in "${CLUSTER_HOST[@]}"
	do
		echo $i
		HOST=($i)
		getinfo ${HOST[0]} ${HOST[1]} $1
	done
else
	echo "error input"
fi

 今天谢了一个shell脚本用来获取redis的信息,发给zabbix告警

[root@tingyun-zabbix opt]# sh redismonitor.sh used_memory_human

192.168.10.18 3000

6.39G

192.168.10.18 3004

3.45G

192.168.10.19 3001

7.12G

192.168.10.19 3005

3.97G

192.168.10.20 3002

6.38G

192.168.10.21 3003

6.38G