监控agent自动发现mysql实例_Mysql 监控 支持 mysql 多实例自动发现以及主从监控

在[/usr/local/zabbix327/bin] 目录下新建python文件,并增加执行权限,如下:

#!/usr/bin/env /usr/bin/python

# _*_ coding:utf-8 _*_

import subprocess

import json

import re

import ConfigParser

def main():

# mysqld is started with mysqld_safe ,and with the configfile,or use 3306 port

command = "ps -eo command |grep mysqld_safe|grep -v grep"

process = subprocess.Popen(command, shell=True, stdin=subprocess.PIPE,

stdout=subprocess.PIPE, stderr=subprocess.PIPE)

out, err = process.communicate()

return_code = process.wait()

if return_code != 0:

print("error found!" + err)

return

all_mysqld = list(str(out).splitlines())

mysql_config_arg = "--defaults-file="

mysql_socket_arg = "--socket="

mysql_bin_reg = "\\s(.+)mysqld_safe\\s"

list_mysql = []

for mysqld in all_mysqld:

socket_file = None

socket_port = None

if mysql_config_arg in mysqld:

for arg in list(mysqld.split()):

if mysql_config_arg in arg:

mysql_config_file = arg.replace(mysql_config_arg, "")

cf = ConfigParser.ConfigParser(allow_no_value=True)

cf.read(mysql_config_file)

socket_file = cf.get("mysqld", "socket")

socket_port = int(cf.get("mysqld", "port"))

elif mysql_socket_arg in mysqld:

for arg in list(mysqld.split()):

if mysql_socket_arg in arg:

socket_file = arg.replace(mysql_socket_arg, "").strip()

# netstat -tulpn | grep `cat /var/run/mysqld/mysqld.pid` |grep -P ':(\d{3,6})(?=\s)' -o | awk 'BEGIN {FS=":"}; {print $2}'

socket_port = 3306

bin_path = str(re.compile(mysql_bin_reg).findall(mysqld)[0]).strip()

list_mysql.append({'{#BIN_PATH}': bin_path, '{#SOCKET_PATH}': socket_file, '{#PORT}': socket_port})

print json.dumps({'data': list_mysql})

if __name__ == '__main__':

main()

copy get_mysql_stats_wrapper.sh mysql_innodb_trx_status.sh ss_get_mysql_stats.php 到 /usr/local/zabbix327/bin 目录下,增加可执行权限.

# chmod +x get_mysql_stats_wrapper.sh

安装php 环境

# yum install php php-mysql

确定php 解释引擎的位置,一般在/usr/bin/php ,如果未能发现,可通过 which php 或 find 命令来查找。

如果php解释引擎未在 /usr/bin/php,则需要修改 get_mysql_stats_wrapper.sh 文件中的php解释引擎的位置

CMD="/usr/bin/php -q $DIR/ss_get_mysql_stats.php --host $HOST --items gg"

copy userparameter_percona_mysql.conf、userparameter_mysql.conf 到 zabbix_agentd.conf.d,并在zabbix_aentd.conf 中include文件(注意userparameter_percona_mysql.conf文件中脚本路径,需要根据实际情况修改)

导入模板

host link template 模板,测试。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值