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
- 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
#脚本内容如下
- #!/bin/bash
- #Date:2017-5-20 13:14:00
- #Author blog:
- # https://www.yangxingzhen.com
- #Author site:
- # https://www.yangxingzhen.com/sitemap.html
- #Author mirrors site:
- # https://mirrors.yangxingzhen.com
- #About the Author
- # BY:、、、小柒
- # QQ:675583110
- # Mail:[email protected]
- #Zabbix监控Redis状态和性能
- HOST='127.0.0.1'
- PORT='8877'
- if [[ $# == 1 ]];then
- case $1 in
- version)
- 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 "\033[32mUsage: $0 { uptime | connected_clients | blocked_clients | used_memory | used_memory_rss | used_memory_peak | used_memory_lua | used_cpu_sys | used_cpu_user | used_cpu_sys_children | used_cpu_user_children | rdb_last_bgsave_status | aof_last_bgrewrite_status | aof_last_write_status | db0_keys | db0_expires | db0_avg_ttl}\033[0m"
- ;;
- esac
- else
- echo -e "\033[32mUsage: $0 { uptime | connected_clients | blocked_clients | used_memory | used_memory_rss | used_memory_peak | used_memory_lua | used_cpu_sys | used_cpu_user | used_cpu_sys_children | used_cpu_user_children | rdb_last_bgsave_status | aof_last_bgrewrite_status | aof_last_write_status | db0_keys | db0_expires | db0_avg_ttl}\033[0m"
- fi
4、脚本授权
[root@localhost scripts]# chmod +x auto_detection_redis_state.sh
5、验证server端验证是否能获取agent端的key值
#使用zabbix_get命令获取key值
Zabbix监控平台配置
1、下载监控模板文件
模板附件下载:https://mirrors.yangxingzhen.com/templates/zabbix_redis_templates.xml
2、导入Redis监控模板
进入后台->配置->模板->导入(右上角)-> 选择下载的模板文件->最后点击导入 。
至此Redis监控模板已经导入到Zabbix中。
3、关联模板
需要把Redis监控模板链接到你的监控主机上,进入后台->配置->点击你的主机->模板->选择刚才导入模板,点击添加,最后点击更新即可。
4、效果图展示
至此,Zabbix监控Redis性能配置完毕。
标签:used,cli,Redis,redis,HOST,Zabbix,awk,监控,PORT From: https://blog.51cto.com/u_12018693/5980557