The last article (Zabbix distributed Server monitoring system installation and deployment (I) records the installation and deployment of the entire Zabbix System, including the Server and client segments, this article mainly describes how to install and configure the custom monitoring metrics of Zabbix. Because I only use some data and other information to monitor mysql
The last article (Zabbix distributed Server monitoring system installation and deployment (I) records the installation and deployment of the entire Zabbix System, including the Server and client segments, this article mainly describes how to install and configure the custom monitoring metrics of Zabbix. Because I only use some data and other information to monitor mysql
The last article (Zabbix distributed Server monitoring system installation and deployment (I) records the installation and deployment of the entire Zabbix System, including the Server and client segments, this article mainly describes how to install and configure the custom monitoring metrics of Zabbix.
Because I only use some data and other information to monitor mysql, I only keep this record. According to the official help documentation, Zabbix provides a template for mysql monitoring, you need to download and import the data by yourself, officially, or download the backup: template_MySql.
After downloading the file, Import it on the Zabbixweb Management page. Configure-Templates-Import Templates. Select the appropriate xml template to Import the file.
Edit the configuration file under etc/zabbix. At the bottom of zabbix_agentd.conf, remove the # Above the following content. Remember to change the mysql account and password:
UserParameter=mysql.ping,mysqladmin -uroot -ppasswd ping|grep alive|wc -lUserParameter=mysql.uptime,mysqladmin -uroot -ppasswd status|cut -f2 -d":"|cut -f1 -d"T"UserParameter=mysql.threads,mysqladmin -uroot -ppasswd status|cut -f3 -d":"|cut -f1 -d"Q"UserParameter=mysql.questions,mysqladmin -uroot -ppasswd status|cut -f4 -d":"|cut -f1 -d"S"UserParameter=mysql.slowqueries,mysqladmin -uroot -ppasswd status|cut -f5 -d":"|cut -f1 -d"O"UserParameter=mysql.qps,mysqladmin -uroot -ppasswd status|cut -f9 -d":"UserParameter=mysql.version,mysql -V
The preceding monitoring parameters are relatively simple.
If not, run the following command in the preceding directory:
vi mysql_status.py
Create a new file and enter the following content:
#!/usr/bin/env python # -*- coding: utf-8 -*- #File:mysql_status.py import MySQLdb,sys user = 'root'passwd = 'passwd'a = sys.argv[1] try: conn = MySQLdb.connect(host = '127.0.0.1',user = user,passwd = passwd,connect_timeout = 2) cursor = conn.cursor() sql = "SHOW STATUS" cursor.execute(sql) alldata = cursor.fetchall() for data in alldata: if data[0] == a : #print data[0],data[1] print data[1] break cursor.close() conn.close() except Exception, e: print e sys.exit() '''''Open_tables Opened_tables Max_used_connections Threads_connected Qcache_free_blocks Qcache_total_blocks Handler_read_first Handler_read_key Handler_read_rnd_next Slow_queries'''
Save. Add the following content under zabbix_agentd.conf:
UnsafeUserParameters=1UserParameter=mysql.Open_tables,/etc/zabbix/mysql_status.py Open_tables UserParameter=mysql.Opened_tables,/etc/zabbix/mysql_status.py Opened_tables UserParameter=mysql.Max_used_connections,/etc/zabbix/mysql_status.py Max_used_connections UserParameter=mysql.Threads_connected,/etc/zabbix/mysql_status.py Threads_connected UserParameter=mysql.Qcache_free_blocks,/etc/zabbix/mysql_status.py Qcache_free_blocks UserParameter=mysql.Qcache_total_blocks,/etc/zabbix/mysql_status.py Qcache_total_blocks UserParameter=mysql.Handler_read_first,/etc/zabbix/mysql_status.py Handler_read_first UserParameter=mysql.Handler_read_key,/etc/zabbix/mysql_status.py Handler_read_key UserParameter=mysql.Handler_read_rnd_next,/etc/zabbix/mysql_status.py Handler_read_rnd_next UserParameter=mysql.Slow_queries,/etc/zabbix/mysql_status.py Slow_queries
Then you can add visual data, such as graphics, to the web...
The following record adds custom monitoring, such as increasing number of monitored users or a port...
Add the following content to zabbix_agentd.conf:
UserParameter=myhost.user,mysql -u root -ppasswd -e "use you_dbname;select count(*) from user" |tail -1
Explanation:
Myhost. user is the Key, which must be used in web settings;
-U root-ppasswd is the mysql user name and password;
You_dbname: the database you want to operate on;
Select count (*) from user SQL statement;
UserParameter=myhost.port1005,netstat -ant | sed -n '1,2!p'|awk '{ if($6!="LISTEN") {if(match($4,"'1005'")) c=c+1}} END{print c}'
The above sentence is port listening. Replace 1005 with the port number you want to listen.
Restart the Zabbix-agentd service.
sudo service zabbix-agent restart
Then, you can test whether the listener is successful on the Zabbix Server. The command is as follows:
zabbix_get -s 192.168.1.106 -k myhost.user
If it succeeds, the data is displayed.
Add items to the web, perform the operation, and find Configuration -- Hosts -- click itmes of the corresponding host. The itmes list of the current host is displayed, and click Create item in the upper right corner.
After creating a chart, you can select this metric item.
Related reading:
[Memo] Zabbix distributed server monitoring system installation and deployment (1)
Original article address: Add and configure custom metrics for Zabbix server monitoring system deployment (2). Thank you for sharing it with me.