zabbix监控redis
Redis使用自带的INFO命令,进行状态监控。以一种易于解释且易于阅读的格式,返回关于 Redis 服务器的各种信息和统计数值。
1.被控端安装redis
[root@192_168_81_170 ~]# yum -y install redis [root@192_168_81_170 ~]# systemctl start redis [root@192_168_81_170 ~]# systemctl enable redis 取值方式 [root@192_168_81_170 ~]# redis-cli -h 127.0.0.1 -p 6379 -a 123456 info
2.编写取值脚本
[root@192_168_81_170 ~]# vim /etc/zabbix/scripts/redis_status.sh #!/bin/bash R_COMMAND="$1" R_PORT="6379" #根据实际情况调整端口 R_SERVER="127.0.0.1" #根据具体情况调整IP地址 PASSWD="123456" #如果没有设置Redis密码,为空即可 redis_status(){ REDIS_STAT_VALUE=$(grep "$R_COMMAND:" /tmp/redis_"$R_PORT".tmp | cut -d ':' -f2) echo "$REDIS_STAT_VALUE" } case $R_COMMAND in used_cpu_user_children) redis_status "$R_PORT" "$R_COMMAND" ;; used_cpu_sys) redis_status "$R_PORT" "$R_COMMAND" ;; total_commands_processed) redis_status "$R_PORT" "$R_COMMAND" ;; role) redis_status "$R_PORT" "$R_COMMAND" ;; lru_clock) redis_status "$R_PORT" "$R_COMMAND" ;; latest_fork_usec) redis_status "$R_PORT" "$R_COMMAND" ;; keyspace_misses) redis_status "$R_PORT" "$R_COMMAND" ;; keyspace_hits) redis_status "$R_PORT" "$R_COMMAND" ;; keys) redis_status "$R_PORT" "$R_COMMAND" ;; expires) redis_status "$R_PORT" "$R_COMMAND" ;; expired_keys) redis_status "$R_PORT" "$R_COMMAND" connected_clients) redis_status "$R_PORT" "$R_COMMAND" ;; changes_since_last_save) redis_status "$R_PORT" "$R_COMMAND" ;; blocked_clients) redis_status "$R_PORT" "$R_COMMAND" ;; bgsave_in_progress) redis_status "$R_PORT" "$R_COMMAND" ;; bgrewriteaof_in_progress) redis_status "$R_PORT" "$R_COMMAND" ;; used_memory_peak) redis_status "$R_PORT" "$R_COMMAND" ;; used_memory) redis_status "$R_PORT" "$R_COMMAND" ;; used_cpu_user) redis_status "$R_PORT" "$R_COMMAND" ;; used_cpu_sys_children) redis_status "$R_PORT" "$R_COMMAND" ;; total_connections_received) redis_status "$R_PORT" "$R_COMMAND" ;; *) echo $"USAGE:$0 {used_cpu_user_children|used_cpu_sys|total_commands_processed|role|lru_clock|latest_fork_usec|keyspace_misses|keyspace_hits|keys|expires|expired_keys|connected_clients|changes_since_last_save|blocked_clients|bgrewriteaof_in_progress|used_memory_peak|used_memory|used_cpu_user|used_cpu_sys_children|total_connections_received}" esac
3.配置zabbix-agent
[root@192_168_81_170 ~]# vim /etc/zabbix/zabbix_agentd.d/redis_status.conf UserParameter=redis_status[*],/bin/bash /etc/zabbix/scripts/redis_status.sh "$1" [root@192_168_81_170 ~]# systemctl restart zabbix-agent zabbix server测试 [root@zabbix-server ~]# zabbix_get -s 192.168.81.170 -k redis_status[role] master
4.创建模板
配置—模板—创建模板
名称:Template Redis Status
创建监控项
名称:used_memory_peak
创建完毕
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-yQvOyC3W-1618906845508)(.\zabbix-笔记图片存放\image-20201217115044872.png)]
5.链接模板
配置—主机–详细信息—模板
全部是已启用的
查看最新数据