当前位置:网站首页>ZABBIX custom monitoring item (server monitoring)

ZABBIX custom monitoring item (server monitoring)

2022-06-23 21:24:00 O & M small flame

zabbix The monitoring system is generally used to monitor the server performance or project , The default monitoring template is sometimes difficult to use , Or I don't have what I want , Let's add custom monitoring items 

server End calls agent The key value parameter of the end configuration calls the script , The script parameters are then passed to server End ,server End write into database , Then get the new value, process it and display it to the user at the front end 


 First of all , Write monitoring scripts 
 second , modify zabbix_agent Configuration of 
 Third , stay zabbix_web Add new   Monitoring item   trigger   graphics 

 Prerequisite  zabbix Installed    This time, the order is used KEY Value presentation , Easier to understand 

First of all , Write monitoring scripts

 Here we simply write a script , simulation nginx The state of ( Import random module   Generate random number   It's because you need to make the following graphics look trendy )

#!/usr/bin/python3  #TestNum.py Content 
import random
number = random.randint(1,100)  # Test import random number module generation 1-100 The random number 

with open('/var/log/nginx_code.log','a') as f: # Write random numbers to the log   Facilitate data validation 
         f.write(str(number) + '\n')

print(number) # Print values as required 

# Script finished 

second , modify zabbix_agent Configuration of

# The operation is only on the client side ( Modify the following parameters of the configuration file )
UnsafeUserParameters=1
UserParameter=nginx.code,/usr/bin/python3 /usr/local/zabbix-3.4.11/script/TestNum.py 
# Restart after modification zabbix_agent client 
/etc/init.d/zabbix_agentd restart   # Restart and take effect 

 Skip the following 3 Step ( There will be no demonstration this time ):
UserParameter You can also get multiple through scripts key Value ( The production environment has been used for a long time KEY value ):
UserParameter=mysql.status[*],/usr/local/zabbix/scripts/check_mysql.sh $1               # The example will not be demonstrated this time 
UserParameter=check_port[*],/usr/local/zabbix/scripts/check_port.sh -H 127.0.0.1 -p $1  # The example will not be demonstrated this time 
# Modify the permissions 
chown zabbix.zabbix /var/log/nginx_code.log     #zabbix The user specified for the source installation 
chown zabbix.zabbix /usr/local/zabbix-3.4.11/script/TestNum.py   
chmod 766  /var/log/nginx_code.log
chmod 766  /usr/local/zabbix-3.4.11/script/TestNum.py  
chmod +x   /usr/local/zabbix-3.4.11/script/TestNum.py  # Script add execute permission 

Third , stay zabbix_web Add new Monitoring item trigger graphics

1  Add monitor  ( After that, slide to the bottom to update )  To configure --> host --> Monitoring item --> Create monitor item 

 Add success ( as follows   Status OK enabled )  abnormal : It will show that it doesn't support ( Red ), If it is normal, it shows enabled ( green )

 Start adding graphics ( To configure --> host --> graphics --> Create graphics )  ps: Triggers and graphs are configured on the basis of monitoring items , Because monitoring items are used to obtain real-time data 

 After adding graphics , Update view ( as follows )

 Check whether the status code output by the script corresponds to the graph , At present, they are consistent ( It should be output with a time , It looks clearer   ha-ha )

 Graphics added 
 Next, add a trigger ( The steps are as follows ) ps: Set according to your own requirements N Value trigger   And then update 

 The next step is to verify ( For demonstration , The set value is easy to trigger , Trigger as follows :)

 Triggered   Verification completed  Over ( as follows )

原网站

版权声明
本文为[O & M small flame]所创,转载请带上原文链接,感谢
https://yzsam.com/2021/12/202112241702047901.html