When using Zabbix custom scripts to collect monitoring data, you will usually encounter the following problems:
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: 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: 7. Observe whether the data is normal: 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. 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:
|
<<: 5 Simple XHTML Web Forms for Web Design
>>: How to write the style of CSS3 Tianzi grid list
Since I usually use the docker build command to g...
The img tag introduces the image Because react ac...
Add a DOCTYPE to the page Since different browser...
1. Preparation before installation 1. Download th...
Assuming business: View the salary information of...
Before introducing the new CSS property contain, ...
Hash Join Hash Join does not require any indexes ...
Table of contents 1. Startup management of source...
question: When developing the Alice management sy...
I remember a question the interviewer asked durin...
01. Compile options and kernel compilation The Li...
I haven't worked with servers for a while. No...
less file name View File less file name | grep -n...
Use the --all-database parameter when performing ...
I encountered a little problem when configuring t...