For multi-instance deployments of Tomcat, Redis and other applications, you can use Zabbix's low-level discovery feature to monitor and reduce repetitive operations. Note: Zabbix version: Zabbix 3.0.21, server configuration 1, create template template name: Template_redis_monitor 2, create an Autodiscover rule to add an Autodiscover rule to a template that you have created Template_redis_monitor. 3, add the monitoring item prototype from the above can be seen, I have created 4, as follows: Look at one of the following: Take a look at the monitoring items after the Host association template: second, the client configuration zabbix_agentd.conf configuration file Add or modify the following:
unsafeuserparameters=1 #允许zabbix用户运行root命令UserParameter=redis.discovery,/data/zabbix/ externalscripts/redis_port.py #获取json格式数据, newspapers Userparameter=redis[*],/data/zabbix/externalscripts /redis_stats. SH $1 $2 #自定义Key值
The following two scripts are used:
Script for Discovery Port:
#Catredis_port.py#!/usr/bin/Envpythonimport osimport Jsonp=os.popen ("""sudo netstat-anp|awk-f: '/redis-server/&&/listen/{sub (/. */,""($), if ($) print $} '""") Ports= [] forPortinchP.readlines (): R= Os.path.basename(Port.strip ()) Ports+= [{'{#REDISPORT}': R}] Print Json.dumps ({'Data':p orts},sort_keys=true,indent=4, separators= (',',':'))
To get a script for monitoring data:
#CatRedis_stats.SH#!/bin/Bashmetric=" $"PORT="${2:-6379}"Cache_file="/data/zabbix/externalscripts/redis_$port.cache"Redis-cli-p ${port} A'uslf93suvwtsf$$#@w' Info> ${cache_file}2>/dev/NULL|| Exit1awk-F'[:,]+' '/' "${metric}"':/{gsub (/^[^0-9]+/, "", $;p rint)'${cache_file}
Third, test on Zabbix_server test, execute the following command: Zabbix_get-s client ip-k Redis.discovery
Client Redis Two instance ports are 6380 and 6444, and you can see that the Autodiscover port is successful! Test to see if data is available: Get data successfully! Finally, you can create a graph to view the data: Other issues: ZABBIX_AGENTD is Zabbix user initiated, the default cannot execute commands such as netstat-p, so you can configure sudo resolution. You can also use chmod +s/usr/bin/netstat for resolution.
Zabbix monitoring Redis Multi-instance (low-level discovery)