Calculate the hit rate per second, where the script gets the current hit rate, the template can be debugged
The hit rate needs to be calculated before it can be evaluated.
[Root@c7-test scripts]# Cat redis_hits.sh
#!/bin/bash
# -------------------------------------------------------------------------------
# -------------------------------------------------------------------------------
# Notice
# Redis Take Hits
# is Scripts Take hits hits/(hits+misses)
#################################################################################
#REDISPORT =$1
/usr/local/bin/redis-cli-h 127.0.0.1-p $ info >/tmp/redis-$1-info.txt
Hits= ' awk-f ': '/keyspace_hits/{print $} '/tmp/redis-$1-info.txt '
Misses= ' awk-f ': '/keyspace_misses/{print $} '/tmp/redis-$1-info.txt '
A= $hits
#a =14414110
#b =3228654
b= $misses
C= ' awk ' begin{a= $a b= $b;p rint ' $a + $b '} '
awk ' begin{c= $c a= $a;p rint ' $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} '
This is the automatic discovery port.
[Root@c7-test scripts]# Cat redis-port.py
#!/usr/bin/env python
# -------------------------------------------------------------------------------
# -------------------------------------------------------------------------------
# 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 $} '" ")
Ports = []
For port in T.readlines ():
R = Os.path.basename (Port.strip ())
Ports + = [{' {#REDISPORT} ': R}]
Print json.dumps ({' Data ':p orts},sort_keys=true,indent=4,separators= (', ', ': '))
Userparameter settings:
userparameter=redis_port,/etc/zabbix/scripts/redis-port.py
Userparameter=redis_info[*],/usr/bin/redis-cli-h 127.0.0.1-p $ info |awk-f ': '/$2\>/{print $$2} '
Userparameter=redis_hits[*],/etc/zabbix/scripts/redis_hits.sh $ $