Application of Zabbix automatic discovery monitoring Redis Multi-instance

Source: Internet
Author: User
Tags json redis

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 $ $

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.