zabbix官方模板监控redis

下载官网模板等文件:

git clone https://github.com/adubkov/zbx_redis_template.git
cd zbx_redis_template

把文件复制到相对应的目录

cp zbx_redis.conf /etc/zabbix/zabbix_agentd.d/
mkdir -p /etc/zabbix/scripts/redis
cp zbx_redis_stats.py /etc/zabbix/scripts/redis

修改脚本中的zabbix-server主机的地址

vim /etc/zabbix/scripts/redis/zbx_redis_stats.py 

zabbix_host = '172.16.157.235' # Zabbix Server IP
zabbix_port = 10051 # Zabbix Server Port

修改配置文件中的脚本路径,并重启zabbix-agent

#以下是redis没有设置密码和修改端口的情况下
cat /etc/zabbix/zabbix_agentd.d/zbx_redis.conf 
UserParameter=redis[*],/etc/zabbix/scripts/redis/zbx_redis_stats.py $1 $2 $3

#以下是redis设置了密码和修改默认端口的情况下
UserParameter=redis[*],/etc/zabbix/scripts/redis/zbx_redis_stats.py -p 6379 -a password $1 $2 $3

#修改完配置文件之后,要重启zabbix-agent配置文件才会生效
systemctl restart zabbix-agent

安装所需要的python的模块

pip install redis
pip install argparse

在zabbix-web界面导入模板文件 zbx_redis_templates.xml

但是发现图形检测中显示没有数据,于是去查看zabbix-agent的日志发现以下错误:

less /var/log/zabbix/zabbix_agentd.log
 19967:20210106:163944.789 Traceback (most recent call last):
  File "/etc/zabbix/scripts/redis/zbx_redis_stats.py", line 142, in <module>
    main()
  File "/etc/zabbix/scripts/redis/zbx_redis_stats.py", line 88, in main
    server_info = client.info()
  File "/usr/lib/python2.7/site-packages/redis/client.py", line 1304, in info
    return self.execute_command('INFO')
  File "/usr/lib/python2.7/site-packages/redis/client.py", line 898, in execute_command
    conn = self.connection or pool.get_connection(command_name, **options)
  File "/usr/lib/python2.7/site-packages/redis/connection.py", line 1192, in get_connection
    connection.connect()
  File "/usr/lib/python2.7/site-packages/redis/connection.py", line 563, in connect
    raise ConnectionError(self._error_message(e))
redis.exceptions.ConnectionError: Error -2 connecting to aliyun9999:6379. Name or service not known.

解决办法:

在/etc/hosts中添加zabbix-agent-hostname解析

aliyun9999为zabbix_agentd.conf中Hostname=aliyun9999

vim /etc/hosts
127.0.0.1 aliyun9999

 

posted @ 2021-01-06 17:15  一只小白龙  阅读(722)  评论(0编辑  收藏  举报