How to Monitor Redis with Zabbix Agent2: A Complete Guide
This article explains how to use Zabbix Agent2 to monitor Redis, covering the plugin's architecture, configuration priority, methods for retrieving INFO, CONFIG, health status, and slow‑query logs, as well as practical steps to set up the Redis template in Zabbix.
Thanks to community expert Wanger for the contribution.
1. Monitoring Redis Implementation Principles
The Redis plugin is located in
zabbix-agent2/src/go/plugins/redis. The main file
redis.goimplements the Exporter interface and dispatches functions based on key values to obtain specific data.
The
whereToConnectfunction builds a URI from the configuration file and key parameters; the first key parameter can be a Redis session name or a URI. The plugin supports multiple sessions, allowing monitoring of several Redis instances, and a URI defined in the key takes precedence over the configuration file.
Configuration parameter priority (from highest to lowest):
Key parameters in the monitoring item
Parameters in
Plugins.Redis.Sessions.<sessionName>.<parameter>Parameters in
Plugins.Redis.<parameter>(configuration file)
Plugin default values
The plugin can retrieve Redis INFO command output, server configuration, health status, and the number of slow‑query logs.
01 – Getting INFO
This corresponds to executing the
INFOcommand in Redis. By default it returns all sections; an optional
sectionargument can limit the output. The result is parsed by
parseRedisInfointo a map.
02 – Getting CONFIG
This is equivalent to running
CONFIG GET *on the client, which returns all configuration parameters by default; a
patternargument can request specific settings.
03 – Getting Health Status
The health check simply executes the
PINGcommand.
04 – Getting Slow‑Query Log Count
The plugin obtains the number of slow‑query logs by querying the last slow‑query ID.
Connection Management
Returning to
redis.go, the
GetConnectionmethod obtains a connection, updates
lastTimeAccess, and compares it with the
keepalivesetting to close idle connections. If no connection exists, a new one is created; a mutex ensures thread safety. Multiple URIs can be added to monitor different instances.
Configuration File Parsing
The
config.gofile reads the plugin configuration. It shows that session parameters (
Plugins.Redis.Sessions.<sessionName>.<parameter>) have higher priority than general plugin parameters (
Plugins.Redis.<parameter>).
2. Monitoring Redis with Zabbix
After understanding the implementation, use the Redis template in Zabbix. Modify the URI macro; the default address is
tcp://127.0.0.1:6379and both TCP and Unix socket connections are supported. If Redis runs in protected mode, edit
redis.confto set
protected-mode noand restart the server.
<code>DENIED Redis Is Running In Protected Mode Because Protected Mode Is Enabled, No Bind Address Was Specified,
No Authentication Password Is Requested To Clients. In This Mode Connections Are Only Accepted From The Loopback Interface.
If You Want To Connect From External Computers To Redis You May Adopt One Of The Following Solutions:
1) Just Disable Protected Mode Sending The Command 'CONFIG SET Protected-Mode No' From The Loopback Interface By Connecting To Redis From The Same Host The Server Is Running, However MAKE SURE Redis Is Not Publicly Accessible From Internet If You Do So. Use CONFIG REWRITE To Make This Change Permanent.
2) Alternatively You Can Just Disable The Protected Mode By Editing The Redis Configuration File, And Setting The Protected Mode Option To 'No', And Then Restarting The Server.
3) If You Started The Server Manually Just For Testing, Restart It With the '--Protected-Mode No' Option.
4) Setup A Bind Address Or An Authentication Password. NOTE: You Only Need To Do One Of The Above Things In Order For The Server To Start Accepting Connections From The Outside.</code>After fixing the configuration, the Redis metrics appear in Zabbix.
Ops Development Stories
Maintained by a like‑minded team, covering both operations and development. Topics span Linux ops, DevOps toolchain, Kubernetes containerization, monitoring, log collection, network security, and Python or Go development. Team members: Qiao Ke, wanger, Dong Ge, Su Xin, Hua Zai, Zheng Ge, Teacher Xia.
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.