Get the App
SLTechnology News&Howtos  ›  Servers  › 

Zabbix monitor how to use scripts to monitor redis services

Shulou Source: shulou.com Published: 2022-06-03 04:22:01 09月17日 Update

zabbix监控如何用脚本监控redis服务?这个问题可能是我们日常学习或工作经常见到的。通过这个问题,希望你能收获更多。今天跟随小编一起来看解决方案吧。

第一步:编写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})

function node_port {length=${#port[@]}

Tags: Scripts monitoring more ports configuration services memory content problems monitoring usage situation skills files schemes methods permissions templates percentage Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Apple Microsoft Shulou Technology Linux