zabbix自动发现监控redis多实例

2023年 7月 15日 57.4k 0

计算每秒命中率,这里脚本获取到底是当前命中率,模板中可调试

我在github上面重新修改了监控,监控脚本和模板redis-info-status.xml,你可以关注此项目。

这里的命中率需要命中才会计算才会有值

[root@c7-test scripts]# cat redis_hits.sh 
#!/bin/bash
# -------------------------------------------------------------------------------
# Filename:    redis3.0.7
# Revision:    1.1
# Date:        20160707
# Author:      mark
# Email:       usertzc@163.com
# Website:     www.linuxea.com
# -------------------------------------------------------------------------------
# Notice
# redis Take hits
# is scripts Take hits hits/(hits+misses)
#################################################################################
#REDISPORT=$1
/usr/local/bin/redis-cli -h 127.0.0.1 -p $1 info > /tmp/redis-$1-info.txt
hits=`awk -F ':' '/keyspace_hits/{print $2}' /tmp/redis-$1-info.txt`
misses=`awk -F ':' '/keyspace_misses/{print $2}' /tmp/redis-$1-info.txt`
a=$hits
#a=14414110

#b=3228654
b=$misses
c=`awk 'BEGIN{a=$a;b=$b;print '$a+$b'}'`
awk 'BEGIN{c=$c;a=$a;print '$a/$c*100'}'
#awk '{a[NR]=$2;b[NR]=$1;s+=$1}END{for (j=1;j<=NR;j++) printf "%s %.2f%n",a[j],b[j]*100/s}'

这里是自动发现端口

[root@c7-test scripts]# cat redis-port.py 
#!/usr/bin/env python
# -------------------------------------------------------------------------------
# Filename:    redis3.0.7
# Revision:    1.1
# Date:        20160707
# Author:      mark
# Email:       usertzc@163.com
# Website:     www.linuxea.com
# -------------------------------------------------------------------------------
# Notice
# redis auto Discovery port
# is scripts Use ps to view the output port after .json format 
#################################################################################

import os
import json
t=os.popen("""ps -ef|grep redis-server|grep -v grep|awk -F'(:| )+' '{print $13}' """)
ports = []
for port in  t.readlines():
        r = os.path.basename(port.strip())
        ports += [{'{#REDISPORT}':r}]
print json.dumps({'data':ports},sort_keys=True,indent=4,separators=(',',':'))

UserParameter设置:

UserParameter=redis_port,/etc/zabbix/scripts/redis-port.py
UserParameter=redis_info[*],/usr/bin/redis-cli -h 127.0.0.1 -p $1 info |awk -F':'  '/$2>/{print $$2}'
UserParameter=redis_hits[*],/etc/zabbix/scripts/redis_hits.sh $1 $2

redis.png模板下载 密码:o5xm

相关文章

对接alertmanager创建钉钉卡片(1)
手把手教你搭建OpenFalcon监控系统
无需任何魔法即可使用 Ansible 的神奇变量“hostvars”
openobseve HA本地单集群模式
基于k8s上loggie/vector/openobserve日志收集
openobseve单节点和查询语法

发布评论