Zabbix服务器监控系统部署之自定义监控项的添加及配置(二)
上一篇文章(Zabbix分布式服务器监控系统安装及部署(一))记录了Zabbix整套系统的安装及部署,其中包含Server端和client段,主要是说安装及配置的事儿了,本文章主要记录Zabbix的自定义监控项配置。 因为我用到只是监控mysql的一些数据等信息,所以也只记
上一篇文章(Zabbix分布式服务器监控系统安装及部署(一))记录了Zabbix整套系统的安装及部署,其中包含Server端和client段,主要是说安装及配置的事儿了,本文章主要记录Zabbix的自定义监控项配置。
因为我用到只是监控mysql的一些数据等信息,所以也只记录这一块儿的,按照官方帮助文档中的说法,Zabbix提供了mysql的监控的模板,需要用户自己下载导入,官方下载地址,或者下载我提供的备用的:template_MySql。
下载后在Zabbixweb管理页面中导入,Configuration— Templates — Import Templates.选择相应xml模板导入即可。
编辑 etc/zabbix 下的配置文件,zabbix_agentd.conf 最下方,将以下内容前面的#去掉,记得将mysql的账号跟密码换掉:
UserParameter=mysql.ping,mysqladmin -uroot -ppasswd ping|grep alive|wc -l UserParameter=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
以上自带的监控参数比较简单。
若不够的话,可以将在上述目录下执行以下命令:
vi mysql_status.py
创建这样一个新的文件,在里面输入以下内容:
#!/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'''
保存。然后在zabbix_agentd.conf下方加入以下内容:
UnsafeUserParameters=1 UserParameter=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
接着便可以在web中添加图形之类的直观数据了。。。
下面记录添加自定义的监控,如:监控用户数的增长,或者某个端口的情况等…
在zabbix_agentd.conf中,加入以下内容:
UserParameter=myhost.user,mysql -u root -ppasswd -e "use you_dbname;select count(*) from user" |tail -1
解释:
myhost.user 为Key,回头web设置中需要用到;
-u root -ppasswd 为mysql的用户名密码;
you_dbname 你要操作的数据库;
select count(*) from user sql语句;
UserParameter=myhost.port1005,netstat -ant | sed -n '1,2!p'|awk '{ if($6!="LISTEN") {if(match($4,"'1005'")) c=c+1}} END{print c}'
以上一句为端口监听。将1005换成你需要监听的端口号就可以。
重启Zabbix-agentd服务。
sudo service zabbix-agent restart
然后可以在Zabbix Server服务器上测试下是否监听成功,命令:
zabbix_get -s 192.168.1.106 -k myhost.user
若成功的话,便会显示出查得的数据了。
接着在 web中添加items,操作步骤,找到:Configuration —— Hosts —— 点击相应host的itmes,进入后会列出当前该主机的itmes列表,点击右上角Create item。
完成后,在创建图表的时候,便可以选择这个监控项了。
相关阅读:
[备忘]Zabbix分布式服务器监控系统安装及部署(一)
原文地址:Zabbix服务器监控系统部署之自定义监控项的添加及配置(二), 感谢原作者分享。

How to effectively monitor MySQL performance? Use tools such as mysqladmin, SHOWGLOBALSTATUS, PerconaMonitoring and Management (PMM), and MySQL EnterpriseMonitor. 1. Use mysqladmin to view the number of connections. 2. Use SHOWGLOBALSTATUS to view the query number. 3.PMM provides detailed performance data and graphical interface. 4.MySQLEnterpriseMonitor provides rich monitoring functions and alarm mechanisms.

The difference between MySQL and SQLServer is: 1) MySQL is open source and suitable for web and embedded systems, 2) SQLServer is a commercial product of Microsoft and is suitable for enterprise-level applications. There are significant differences between the two in storage engine, performance optimization and application scenarios. When choosing, you need to consider project size and future scalability.

In enterprise-level application scenarios that require high availability, advanced security and good integration, SQLServer should be chosen instead of MySQL. 1) SQLServer provides enterprise-level features such as high availability and advanced security. 2) It is closely integrated with Microsoft ecosystems such as VisualStudio and PowerBI. 3) SQLServer performs excellent in performance optimization and supports memory-optimized tables and column storage indexes.

MySQLmanagescharactersetsandcollationsbyusingUTF-8asthedefault,allowingconfigurationatdatabase,table,andcolumnlevels,andrequiringcarefulalignmenttoavoidmismatches.1)Setdefaultcharactersetandcollationforadatabase.2)Configurecharactersetandcollationfor

A MySQL trigger is an automatically executed stored procedure associated with a table that is used to perform a series of operations when a specific data operation is performed. 1) Trigger definition and function: used for data verification, logging, etc. 2) Working principle: It is divided into BEFORE and AFTER, and supports row-level triggering. 3) Example of use: Can be used to record salary changes or update inventory. 4) Debugging skills: Use SHOWTRIGGERS and SHOWCREATETRIGGER commands. 5) Performance optimization: Avoid complex operations, use indexes, and manage transactions.

The steps to create and manage user accounts in MySQL are as follows: 1. Create a user: Use CREATEUSER'newuser'@'localhost'IDENTIFIEDBY'password'; 2. Assign permissions: Use GRANTSELECT, INSERT, UPDATEONmydatabase.TO'newuser'@'localhost'; 3. Fix permission error: Use REVOKEALLPRIVILEGESONmydatabase.FROM'newuser'@'localhost'; then reassign permissions; 4. Optimization permissions: Use SHOWGRA

MySQL is suitable for rapid development and small and medium-sized applications, while Oracle is suitable for large enterprises and high availability needs. 1) MySQL is open source and easy to use, suitable for web applications and small and medium-sized enterprises. 2) Oracle is powerful and suitable for large enterprises and government agencies. 3) MySQL supports a variety of storage engines, and Oracle provides rich enterprise-level functions.

The disadvantages of MySQL compared to other relational databases include: 1. Performance issues: You may encounter bottlenecks when processing large-scale data, and PostgreSQL performs better in complex queries and big data processing. 2. Scalability: The horizontal scaling ability is not as good as Google Spanner and Amazon Aurora. 3. Functional limitations: Not as good as PostgreSQL and Oracle in advanced functions, some functions require more custom code and maintenance.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

SublimeText3 Linux new version
SublimeText3 Linux latest version