This article mainly introduces the simple use of Zabbix macros and monitors Redis related metrics through custom scripting.
Zabbix monitoring Redis requires a custom script to monitor, and scripts on the network are not very useful for having multiple Redis instances on a single machine. the next monitoring script is modified so that it can accept incoming port parameters.
Principle: Filter out information for info output via Redis Client connection command
I. Introduction and definition of ZABBIX macro
1. Introduction to Macros
(1) A macro is an abstraction that replaces a certain set of text patterns based on a series of predefined rules, and the interpreter or compiler automatically makes this pattern substitution when it encounters a macro, which can be understood as a variable.
(2) Zabbix There are many built-in macros, such as {host.name} {host. IP} , {trigger. DESCRIPTION} , {trigger.name} {trigger. EVENTS. ACK}
(3) for greater flexibility, Zabbix supports global, template, or host-level custom macros that users customize macros to use ' {$MACRO} ' This special syntax format, the name of the macro can only use uppercase letters, numbers and underscores
(4)macros can be applied toItem Keysand theDescriptions,Triggername and expression -type, host interfaceIp/dnsand Ports,Discoverymechanism ofSNMPProtocol information about the medium
(5) When you repeatedly reference the same value in multiple monitoring items, use a macro at this time to make subsequent modifications easier
2. priority of the macro
Prioritize using host macros, followed by template macros, and finally using global macros
3. definition of host macros
The Redis instance port is defined here
Select Configure----> Host----> select the appropriate host
650) this.width=650; "Src=" Http://s1.51cto.com/wyfs02/M01/87/3C/wKioL1fYxhzwue7HAABqETj0dqA995.png-wh_500x0-wm_3 -wmp_4-s_1659060767.png "title=" 01.png "alt=" Wkiol1fyxhzwue7haabqetj0dqa995.png-wh_50 "/>
4. definition of template macros
Select configuration----> Templates----> select the appropriate template
650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M01/87/3F/wKiom1fYxi6zL3SbAABELKMEI1g306.png-wh_500x0-wm_3 -wmp_4-s_3290969120.png "title=" 02.png "alt=" Wkiom1fyxi6zl3sbaabelkmei1g306.png-wh_50 "/>
5. Definition of global macros
Select Management----> General----> select macros
650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M00/87/3C/wKioL1fYxjmT8hWWAAAni8ZyVP4456.png-wh_500x0-wm_3 -wmp_4-s_225051867.png "title=" 03.png "alt=" Wkiol1fyxjmt8hwwaaani8zyvp4456.png-wh_50 "/>
Second, create a monitoring capture script
1. script content:
#catcheck_redis. Sh
#!/bin/bash
Redispath= "/usr/local/redis3379_6_test/bin/redis-cli"
Host= "127.0.0.1"
Port= "$"
Redis_pa= "$REDISPATH-H $HOST-P $PORT Info"
Redis_pi= "$REDISPATH-H $HOST-P $PORT Ping"
if [[$# = = 2]];then
Case $ in
# memory
Used_memory)
result= ' $REDIS _pa|/bin/grepused_memory|awk-f ': ' {print $NF} ' |awk ' Nr==1 '
Echo $result
;;
Used_memory_human)
result= ' $REDIS _pa|/bin/grepused_memory_human | Awk-f ":" ' {print $NF} ' |awk-f ' K ' {print '} '
Echo $result
;;
Used_memory_peak_human)
result= ' $REDIS _pa|/bin/grepused_memory_peak_human | Awk-f ":" ' {print $NF} ' |awk-f ' K ' {print$1} '
Echo $result
;;
Used_memory_peak)
result= ' $REDIS _pa|/bin/grepused_memory_peak|awk-f ': ' {print $NF} ' |awk ' Nr==1 '
Echo $result
;;
# status
INSTANTANEOUS_OPS_PER_SEC)
result= ' $REDIS _pa|/bin/grep-w "Instantaneous_ops_per_sec" | Awk-f ': ' {print $} '
Echo $result
;;
connected_clients)
result= ' $REDIS _pa|/bin/grepconnected_clients|awk-f ': ' {print $NF} '
Echo $result
;;
Statu)
result= ' $REDIS _pi|/bin/grep-c PONG '
Echo $result
;;
# Replication
Role
result= ' $REDIS _pa|/bin/grep role | Awk-f ': ' {print $NF} '
Echo $result
;;
connected_slaves)
result= ' $REDIS _pa|/bin/grep-w "connected_slaves" | Awk-f ': ' {print $} '
Echo $result
;;
Master_link_status)
result= ' $REDIS _pa|/bin/grep-w "Master_link_status" |awk-f ': ' {print $} ' |/bin/grep-c up '
Echo $result
;;
Esac
# Db0:key
elif [[$# = = 3]];then
Case $ in
Keys
result= ' $REDIS _pa| /bin/grep-w "Db0" | /bin/grep-w "$" | /bin/grep-w "Keys" |awk-f ' =|, ' {print $} '
Echo $result
;;
Expires
result= ' $REDIS _pa| /bin/grep-w "Db0" | /bin/grep-w "$" | /bin/grep-w "Expires" | Awk-f ' =|, ' {print $4} '
Echo $result
;;
AVG_TTL)
result= ' $REDIS _pa|/bin/grep-w "Db0" | /bin/grep-w "$" | /bin/grep-w "Avg_ttl" | Awk-f ' =|, ' {print $6} '
Echo $result
;;
*)
echo "Usage:$0{db0 keys|db0expires|db0 Avg_ttl}"
;;
Esac
Fi
2. Script Use
Storage location: /usr/local/zabbix/etc/scripts
Function: script can accept three parameters, monitor whether Redis instance is online, memory usage, number of client connections, master-slave synchronization status, etc.
Third, modify the agent configuration file
1. Modify zabbix_agentd.conf
include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/
2. define the key to monitor Redis under zabbix_agentd.conf.d
#cat redis_info.confuserparameter=redis_info[*],/usr/local/zabbix/etc/scripts/check_redis.sh
3. Restart Agent service
Iv. creating a monitoring item in the Web interface
1. Create Redis status Items
650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M02/87/3C/wKioL1fYxlOi8qCiAACaSwDKbKs064.png-wh_500x0-wm_3 -wmp_4-s_1563212007.png "title=" 04.png "alt=" Wkiol1fyxloi8qciaacaswdkbks064.png-wh_50 "/>
2. Create Redis memory usage items
650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M00/87/3F/wKiom1fYxmDw148pAACbtPHeEjk971.png-wh_500x0-wm_3 -wmp_4-s_1958356238.png "title=" 05.png "alt=" Wkiom1fyxmdw148paacbtpheejk971.png-wh_50 "/>
3. create Db0 average hit ratio items
650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M01/87/3C/wKioL1fYxnHQGnBgAACgcgqXOxI007.png-wh_500x0-wm_3 -wmp_4-s_1503304657.png "title=" 06.png "alt=" Wkiol1fyxnhqgnbgaacgcgqxoxi007.png-wh_50 "/>
Description
1. The first parameter is the instance port defined in the host macro, the second parameter is the monitored information, these parameters are passed to the monitoring script, and the monitoring script obtains the relevant monitoring information according to the parameters passed in.
2. The first parameter is the instance port defined in the host macro, the second parameter is the DB name, the third parameter is the monitored information, the parameters are passed to the monitoring script, and the monitoring script obtains the relevant monitoring information according to the parameters passed in.
V. Viewing monitoring data
Select----> Latest data in monitoring----> select the appropriate filter criteria
650) this.width=650; "Src=" Http://s1.51cto.com/wyfs02/M00/87/3F/wKiom1fYxoOCp5fJAADXp0l_9NE908.png-wh_500x0-wm_3 -wmp_4-s_3409102524.png "title=" 07.png "alt=" Wkiom1fyxoocp5fjaadxp0l_9ne908.png-wh_50 "/>
This article is from the "Linux Road" blog, make sure to keep this source http://hnr520.blog.51cto.com/4484939/1852655
Zabbix monitoring Redis Configuration and the use of macros