您好,登錄后才能下訂單哦!
#!/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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。