實驗環境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