How to Monitor Redis with Zabbix: Auto‑Discovery Scripts and Templates
This guide walks you through creating Zabbix auto‑discovery scripts to extract all Redis INFO parameters, configuring custom keys, setting permissions, and building a complete Redis monitoring template with step‑by‑step screenshots.
Auto‑Discovery Script Creation
This script retrieves all Redis INFO parameter names via redis-cli and formats them as JSON for Zabbix low‑level discovery.
#!/bin/bash
/usr/local/bin/redis-cli -p 3000 -a redis66cs "info" > /home/zabbix/tmp/info.txt
cat /tmp/info.txt | grep -v "^#" | awk -F ":" '{print $1}' | grep -v [[:space:]] > /home/zabbix/tmp/info_parameter
Redis_parameter_discovery () {
Redis_Site=`cat /home/zabbix/tmp/info_parameter`
Redis_Site_Num=`echo ${Redis_Site} | awk '{print NF}'`
Redis_Site_parameter=(${Redis_Site})
printf '{
'
printf '\t"data":[
'
for ((i=0;i<${Redis_Site_Num};i++))
{
if [ `expr $i + 1` != ${Redis_Site_Num} ]; then
printf "\t{\"{#SITENAME}\":\"${Redis_Site_parameter[$i]}\"},
"
else
printf "\t{\"{#SITENAME}\":\"${Redis_Site_parameter[$i]}\"}
"
fi
}
printf '\t]
'
printf '}
'
}
case "$1" in
redis_parameter_discovery)
Redis_parameter_discovery
;;
*)
echo "Usage:$0 redis_parameter_discovery"
;;
esacPrepare Directories and Files
#mkdir /home/zabbix/tmp
#touch /home/zabbix/tmp/info.txt
#touch /home/zabbix/tmp/info_parameter
#chown -R zabbix:zabbix /home/zabbix
#chmod 777 /home/zabbix/tmp/{info.txt,info_parameter}Script to Retrieve Specific INFO Values
This script receives a parameter name (e.g., used_memory) and returns its value from the previously saved INFO output.
#!/bin/bash
/usr/local/bin/redis-cli -p 3000 -a redis66cs "info" > /home/zabbix/tmp/info.txt
Redis_Site=`cat /home/zabbix/tmp/info_parameter`
Redis_info_value=$(grep "$1" /home/zabbix/tmp/info.txt | awk -F ":" '{print $NF}')
echo $Redis_info_valueDefine Custom Zabbix Keys
Add the following lines to the Zabbix agent configuration directory.
UserParameter=redis.parameter.discovery,/etc/zabbix/scripts/redis_parameter redis_parameter_discoveryThe key redis.parameter.discovery calls the discovery script and returns all INFO parameter names.
UserParameter=redis.info.value[*],/etc/zabbix/scripts/redis_info.sh $1The key redis.info.value fetches the value of a specific INFO parameter passed as $1.
Set Permissions and Restart Agent
#chown -R zabbix:zabbix /etc/zabbix/*
#chmod +x /etc/zabbix/scripts/*
#/etc/init.d/zabbix/zabbix_agentd restartTest Discovery with zabbix_get
zabbix_get -s 192.168.14.56 -k redis.parameter.discoveryThe command returns a JSON array containing all 82 Redis INFO parameters, for example:
{
"data":[
{"{#SITENAME}":"redis_version"},
{"{#SITENAME}":"redis_git_sha1"},
...
{"{#SITENAME}":"cluster_enabled"}
]
}Create a Redis Template in Zabbix UI
1. Create a new template.
2. Create an application set.
3. Add the auto‑discovery rule using the key redis.parameter.discovery.
Link Template to a Host
Select a host and attach the newly created Redis template.
Check the host's discovery status; a red exclamation indicates a problem.
Navigate to the host's monitoring items under the Redis application set to verify that all 82 parameters are collected.
The final screen shows successful data collection for each Redis INFO parameter.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
