In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Step 1: write the port discovery script redis_port.py for redis python
#! / 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= (',',':))
Write a port discovery script check_redis_port.sh for redis shell
#! / bin/sh
REDIS_SERVER_PIDS= "$(ps-ef | egrep-v 'grep | egrep | vi | vim | find | cat | tac | head | 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] [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 / 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 | 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
Percentage of memory usage monitored
#! / 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 | 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
Zabbix template configuration
Automatic discovery
Trigger
{HOST.NAME}: {# REDIS_PORT} redis ping exception, please check
{Template for redis:redis.liveness [{# REDIS_PORT}] .str (PONG)} = 0
{HOST.NAME}: {# REDIS_PORT} redis memory utilization > 80%, reaching {ITEM.LASTVALUE1}%
{Template for redis:redis_used_memory_per [{# REDIS_PORT}] .last ()} > 80
Restart after zabbix configuration file is added
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
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.