Low level discovery monitoring redis for zabbix enterprise applications

Source: Internet
Author: User
Tags echo info

I have introduced redis using zabbix to monitor fixed port 6379 (article address is http://dl528888.blog.51cto.com/2382721/1361407), there is a bad place that only monitoring fixed port 6379, if it is not port 6379, you need to modify the template. If the host has multiple redis instances, you need to have different redis templates and manage monitoring. This is very troublesome. To solve this problem, I use lld (low level discovery) to monitor redis. You only need to mark the port to be monitored in the regular expression to monitor multiple redis instances.

The following is monitoring:

1. Redis 20000 Port Connections

WKioL1MT5fuTl331AAQktsi8GGc337.jpg

2. Redis 20000 Port key

WKiom1MT5m3j5v3vAAPHA-Z2xdY859.jpg

3. Redis 20000 Port Last_save_time

WKiom1MT5p3RZPscAAPUilCx0N8911.jpg

4. Redis 20000 Port status

WKioL1MT5rKgk624AAOkTIkbnHY590.jpg

5. Redis 20000 Port Uptime_in_seconds

WKioL1MT5xzzuX1fAAOeH4KTQvM868.jpg

6. Redis 20000 Port Used memory

Wkiom1mt54gbaw.maamyd0rebqg772.jpg

How to implement:

I. Client

1. json-based monitoring content

In the client, the monitoring content needs to be displayed in json format, and then the server can filter the results through regular expressions.

Below is the json display of my json monitoring redis

WKiom1MT7yrAIIWSAACL1Sd60Rg007.jpg

The script content is as follows:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

#! /Bin/bash
# Fucation: mysql low-level discovery
# Script_name redis_low_discovery.sh
Redis (){
Port = ($ (sudo netstat-tpln | awk-F "[:] +" '/redis/& amp;/0.0.0.0/{print $5 }'))
Printf' {\ N'
Printf' \ t "data": [\ N'
For key in $ {! Port [@]}
Do
If [["$ {# port [@]}"-gt 1 & "$ {key}"-ne "$ ($ {# port [@]}-1 )) "]; then
Socket = 'ps aux | grep $ {port [$ {key}]} | grep-v grep | awk-F' = ''{print $10} '| cut-d ''-f 1'
Printf' \ t {\ N'
Printf "\ t \" {# REDISPORT} \ ": \" $ {port [$ {key}]} \ "}, \ n"
Else [["$ {key}"-eq "($ {# port [@]}-1)"]
Socket = 'ps aux | grep $ {port [$ {key}]} | grep-v grep | awk-F' = ''{print $10} '| cut-d ''-f 1'
Printf' \ t {\ N'
Printf "\ t \" {# REDISPORT} \ ": \" $ {port [$ {key}]} \ "} \ n"
Fi
Done
Printf' \ t] \ N'
Printf'} \ N'
}
$1

Store the file in/usr/local/zabbix/bin, grant 755 permissions, modify the user and group to zabbix, and allow zabbix users to run netstat without a password.
1

Echo "zabbix ALL = (root) NOPASSWD:/bin/netstat">/etc/sudoers

# Disable requiretty
1

Sed-I's/^ Defaults. *. requiretty/# Defaults requiretty/'/etc/sudoers

If it is not disabled, data cannot be obtained and the zabbix log reports

WKioL1L5lG7DIj1bAADTHBgUAt4491.jpg

2. Modify the zabbix_agentd.conf File

Add the following content at the end of zabbix_agentd.conf:
1
2

UserParameter = zabbix_low_discovery [*],/bin/bash/usr/local/zabbix/bin/redis_low_discovery.sh $1
UserParameter = redis_stats [*], (echo info; sleep 1) | telnet 127.0.0.1 $1> & 1 | grep $2 | cut-d:-f2

Set the telnet ip address in redis_stats according to your environment.

Test

If you can get data through the/usr/local/zabbix/bin/zabbix_get-s 127.0.0.1-k zabbix_low_discovery [redis] command, it means no problem.

WKioL1MT9xbyWV9PAACr6829dkc725.jpg

3. Restart the zabbix service.
1
2

Ps-ef | grep zabbix | grep-v grep | awk '{print $2}' | xargs kill-9
/Usr/local/zabbix/sbin/zabbix_agentd-c/usr/local/zabbix/conf/zabbix_agentd.conf

Ii. Server

1. template Import

Import the Template Redis Auto Discovery into zabbix (the Template is included in the attachment). The specific operations are not described.

2. Set the Regular Expression

In "manage" = "general" = "Regular Expression", select "new regular expression"

Then, set the settings as follows:

WKioL1MT97Pzv4GDAAJ_GhR5I0o411.jpg

I am running many redis instances.

3. Host Association Template

You can monitor the host management template of the redis instance, which is automatically updated 3600 seconds by default, as shown in figure

WKiom1MT-CTTPlIiAAJ3kZAdPX0616.jpg

Why set 3600 seconds? The reason is that if the setting time is too short, for example, if you set 60 s, one is the pressure on the server, and the other is that if the port you detect suddenly drops, there is no urgent alarm, if the host cannot obtain this information through json, it is deemed that this port is not available. The content of this metric item is automatically disabled in the template (30 days by default, and then automatically deleted ), in this way, the alarm function is basically unavailable, so it is better to find a longer interval.

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.