#!/usr/bin/env python
import os
import json
t=os.popen("""ps aux |grep -v grep |grep redis-server|awk -F '*:' '{print $2}'|awk '{print $1}' """)
ports = []
for port in t.readlines():
r = os.path.basename(port.strip())
ports += [{'{#REDIS_PORT}':r}]
print json.dumps({'data':ports},sort_keys=True,indent=4,separators=(',',':'))
#!/bin/sh
REDIS_SERVER_PIDS="$(ps -ef|egrep -v 'grep|egrep|vi|vim|find|cat|tac|head|tail|more|less'|grep 'redis-server'|awk '{print $2}')"
REDIS_PORTS=""
for pid in ${REDIS_SERVER_PIDS};do
PORTS=$(sudo netstat -anlp|grep -w ${pid}|awk '{print $4}'|awk -F: '{print $2}'|grep -v "[0-9][0-9][0-9][0-9][0-9]"|grep -v "^$" |head -1)
REDIS_PORTS="${PORTS} ${REDIS_PORTS}"
done
port=(${REDIS_PORTS})
function node_port {length=${#port[@]}
br/>length=${#port[@]}
printf '\t'"\"data\":["
for ((i=0;i<$length;i++));do
printf '\n\t\t{'
printf "\"{#REDIS_PORT}\":\"${port[$i]}\"}"
if [ $i -lt $[$length-1] ];then
printf ','
fi
done
printf "\n\t]\n"
printf "}\n"
}
node_port
shell和python选择一种即可。
#!/bin/bash
function redis_cli_command () {
redis_cli_tmp="$(whereis redis-cli|awk -F: '{print $2}')"
${redis_cli_tmp} -v > /dev/null 2>&1
if [ $? -eq 0 ];then
redis_cli="${redis_cli_tmp}"
else
REDIS_USERS="$(ps -ef|egrep -v 'grep|egrep|vi|vim|cat|tac|head|tail|more|less'|grep 'redis-server'|awk '{print $1}'|sort|uniq)"
for user in ${REDIS_USERS};do
USER_HOME="$(cat /etc/passwd|grep ${user}|awk -F: '{print $(NF-1)}')"
if [ -d ${USER_HOME} ];then
redis_cli_tmp="$(sudo find ${USER_HOME}/redis* -type f -name redis-cli|head -1)"
${redis_cli_tmp} -v > /dev/null 2>&1
[ $? -eq 0 ] && redis_cli="${redis_cli_tmp}" && break
fi
done
fi
}
hostip=/sbin/ifconfig|grep 10.169.42| awk '{print $2}'
redis_cli_command
liveness=$(${redis_cli} -h ${hostip} -p $1 ping)
if [ ${liveness} == "PONG" ];then
echo "PONG"
else
echo "error"
fi
#!/bin/bash
function redis_cli_command () {
redis_cli_tmp="$(whereis redis-cli|awk -F: '{print $2}')"
${redis_cli_tmp} -v > /dev/null 2>&1
if [ $? -eq 0 ];then
redis_cli="${redis_cli_tmp}"
else
REDIS_USERS="$(ps -ef|egrep -v 'grep|egrep|vi|vim|cat|tac|head|tail|more|less'|grep 'redis-server'|awk '{print $1}'|sort|uniq)"
for user in ${REDIS_USERS};do
USER_HOME="$(cat /etc/passwd|grep ${user}|awk -F: '{print $(NF-1)}')"
if [ -d ${USER_HOME} ];then
redis_cli_tmp="$(sudo find ${USER_HOME}/redis* -type f -name redis-cli|head -1)"
${redis_cli_tmp} -v > /dev/null 2>&1
[ $? -eq 0 ] && redis_cli="${redis_cli_tmp}" && break
fi
done
fi
}
hostip=/sbin/ifconfig|grep 10.169.42| awk '{print $2}'
redis_cli_command
used_memory=$(${redis_cli} -h ${hostip} -p $1 info|grep 'used_memory:'|awk -F: '{print $2}'|tr -d '\r')
max_memory=$(${redis_cli} -h ${hostip} -p $1 config get maxmemory|tail -1|awk '{print $NF}'|tr -d '"')
if [ ${max_memory} -eq 0 ];then
echo "0"
elif [ ${max_memory} -gt 0 ];then
num_per=echo "scale=0;$used_memory*100"/${max_memory}|bc
echo $num_per
fi
{HOST.NAME}:{#REDIS_PORT} redis ping异常,请检查
{Template for redis:redis.liveness[{#REDIS_PORT}].str(PONG)}=0
{HOST.NAME}:{#REDIS_PORT} redis 内存使用率>80%,达到{ITEM.LASTVALUE1}%
{Template for redis:redis_used_memory_per[{#REDIS_PORT}].last()}>80
UserParameter=redis_port.discovery,/app/sinova/zabbix/scripts/check_redis_port.sh
UserParameter=redis_used_memory_per[*],/app/sinova/zabbix/scripts/redis_used_memory.sh $1
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。