zabbix监控redis

Posted 你很棒

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了zabbix监控redis相关的知识,希望对你有一定的参考价值。

1)agent端配置

  • 安装redis
yum install epel-release -y 
yum install redis -y 
  • 配置认证密码
#vim /etc/redis.conf
requirepass redhat 
#systemctl restart redis
  • 获取redis的item值shell脚本
#vim /etc/zabbix/zabbix_agentd.d/redis_status.sh
#/bin/bash 
R_COMMAND="$1"
R_PORT="6379"
R_SERVER="127.0.0.1"
PASSWD="redhat"
redis_status(){
   (echo -en "AUTH $PASSWD\\r\\nINFO\\r\\n";sleep 1;) | /usr/bin/nc "$R_SERVER" "$R_PORT" > /tmp/redis_"$R_PORT".tmp
      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"
	;;
    evicted_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
  • 授权
chmod +x /etc/zabbix/zabbix_agentd.d/redis_status.sh
  • 修改agent配置文件
#vim /etc/zabbix/zabbix_agentd.d/userparameter_redis.conf
UserParameter=redis.status[*],/etc/zabbix/zabbix_agentd.d/redis_status.sh $1
  • 重启agent服务
systemctl restart zabbix-agent

2)server端配置

  • server端获取key值
# zabbix_get -s 192.168.1.33 -k redis.status
USAGE:/etc/zabbix/zabbix_agentd.d/redis_status.sh {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}
# zabbix_get -s 192.168.1.33 -k redis.status[used_cpu_sys]
0.11
  • 键值
redis.status[used_cpu_user_children]
redis.status[used_cpu_sys]
redis.status[total_commands_processed]
redis.status[role]
redis.status[lru_clock]
redis.status[latest_fork_usec]
redis.status[keyspace_misses]
redis.status[keyspace_hits]
redis.status[keys]
redis.status[expires]
redis.status[expired_keys]
redis.status[connected_clients]
redis.status[changes_since_last_save]
redis.status[blocked_clients]
redis.status[bgrewriteaof_in_progress]
redis.status[used_memory_peak]
redis.status[used_memory]
redis.status[used_cpu_user]
redis.status[used_cpu_sys_children]
redis.status[total_connections_received]
  • 创建模板
  • 创建监控项
  • 其它省略,验证图形

以上是关于zabbix监控redis的主要内容,如果未能解决你的问题,请参考以下文章

zabbix监控redis

zabbix 监控 redis

zabbix监控redis

Zabbix--​Zabbix-Redis状态监控

zabbix 3.0.2监控redis

zabbix监控redis