pavelnemirovsky / zabbix-redis-template

Multi Instance Redis Discovery Template for Zabbix
MIT License
44 stars 26 forks source link

Discover Redis Instances marked as Not supported #6

Closed cmmata closed 6 years ago

cmmata commented 7 years ago

Hello,

I have installed your template, and I don't understand why it's not working. Discover Redis Commands and Discover Redis Slaves are working correctly, but Discover Redis Instances shows as Not supported in Zabbix. The error message is Value should be a JSON object., but the output looks like a valid JSON.

{"data":[{"{#HOST}":"127.0.0.1","{#PORT}":"6379","{#INSTANCE}":"REDIS","{#RDB_PATH}":"/var/lib/redis/dump.rdb"}]}

Here is my debug

$ ./zbx_redis_discovery.sh general debug
+ '[' -e /tmp/redis-cli ']'
++ cat /tmp/redis-cli
+ REDIS_CLI=/usr/bin/redis-cli
+ '[' -a /tmp/stdbuf ']'
++ cat /tmp/stdbuf
+ STDBUF=/usr/bin/stdbuf
+ '[' general '!=' general ']'
+ echo -n '{"data":['
{"data":[+ sed -e 's:\},$:\}:'
+ for s in '$LIST'
++ echo redis:/usr/bin/redis-server:127.0.0.1:6379:
++ sed 's/*/127.0.0.1/g'
++ cut -d: -f3
+ HOST=127.0.0.1
++ echo redis:/usr/bin/redis-server:127.0.0.1:6379:
++ sed 's/*/127.0.0.1/g'
++ cut -d: -f4
+ PORT=6379
+ [[ 1 -ne 0 ]]
+ (( i=0 ))
+ (( i<1 ))
+ PASSWORD=debug
++ discover_redis_instance 127.0.0.1 6379 debug
++ HOST=127.0.0.1
++ PORT=6379
++ PASSWORD=debug
+++ /usr/bin/redis-cli -h 127.0.0.1 -p 6379 -a debug ping
++ ALIVE=PONG
++ [[ PONG != \P\O\N\G ]]
+++ /usr/bin/redis-cli -h 127.0.0.1 -p 6379 -a debug info
+++ grep config_file
+++ cut -d : -f2
+++ cut -d / -f1
+++ rev
+++ tr -d '[:space:]'
+++ rev
+++ tr '[:lower:]' '[:upper:]'
+++ sed s/.conf//g
++ INSTANCE=REDIS
++ '[' REDIS = '' ']'
+++ /usr/bin/redis-cli -h 127.0.0.1 -p 6379 -a debug config get dir
+++ cut -d ' ' -f2
+++ sed -n 2p
++ INSTANCE_RDB_PATH=/var/lib/redis
+++ /usr/bin/redis-cli -h 127.0.0.1 -p 6379 -a debug config get dbfilename
+++ sed -n 2p
+++ cut -d ' ' -f2
++ INSTANCE_RDB_FILE=dump.rdb
++ echo REDIS
+ INSTANCE=REDIS
++ discover_redis_rdb_database 127.0.0.1 6379 debug
++ HOST=127.0.0.1
++ PORT=6379
++ PASSWORD=debug
+++ /usr/bin/redis-cli -h 127.0.0.1 -p 6379 -a debug ping
++ ALIVE=PONG
++ [[ PONG != \P\O\N\G ]]
+++ /usr/bin/redis-cli -h 127.0.0.1 -p 6379 -a debug config get dir
+++ cut -d ' ' -f2
+++ sed -n 2p
++ INSTANCE_RDB_PATH=/var/lib/redis
+++ /usr/bin/redis-cli -h 127.0.0.1 -p 6379 -a debug config get dbfilename
+++ cut -d ' ' -f2
+++ sed -n 2p
++ INSTANCE_RDB_FILE=dump.rdb
++ echo /var/lib/redis/dump.rdb
+ RDB_PATH=/var/lib/redis/dump.rdb
++ discover_redis_avalable_commands 127.0.0.1 6379 debug
++ HOST=127.0.0.1
++ PORT=6379
++ PASSWORD=debug
+++ /usr/bin/redis-cli -h 127.0.0.1 -p 6379 -a debug ping
++ ALIVE=PONG
++ [[ PONG != \P\O\N\G ]]
+++ /usr/bin/redis-cli -h 127.0.0.1 -p 6379 -a debug info all
+++ grep cmdstat
+++ cut -d: -f1
++ REDIS_COMMANDS='cmdstat_get
cmdstat_set
cmdstat_setnx
cmdstat_del
cmdstat_incr
cmdstat_rpush
cmdstat_lpush
cmdstat_rpop
cmdstat_lpop
cmdstat_llen
cmdstat_lrange
cmdstat_sadd
cmdstat_spop
cmdstat_mset
cmdstat_select
cmdstat_expire
cmdstat_scan
cmdstat_auth
cmdstat_ping
cmdstat_type
cmdstat_info
cmdstat_config
cmdstat_eval
cmdstat_slowlog
cmdstat_command'
++ IFS='
'
++ echo 'cmdstat_get
cmdstat_set
cmdstat_setnx
cmdstat_del
cmdstat_incr
cmdstat_rpush
cmdstat_lpush
cmdstat_rpop
cmdstat_lpop
cmdstat_llen
cmdstat_lrange
cmdstat_sadd
cmdstat_spop
cmdstat_mset
cmdstat_select
cmdstat_expire
cmdstat_scan
cmdstat_auth
cmdstat_ping
cmdstat_type
cmdstat_info
cmdstat_config
cmdstat_eval
cmdstat_slowlog
cmdstat_command'
+ COMMANDS='cmdstat_get
cmdstat_set
cmdstat_setnx
cmdstat_del
cmdstat_incr
cmdstat_rpush
cmdstat_lpush
cmdstat_rpop
cmdstat_lpop
cmdstat_llen
cmdstat_lrange
cmdstat_sadd
cmdstat_spop
cmdstat_mset
cmdstat_select
cmdstat_expire
cmdstat_scan
cmdstat_auth
cmdstat_ping
cmdstat_type
cmdstat_info
cmdstat_config
cmdstat_eval
cmdstat_slowlog
cmdstat_command'
++ discover_redis_avalable_slaves 127.0.0.1 6379 debug
++ HOST=127.0.0.1
++ PORT=6379
++ PASSWORD=debug
+++ /usr/bin/redis-cli -h 127.0.0.1 -p 6379 -a debug ping
++ ALIVE=PONG
++ [[ PONG != \P\O\N\G ]]
+++ /usr/bin/redis-cli -h 127.0.0.1 -p 6379 -a debug info all
+++ grep '^slave'
+++ cut -d : -f1
+++ grep '[0-1024]'
++ REDIS_SLAVES=
++ IFS='
'
++ echo ''
+ SLAVES=
+ [[ -n REDIS ]]
+ [[ general == \g\e\n\e\r\a\l ]]
+ generate_redis_stats_report 127.0.0.1 6379 debug
+ HOST=127.0.0.1
+ PORT=6379
+ PASSWORD=debug
++ stdbuf -oL /usr/bin/redis-cli -h 127.0.0.1 -p 6379 -a debug info all
+ REDIS_REPORT=
++ stdbuf -oL /usr/bin/redis-cli -h 127.0.0.1 -p 6379 -a debug slowlog len
++ cut -d ' ' -f2
++ /usr/bin/redis-cli -h 127.0.0.1 -p 6379 -a debug slowlog reset
+ REDIS_SLOWLOG_LEN=
++ stdbuf -oL /usr/bin/redis-cli -h 127.0.0.1 -p 6379 -a debug slowlog get
+ REDIS_SLOWLOG_RAW=
++ cut -d ' ' -f2
++ stdbuf -oL /usr/bin/redis-cli -h 127.0.0.1 -p 6379 -a debug config get '*maxclients*'
++ sed -n 2p
+ REDIS_MAX_CLIENTS=
+ generate_general_discovery_json 127.0.0.1 6379 REDIS /var/lib/redis/dump.rdb
+ HOST=127.0.0.1
+ PORT=6379
+ INSTANCE=REDIS
+ RDB_PATH=/var/lib/redis/dump.rdb
+ echo -n '{'
+ echo -n '"{#HOST}":"127.0.0.1",'
+ echo -n '"{#PORT}":"6379",'
+ echo -n '"{#INSTANCE}":"REDIS",'
+ echo -n '"{#RDB_PATH}":"/var/lib/redis/dump.rdb"'
+ echo -n '},'
+ (( i++  ))
+ (( i<1 ))
+ unset
{"{#HOST}":"127.0.0.1","{#PORT}":"6379","{#INSTANCE}":"REDIS","{#RDB_PATH}":"/var/lib/redis/dump.rdb"}+ echo -n ']}'
]}+ echo ''

+ unset IFS

I don't know if it's related, but I see REDIS_MAX_CLIENTS is blank in output message. If I execute the command I see there in the command line, it works

$ stdbuf -oL /usr/bin/redis-cli -h 127.0.0.1 -p 6379 -a debug config get '*maxclients*' | sed -n 2p
10000

What can be wrong in my setup?

Thanks

pavelnemirovsky commented 6 years ago

Very strange, provided JSON is fully valid, take a look

echo '{"data":[{"{#HOST}":"127.0.0.1","{#PORT}":"6379","{#INSTANCE}":"REDIS","{#RDB_PATH}":"/var/lib/redis/dump.rdb"}]}' | jq . { "data": [ { "{#HOST}": "127.0.0.1", "{#PORT}": "6379", "{#INSTANCE}": "REDIS", "{#RDB_PATH}": "/var/lib/redis/dump.rdb" } ] }

pavelnemirovsky commented 6 years ago

Any update? Considered as resolved.

cmmata commented 6 years ago

Sorry, I had two very busy weeks at work and couldn't take another look at this. I have updated to the last version both the template in Zabbix web interface and the repository in the server path, and it's still the same. Value should be a JSON object, although zbx_redis_discovery.sh general | jq . outputs a valid JSON. How can I debug the process? Or do you know where can I look to find what's wrong?

pavelnemirovsky commented 6 years ago

please provide an output from following command:

zabbix_get -s YOUR_SERVER_NAME -k redis.discovery[general]

The command should be invoked from zabbix server or proxy.

Also it will be good to run following command under zabbix user on host itself where u try to discover redis instances:

zabbix_agentd -t redis.discovery[general]

cmmata commented 6 years ago

Found it! I was getting a permission denied error. I didn't know how to check from command line. The output was

$ zabbix_get -s SERVER_NAME -k "redis.discovery[general]"
{"data":[/etc/zabbix/scripts/zabbix-redis-template/zabbix_agentd.d/zbx_redis_discovery.sh: line 184: /tmp/redis-127.0.0.1-6379: Permission denied

The problem was that /tmp/redis-127.0.0.1-6379 file was created with root user / group

$ ls -l
-rw-rw-r-- 1 root  root      3475 oct 17 10:06 redis-127.0.0.1-6379
-rw-rw-r-- 1 root  root         6 oct 17 10:06 redis-127.0.0.1-6379-maxclients
-rw-rw-r-- 1 root  root         2 oct 17 10:06 redis-127.0.0.1-6379-slowlog-len
-rw-rw-r-- 1 root  root         1 oct 17 10:06 redis-127.0.0.1-6379-slowlog-raw

I changed group to redis and added zabbix user, and now it's working.

$ zabbix_get -s SERVER_NAME -k "redis.discovery[general]"
{"data":[{"{#HOST}":"127.0.0.1","{#PORT}":"6379","{#INSTANCE}":"REDIS","{#RDB_PATH}":"/var/lib/redis/dump.rdb"}]}

Thank you for your help! And of course for your work :)

pavelnemirovsky commented 6 years ago

Great thanks, considered resolved.