Hello!
I monitor redis with this script. But it works only when the requirepass password is not specified in redis.conf. Please tell me how to change the script to monitor redis with a password.
Script for Redis without password and it works.
2) When I write to which look for redis-cli -a password. Zabbix writes in Latest data:
which: no password in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin)
Because when i write command redis-cli -a password info Redis shows me metrics.
How should I write authorization in a script, or where to put the password. I would really appreciate any help. Maybe someone has already come across.
I monitor redis with this script. But it works only when the requirepass password is not specified in redis.conf. Please tell me how to change the script to monitor redis with a password.
Script for Redis without password and it works.
Code:
#!/bin/bash
##### Help #####
help () {
echo "Usage: $0 redis_metric"
echo "For example: $0 rejected_connections"
}
##### OPTIONS VERIFICATION #####
if [[ -z "$1" ]]; then
help
exit 1
fi
##### PARAMETERS #####
HOSTNAME=$(hostname -f)
AWK=$(which awk)
GREP=$(which grep)
METRIC="$1"
REDIS_CLI=$(which redis-cli)
# To use Unix-socket instead of port
# REDIS_CLI= "$(which redis-cli) -s /path/to/socket/file"
CACHE_TTL="55"
CACHE_FILE="/tmp/zabbix.redis.`echo $HOSTNAME | md5sum | cut -d" " -f1`.cache"
EXEC_TIMEOUT="1"
NOW_TIME=`date '+%s'`
##### RUN #####
if [ -s "${CACHE_FILE}" ]; then
CACHE_TIME=`stat -c"%Y" "${CACHE_FILE}"`
else
CACHE_TIME=0
fi
DELTA_TIME=$((${NOW_TIME} - ${CACHE_TIME}))
#
if [ ${DELTA_TIME} -lt ${EXEC_TIMEOUT} ]; then
sleep $((${EXEC_TIMEOUT} - ${DELTA_TIME}))
elif [ ${DELTA_TIME} -gt ${CACHE_TTL} ]; then
echo "" >> "${CACHE_FILE}" # !!!
DATACACHE=`${REDIS_CLI} info 2>&1`
echo "${DATACACHE}" > "${CACHE_FILE}" # !!!
chmod 640 "${CACHE_FILE}"
fi
case ${METRIC} in
rejected_connections|expired_keys|evicted_keys|keyspace_hits|keyspace_misses|connected_clients|blocked_clients|rdb_last_bgsave_status|total_connections_received|total_commands_processed|used_cpu_sys|used_cpu_user)
$GREP -w ${METRIC} "${CACHE_FILE}" | $AWK -F: '{print $2}'
;;
total_net_input_bytes|total_net_output_bytes)
$GREP -w ${METRIC} "${CACHE_FILE}" | $AWK -F: 'x=$2 {print x/1024/1024}'
;;
used_memory_rss|used_memory_peak|used_memory_overhead|used_memory_startup|used_memory_dataset|used_memory_lua|used_memory|maxmemory)
$GREP -w ${METRIC} "${CACHE_FILE}" | $AWK -F: 'x=$2 {print x/1024/1024}'
;;
*)
help
;;
esac
exit 0
which: no password in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin)
Code:
##### PARAMETERS ##### HOSTNAME=$(hostname -f) AWK=$(which awk) GREP=$(which grep) METRIC="$1" REDIS_CLI=$(which redis-cli -a password)
How should I write authorization in a script, or where to put the password. I would really appreciate any help. Maybe someone has already come across.