The implementation principle of Zabbix dynamic execution monitoring collection script

The implementation principle of Zabbix dynamic execution monitoring collection script

When using Zabbix custom scripts to collect monitoring data, you will usually encounter the following problems:

  • After the server capacity is expanded, how to deploy the monitoring script to the new server?
  • When a monitoring script needs to be modified, how can all identical monitoring scripts be automatically modified?
  • How to back up monitoring and collection scripts to avoid loss due to server abnormalities?
  • How to avoid excessive operations by system administrators when deploying custom monitoring?
  • How can we solve the above problems without extensive R&D?

Implementation principle : Use the file server to uniformly store and manage monitoring scripts, pre-embed the general script in the zabbix agent, and pull the script from the file server according to the key and parameters transmitted by the zabbix server and return the data after execution.

Architecture design:

insert image description here

Specific implementation:

1. Build a file server, taking nginx as an example

Modify the nginx configuration and restart

erver
    listen 8080;
    server_name zabbix;
    root /usr/local/static/;
    location / {
      autoindex on;
      autoindex_exact_size on;
      autoindex_localtime on;
      charset utf-8;
    }
  }

2. Write scripts for file pulling and execution

url="http://192.168.24.108:8080/" #Define the URL of the file server
parentDir="/usr/local/zabbix/bin/zabbix_script" 
file_directory=$parentDir/$1 #Define the directory where the script is stored locally file_name=$2 #Script name file_path=$1/$2 #Join the script path of the file server if [ ! -d $file_directory ];then #Judge whether the file directory exists mkdir -p $file_directory
fi

if [ ! -f $parentDir/$file_path ];then #Judge whether the script already exists wget -P $file_directory $url$file_path 2>>log
fi

timestamp=$(date +%s)
filetimestamp=$(stat -c %Y $parentDir/$file_path)
if [ $[$timestamp - $filetimestamp] -gt 3600 ];then #Judge the difference between the current time and the script modification time, and update every 3600 seconds wget $url$file_path -O $parentDir/$file_path 2>>log #Overwrite the script touch -c $parentDir/$file_path #Modify the script modification time fi
python $parentDir/$file_path $3 #Execute the script

3. Add the configuration file of zabbix

UserParameter=requests_file[*],sh /usr/local/zabbix/bin/zabbix_script/requests_file.sh $1 $2 $3

4. Restart zabbix agent

5. Write the test script and upload it to the specified directory of the file server

#Monitor the number of server connections#!/usr/bin/python
import pwd
import os,sys
import re
import glob
state = sys.argv[1]

cmd = "netstat -an | grep " + state + " | wc -l"
os.system(cmd)

6. Configure the monitoring items of the zabbix page:

insert image description here

7. Observe whether the data is normal:

insert image description here

8. The new monitoring script is placed after the file server, and the monitoring items of the configuration page can be directly configured for data collection.

insert image description here

This article focuses on providing a solution for centralized management of custom monitoring scripts in Zabbix. Based on this idea, you can freely expand the use of Zabbix to be more concise and efficient, further simplifying operation and maintenance.

Reference Links:

How does Zabbix dynamically execute monitoring collection scripts: https://mp.weixin.qq.com/s/ikuCSYhlFdtiAmt7epskWw

This is the end of this article about the implementation principle of Zabbix dynamic execution monitoring and collection script. For more relevant Zabbix dynamic execution monitoring and collection script content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Zabbix WEB monitoring implementation process diagram
  • Example code for configuring monitoring items and aggregated graphics in Zabbix
  • Detailed tutorial on how to monitor Nginx/Tomcat/MySQL using Zabbix
  • zabbix custom monitoring nginx status implementation process

<<:  5 Simple XHTML Web Forms for Web Design

>>:  How to write the style of CSS3 Tianzi grid list

Recommend

Delete the image operation of none in docker images

Since I usually use the docker build command to g...

Several ways to introduce pictures in react projects

The img tag introduces the image Because react ac...

Cross-browser development experience summary (I) HTML tags

Add a DOCTYPE to the page Since different browser...

VMware15.5 installation Ubuntu20.04 graphic tutorial

1. Preparation before installation 1. Download th...

Summary of three ways to implement ranking in MySQL without using order by

Assuming business: View the salary information of...

CSS new feature contain controls page redrawing and rearrangement issues

Before introducing the new CSS property contain, ...

Mysql 8.0.18 hash join test (recommended)

Hash Join Hash Join does not require any indexes ...

Service management of source package installation under Linux

Table of contents 1. Startup management of source...

Solution to the conflict between nginx and backend port

question: When developing the Alice management sy...

What are HTML inline elements and block-level elements and their differences

I remember a question the interviewer asked durin...

How to purchase and initially build a server

I haven't worked with servers for a while. No...

Detailed explanation of Linux less command examples

less file name View File less file name | grep -n...

How to filter out certain libraries during mysql full backup

Use the --all-database parameter when performing ...

Solution to Tomcat server failing to open tomcat7w.exe

I encountered a little problem when configuring t...