Zabbix监控Redis性能状态
监控原理示意图:
监控原理
Zabbix-server通过agent监控中配置文件调用shell脚本。Redis中提供redis-cli 命令使用info可以获得redis大部分信息。在使用shell命令获取到需要的信息。
监控操作步骤:
1、编辑脚本
2、上传脚本到指定位置
3、修改zabbix_agent配置文件
4、zabbix_server的web界面导入模版(编辑模板)
5、主机关联
1、配置zabbix_agent配置文件,添加以下内容
[root@localhost ~]# vim /usr/local/zabbix/etc/zabbix_agentd.conf
代码语言:javascript复制UserParameter=Redis.Info[*],/data/scripts/auto_detection_redis_state.sh $1
#保存退出
2、重启Zabbix_agentd服务
[root@localhost ~]# service zabbix_agentd restart
3、下载脚本文件(获取监控值)
[root@localhost ~]# cd /data/scripts
[root@localhost scripts]# wget -c https://mirrors.yangxingzhen.com/shell/auto_detection_redis_state.sh
[root@localhost scripts]# cat auto_detection_redis_state.sh
#脚本内容如下
代码语言:javascript复制#!/bin/bash#Date:2018-5-20 14:08:55#Author Blog:# https://www.yangxingzhen.com#Author WeChat:# 微信公众号:小柒博客#Author mirrors site:# https://mirrors.yangxingzhen.com#About the Author# BY:YangXingZhen# Mail:xingzhen.yang@yangxingzhen.com#Zabbix监控Redis状态和性能 HOST='127.0.0.1'PORT='8877' if [[ $# == 1 ]];thencase $1 inversion)redis-cli -h $HOST -p $PORT info | grep redis_version | awk -F: '{print $2}';;uptime)redis-cli -h $HOST -p $PORT info | grep uptime_in_seconds | awk -F: '{print $2}';;connected_clients)redis-cli -h $HOST -p $PORT info | grep connected_clients | awk -F: '{print $2}';;blocked_clients)redis-cli -h $HOST -p $PORT info | grep blocked_clients | awk -F: '{print $2}';;used_memory)redis-cli -h $HOST -p $PORT info | grep used_memory | awk NR==1 | awk -F: '{print $2}';;used_memory_rss)redis-cli -h $HOST -p $PORT info | grep used_memory_rss | awk NR==1 | awk -F: '{print $2}';;used_memory_peak)redis-cli -h $HOST -p $PORT info | grep used_memory_peak | awk NR==1 | awk -F: '{print $2}';;used_memory_lua)redis-cli -h $HOST -p $PORT info | grep used_memory_lua | awk NR==1 |awk -F: '{print $2}';;used_cpu_sys)redis-cli -h $HOST -p $PORT info | grep used_cpu_sys | awk NR==1 | awk -F: '{print $2}';;used_cpu_user)redis-cli -h $HOST -p $PORT info | grep used_cpu_user | awk NR==1 | awk -F: '{print $2}';;used_cpu_sys_children)redis-cli -h $HOST -p $PORT info | grep used_cpu_sys_children | awk -F: '{print $2}';;used_cpu_user_children)redis-cli -h $HOST -p $PORT info | grep used_cpu_user_children | awk -F: '{print $2}';;rdb_last_bgsave_status)redis-cli -h $HOST -p $PORT info | grep rdb_last_bgsave_status | awk -F: '{print $2}' | wc -l;;aof_last_bgrewrite_status)redis-cli -h $HOST -p $PORT info | grep aof_last_bgrewrite_status | awk -F: '{print $2}' | wc -l;;aof_last_write_status)redis-cli -h $HOST -p $PORT info | grep aof_last_write_status | awk -F: '{print $2}' | wc -l;;db0_keys)redis-cli -h $HOST -p $PORT info | grep -w keys | awk -F '=|,' '{print $2}';;db0_expires)redis-cli -h $HOST -p $PORT info | grep -w expires | awk -F '=|,' '{print $4}';;db0_avg_ttl)redis-cli -h $HOST -p $PORT info | grep avg_ttl | awk -F '=' '{print $4}';;*)echo -e "