Giter VIP home page Giter VIP logo

mysql_monitor's Introduction

MySQL Monitor面向研发人员图形可视化监控工具

简介:

目前常用开源监控工具有nagios,zabbix,grafana,但这些是面向专业DBA使用的,而对于业务研发人员来说,没有专业的MySQL理论知识,并且上述监控工具均为纯英文界面,交互不直观,那么多的监控指标,你知道有哪些是研发最关心的吗?

所以每次都是DBA通知研发,系统哪块出了问题,这样的效率其实是低下的,我是希望把监控这块东西定制化,做成开发一眼就能看懂的指标项,纯中文页面,清爽直观,简约而不简单,出了问题报警信息直接第一时间推送给研发,效率会大大提升,同时也减少了DBA作为中间人传话的作用(传达室大爷角色)。

参考了天兔Lepus的UI风格,目前采集了数据库连接数(具体连接了哪些应用程序IP,账号统计)、QPS/TPS、索引使用率统计,同步复制状态/延迟监控。可实现微信和邮件报警。

1、MySQL状态监控 image

2、点击活动连接数,可以查看具体的连接数统计信息 image

3、点击图表,可以查看历史曲线图 image

4、主从复制状态监控

image

5、微信报警

image

6、邮件报警

image

一、环境搭建

yum install httpd mysql php-mysqlnd -y

yum install python-simplejson -y

service httpd start

https://github.com/hcymysql/mysql_monitor/archive/master.zip安装包解压缩到 /var/www/html/目录下

cd /var/www/html/mysql_monitor/

chmod 755 ./mail/sendEmail

chmod 755 ./weixin/wechat.py

(注:邮件和微信报警调用的第三方工具,所以这里要赋予可执行权限755)

二、MySQL Monitor监控工具搭建

1、导入MySQL Monitor监控工具表结构(sql_db库)

cd /var/www/html/mysql_monitor/

mysql -uroot -p123456 < mysql_monitor_schema.sql

2、录入被监控主机的信息

mysql>insert into mysql_status_info(id,ip,dbname,user,pwd,port,monitor,send_mail,sen d_mail_to_list,send_weixin,send_weixin_to_list,alarm_threads_running,thresh old_alarm_threads_running,alarm_repl_status,threshold_warning_repl_delay) values (1,'127.0.0.1','sql_db','admin','hechunyang',3306,1,1,'[email protected],chu [email protected]',1,'hechunyang',NULL,NULL,NULL,NULL);

注,以下字段可以按照需求变更:

ip字段含义:输入被监控MySQL的IP地址

dbname字段含义:输入被监控MySQL的数据库名

user字段含义:输入被监控MySQL的用户名(最好给ALL管理员权限)

pwd字段含义:输入被监控MySQL的密码

port字段含义:输入被监控MySQL的端口号

monitor字段含义:0为关闭监控(也不采集数据,直接跳过);1为开启监控(采集数据)

send_mail字段含义:0为关闭邮件报警;1为开启邮件报警

send_mail_to_list字段含义:邮件人列表

send_weixin字段含义:0为关闭微信报警;1为开启微信报警

send_weixin_to_list字段含义:微信公众号

threshold_alarm_threads_running字段含义:设置连接数阀值(单位个)

threshold_warning_repl_delay字段含义:设置主从复制延迟阀值(单位秒)

3、修改conn.php配置文件

vim /var/www/html/mysql_monitor/conn.php

$con = mysqli_connect("127.0.0.1","admin","hechunyang","sql_db","3306") or die("数据库链接错误".mysql_error());

改成你的MySQL Monitor监控工具表结构(sql_db库)连接信息

4、修改邮件报警信息

cd /var/www/html/mysql_monitor/mail/

vim mail.php

system("./mail/sendEmail -f [email protected] -t '{$this->send_mail_to_list}' -s smtp.139.com:25 -u '{$this->alarm_subject}' -o message-charset=utf8 -o message-content-type=html -m '报警信息:
{$this->alarm_info}' -xu [email protected] -xp '123456' -o tls=no");

改成你的发件人地址,账号密码,里面的变量不用修改。

5、修改微信报警信息

cd /var/www/html/mysql_monitor/weixin/

vim wechat.py

微信企业号设置移步 https://github.com/X-Mars/Zabbix-Alert-WeChat/blob/master/README.md 看此教程配置。

6、定时任务每分钟抓取一次

crontab -l

*/1 * * * * cd /var/www/html/mysql_monitor/; /usr/bin/php /var/www/html/mysql_monitor/check_mysql_repl.php > /dev/null 2 >&1

*/1 * * * * cd /var/www/html/mysql_monitor/; /usr/bin/php /var/www/html/mysql_monitor/check_mysql_status.php > /dev/null 2 >&1

check_mysql_status.php(用来采集被监控端MySQL状态信息和触发报警)

check_mysql_repl.php(用来采集被监控端MySQL主从复制信息和触发报警)

7、更改页面自动刷新频率

vim mysql_status_monitor.php

vim mysql_repl_monitor.php

http-equiv="refresh" content="600"

默认页面每600秒自动刷新一次。

8、页面访问

http://yourIP/mysql_monitor/mysql_status_monitor.php

http://yourIP/mysql_monitor/mysql_repl_monitor.php

加一个超链接,可方便地接入你们的自动化运维平台里。

mysql_monitor's People

Contributors

hcymysql avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.