Zabbix-26 cross-network monitoring and custom monitoring to pass multiple parameters

1. Goal

Master zabbix cross-network (cross-network segment) monitoring, such as using offline zabbix server to monitor Alibaba Cloud ECS server;

Master the method of passing multiple parameters in zabbix_agent custom parameters

2. Description

●The first step is to prepare to implement offline zabbix server monitoring Alibaba Cloud ECS server

The zabbix server was built on centos7.6 in advance.

●The second step is to use the offline zabbix server to monitor the various connections of Alibaba Cloud's nginx_status online

Build the nginx site in advance on ecs, and configure the Nginx_status access policy.

Make it possible to use the public URL to access the nginx_status page. The screenshot of the page effect is as follows:

Three, offline zabbix server monitoring online Alibaba Cloud ECS server

1. Ensure that ECS has opened port 10050 (zabbix_agent uses port 10050 by default).

You can use the telnet command [telnet 123.123.123.123 10050] to test that zabbix_agent on the line can be accessed normally. (123.123.123.123 is the example Alibaba Cloud ECS server ip address)

Pay special attention to the opening of the security group.

2. Ensure that the port 10050 in the outbound direction of offline zabbix is ​​not blocked by the firewall.

You can still use commands similar to [telnet 123.123.123.123 10050] to test

3. Add monitoring host

Add the Alibaba Cloud ECS server to the offline zabbix host list

4. Show my real Alibaba Cloud ECS monitoring diagram below

4. Write custom monitoring scripts to monitor the number of web site visits

1. Description

My zabbix server is built using centos7.6, which is convenient for writing monitoring scripts. This time using shell scripts, it has the characteristics of high speed, convenience, and simple syntax.

After writing the script, use the zabbix server as the monitoring terminal.

2. Write monitoring scripts

vi /data/script/xMonitorNginxStatus.sh
#!/usr/bin/env bash
#active    当前活动的客户端连接数,包括waiting连接数
#accepts   当前的客户端连接数
#handled   已处理的连接总数
#requests  客户端请求的总和
#reading   正在读取请求头的当前连接数
#writing   将响应写回客户端的当前连接数
#waiting   等待请求空闲客户端的当前连接数

#---注意:你的zabbix服务器上必须安装curl#

result="/usr/bin/curl -s $1"
case $2 in
        active)
                $result |awk '/Active/ {print $NF}'
        ;;
        accepts)
                $result |awk 'NR==3 {print $1}'
        ;;
        handled)
                $result |awk 'NR==3 {print $2}'
        ;;
        requests)
                $result |awk 'NR==3 {print $3}'
        ;;
        reading)
                $result |awk '/Reading/ {print $2}'
        ;;
        writing)
                $result |awk '/Writing/ {print $4}'
        ;;
        waiting)
                $result |awk '/Writing/ {print $6}'
        ;;
        *)
                echo -e "\e[1;31m应当输入参数active/accepts/handled/requests/reading/writing/waiting中的任一个\e[0m"
        ;;
esac

3. Pay attention to adding executable permissions to the script (or let the user of the zabbix service have execute permissions)

For example, write like this, but you can’t copy

chmod +x /data/script/xMonitorNginxStatus.sh

4. Modify the zabbix_agentd.conf file on the zabbix server

● Add a line of content where appropriate, such as:

UserParameter=xMonitorNginxStatus[*],"/data/script/xMonitorNginxStatus.sh" $1 $2

Long-winded: $1 is the URL you passed, and $2 is the status name of nginx_status (any one of active/accepts/handled/requests/reading/writing/waiting)

In this way, 2 parameters are passed to the custom script

5. Modify the timeout parameters of zabbix

Nani? What the hell is this?

Because CURL may sometimes be a bit slow when pulling web pages, if the time to pull web pages exceeds 4 seconds, then zabbix will consider the timeout failure.

●Modify the timeout parameter of zabbix_agentd.conf

Find the line that contains [Timeout=], and adjust the value slightly larger, for example, change it to [ Timeout=30 ]

●Modify the timeout parameter of zabbix_server.conf

Find the line that contains [Timeout=], and adjust the value slightly larger, for example, change it to [ Timeout=30 ]

Long-winded: If you are using the yum installation method, the configuration file is in the /etc/zabbix/ directory.

6. Restart the two services on the zabbix server

systemctl restart zabbix-agent
systemctl restart zabbix-server

7. Use the zabbix_get tool under the zabbix shell to check whether the data can be obtained

zabbix_get -s 127.0.0.1 -p 10050 -k xMonitorNginxStatus["http://git.hiibm.com/kahn_status","writing"]

Long-winded: The two quotation marks in the brackets are the two parameters passed to the script.

This command means to execute the user parameter xMonitorNginxStatus on the zabbix server (that is, the custom script /data/script/xMonitorNginxStatus.sh), and then pass two parameters to the script, one is a string of URLs, and the other is a writing string.

If you can get the value correctly in this way, then everything is ok.

 

8. How to display the data obtained by the custom monitoring script just now on the zabbix web page graphically?

Add monitoring items in [Configuration---Host---zabbix server] on the zabbix web page

Then go to add a graphic and it's done.

 

something wrong?

What about monitoring the connection status of other websites?

Just write your URL in the key value of the web page just now.

 

Five, summary

1. The zabbix_agent program uses port 10050 by default, and the client opens port 10050 in the inbound direction

2. The offline zabbix server monitors the online server, and the outgoing direction 10050 of the zabbix server should be opened

3. How to pass multiple parameters in the script of custom parameters: UserParameter=xMonitorNginxStatus[*],"/data/script/xMonitorNginxStatus.sh" $1 $2

--------------------------------------------END October 22, 2020 Day 16:30:09-------------------------------------------- -----

 

Writing technical posts is very time-consuming. If this post is helpful to you, I hope you can support a little bit at will and give me more creative motivation.

Contempt for the White Snake Party

Guess you like

Origin blog.csdn.net/xoofly/article/details/109222979