您的位置:首页 > 数据库 > Redis

redis监控zabbix自动化监测端口和内存(shell和python)

2020-01-10 10:40 981 查看
第一步:编写redis python 的端口发现脚本 redis_port.py

#!/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=(',',':'))

编写redis shell 的端口发现脚本 check_redis_port.sh

#!/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})

[p]function node_port {[url=https://blog.51cto.com/14661718/mailto:br/>length=${#port[@]}length=${#port[@]}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: