Home > Database > Mysql Tutorial > body text

Zabbix监控mysql(bash版)

WBOY
Release: 2016-06-07 17:37:27
Original
833 people have browsed it

大家都知道,zabbix自定义key的功能十分方便,监控任意值都是特别的方便,安装好了之后,如果你需要监控mysql,用默认的模板是无法工作的,因为没有key的存在,

   大家都知道,zabbix自定义key的功能十分方便,监控任意值都是特别的方便,安装好了之后,如果你需要监控mysql,用默认的模板是无法工作的,因为没有key的存在,所以要自己写一个脚本去实现key。当然也可以用https://www.zabbix.com/wiki/howto/monitor/db/mysql/extensive_mysql_monitoring_including_replication这里的php脚本,如果想监控主从同步状态,原理相同,此处不写了。

   脚本可以用任意语言写,但是在linux下,还是shell最方便,用php,需要安装php环境,用python,需要安装python-MySQL库,用perl也是如此,所以选择了bash。bash脚本提供了用户名密码主机在web界面配置的功能,这里不写了,有问题的可以留言。

   脚本位置zabbix-agent,脚本,配置文件ok后重启服务,web上面添加对应主机mysql模板(自带)

shell#cat /etc/zabbix/scripts/monitor_mysql #!/bin/bash #author:itnihao #mail:itnihao@qq.com #date 2013-12-18 #version v1.0 #function:use zabbix monitor mysql status mysql=$(which mysql) #注意,如果你的mysql是非标准安装,请写mysql的绝对路径 #mysql=/usr/bin/mysql var=$1 MYSQL_USER=$2 MYSQL_PASSWORD=$3 MYSQL_Host=$4 [ "${MYSQL_USER}" = '' ] && MYSQL_USER=zabbix [ "${MYSQL_PASSWORD}" = '' ] && MYSQL_PASSWORD=zabbix [ "${MYSQL_Host}" = '' ] && MYSQL_Host=localhost [ "${var}" = '' ] && echo ""||${mysql} -u${MYSQL_USER} -p${MYSQL_PASSWORD} -h${MYSQL_Host} -e 'show status'|grep -v Variable_name|grep "\b${var}\b"|awk '{print $2}'shell#egrep -v "(^#|^$)" /etc/zabbix/zabbix_agentd.conf #Server=这个参数,这里不详细的写了,主要改以下的参数 Include=/etc/zabbix/zabbix_agentd.conf.d/ #配置文件路径 UnsafeUserParameters=1 #允许特殊字符shell#cat /etc/zabbix/zabbix_agentd.conf.d/mysql_status.conf UserParameter=mysql.status[*],/etc/zabbix/scripts/monitor_mysql $1 UserParameter=mysql.ping,/usr/bin/mysqladmin -uzabbix -pzabbix ping|grep alive|wc -l UserParameter=mysql.version,mysql -V | cut -f6 -d" " | sed 's/,//'

上面步骤好了之后用zabbix_get测试

shell#zabbix_get -s 127.0.0.1 -k mysql.status[Uptime]

有数据即成功创建了可用key

本文出自 “itnihao的运维技术博客” 博客,,请务必保留此出处

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!