zabbix4.4.5监控redis消息队列长度

实验环境centos7.6

环境准备,安装python的redis支持模块

yum -y install epel-release
yum -y install python-pip
pip install redis

1、在被监控的服务器上创建一个python脚本

只需要修改host,port,db,password,llen("队列名称")的值即可
vim redis_conn.py 
#!/usr/bin/env python
#ending:utf-8
import redis
def redis_conn():
    pool = redis.ConnectionPool(host="127.0.0.1",port=6380,db=0)
    conn = redis.Redis(connection_pool=pool)
    data = conn.llen("test_name")
    print(data)
redis_conn()

redis如果配置了连接密码可以使用以下脚本

#!/usr/bin/env python
#ending:utf-8
import redis
def redis_conn():
    pool = redis.ConnectionPool(host="127.0.0.1",port=6379,db=3,password=123456)
    conn = redis.Redis(connection_pool=pool)
    data = conn.llen("test_name")
    print(data)
redis_conn()  

2、赋予脚本可执行权限

chmod +x /usr/local/bin/redis_conn.py

3、创建zabbix-agent配置文件

vim /etc/zabbix/zabbix_agentd.d/userparameter_redis_queue.conf
UserParameter=redis.queue,/usr/local/bin/redis_conn.py

4、重启zabbix-agent服务

systemctl restart zabbix-agent

5、在zabbix-web端创建对应的监控项,注意这里键值需要和上面UserParameter值一致

6、查看下是否获取到队列长度,这里可以看到当前队列长度是675

7、点击下图形,可以看到曲线图

8、自行创建一个触发器即可实现微信或者邮件告警

原文地址:https://www.cnblogs.com/caidingyu/p/12835358.html