安装部署redis服务
- 安装redis
yum -y install redis
- 配置redis服,添加redis密码
echo "requirepass 123456" >> /etc/redis.conf
- 启动、开机自启服务
systemctl enable redis
systemctl start redis
获取redis信息的脚本
cat /server/scripts/reids_status.sh
#!/bin/bash
R_COMMAND="$1"
R_PORT="6379" #根据实际情况调整端口
R_SERVER="127.0.0.1" #根据具体情况调整IP地址
PASSWD="123456" #如果没有设置Redis密码,为空即可
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"
;;
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"
;;
rdb_bgsave_in_progress)
redis_status "$R_PORT" "$R_COMMAND"
;;
aof_rewrite_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"
;;
cluster_enabled)
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|expired|expired_keys|connected_clients|changes_since_last_save|blocked_clients|rdb_bgsave_in_progress|used_memory_peak|used_memory|used_cpu_user|used_cpu_sys_children|total_connections_received|aof_rewrite_in_progress|cluster_enabled}"
esac
给脚本添加执行权限
chmod +x /server/scripts/redis.sh
配置获取redis状态的key
[root@web03 ~]# cat /etc/zabbix/zabbix_agentd.d/redis_status.conf
UserParameter=redis_status[*],/bin/bash /server/scripts/redis_status.sh "$1"
重启agent服务
systemctl restart zabbix-agent
测试获取key值
#agent端测试
[root@web03 ~]# zabbix_agentd -t redis_status[used_cpu_user_children]
redis_status[used_cpu_user_children] [t|0.00]
#server端测试
[root@zabbix-server ~]# zabbix_get -s 172.16.1.9 -p 10050 -k redis_status[used_cpu_user_children]
0.00
web上导入模板
- 导入模板
查看web的获取的key值
文档更新时间: 2020-12-28 19:02 作者:Wan Hebin