标签:pil 导入 grep .config -o start net conf temp
在[/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 模板,测试。
本例对 原percona MySQL Server Template 中监控的指标进行了删减(根据DBA的需求),如果需要其他指标,请参考userparameter_percona_mysql.conf文件中的监控项以及模板中现有的监控项,在模板中新增 Item prototypes .
增加了slave的 Last_Errno 的监控(修改了php文件)
Mysql 监控 支持 mysql 多实例自动发现以及主从监控
标签:pil 导入 grep .config -o start net conf temp
原文地址:https://www.cnblogs.com/cpsing/p/10655851.html