自己写的一个MYSQL监控show global status工具用于查看指定时间内变化的指标

本文涉及的产品
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS PostgreSQL,集群系列 2核4GB
简介: 工具用于查看指定时间内show global status指标的变化,能够帮助运维人员了解系统负载的走势 本工具在5.5 5.6 5.7中测试通过 源码我放在百度云盘了 http://pan.
工具用于查看指定时间内show global status指标的变化,能够帮助运维人员了解系统负载的走势
本工具在5.5 5.6 5.7中测试通过

源码我放在百度云盘了
http://pan.baidu.com/s/1mhIeKp6
源码一共5个文件
conmysql.c main.c findv.c other.c type.h

如果源码编译使用如下方法
1、建立一个MYSQL用户用于监控,不需要什么权限只要能够show global status 即可
mysql> create user mmon@'localhost' identified by 'test123';
Query OK, 0 rows affected (0.30 sec)
这样就可以了

2、找到你的MYSQL库文件
   一般在你的安装目录lib 目录下
   如/mysqldata/mysql5.7/lib
   export LD_LIBRARY_PATH=/mysqldata/mysql5.7/lib
3、编译源文件
   原版
   gcc conmysql.c main.c findv.c other.c -L/mysqldata/mysql5.7/lib -L/mysqldata/mysql5.7/lib -lmysqlclient -I/mysqldata/mysql5.7/include -o mmon  -W -fPIC
   percona
   gcc conmysql.c main.c findv.c other.c -L/dbdata/mysql3307/lib  -lperconaserverclient -I/dbdata/mysql3307/include -o mmon  -W -fPIC
 
4、帮助
[root@testmy mysqlmon]# ./mmon -help
Welcome use this mon tool!
This mon tool is calc status delta!
Author:gaopeng QQ:22389860
This mon tool is calc status delta, interval time is paramter -l define default is 10 seconds
but cant's less than 3 seconds
-t define how many times defualt is 1440 times
If -10 appear means is that no values find!
Usage::./mmon -h -u -p -P/-s [-l] [-t]
-h:host
-u:username
-p:password
-P:port
-s:socket
-l:interval time of seconds
-t:how many times

-l 是时间间隔默认是10秒,指定时间最小为3秒,小于3秒会报错。
-t 是你想采样的此时默认是1440次,不能小于1.


5、使用
./mmon -h=localhost -u=test11 -p=gelc123 -s=/mysqldata/mysql5.7/mysqld3307.sock -l=5 -t=3

按ctrl+c 即可以退出

注意-p=lc1\$23 这里的特殊字符用一下转义\
输出为:

Welcome use this mon tool!
This mon tool is calc status delta!
Author:gaopeng QQ:22389860
Your input paramter is: -h,localhost
Your input paramter is: -u,mmontest
Your input paramter is: -p,Lc123
Your input paramter is: -s, /dbdata/mysql5800/mysql.sock
Your input paramter is: -l,5
Your input paramter is: -t,3
Parameter counter is: 5
Mmonitor:host is:localhost,user is:mmontest,passwd is:gelc123,socket is:/dbdata/mysql5800/mysql.sock,port is 0
Mmonitor:Connect mysql server success
Mmonitor:status rows : 402,field : 2
------------------------------------------MMON--------------------------------------------
SysTime: Mon Sep 12 12:25:28 2016


Uptime:2312561    Connections:1       Aborted_clients:0       Max_used_connections:44      
--------------------------------------MYSQLINFO-------------------------------------------
Threads_connected:12          Threads_running:1           Qcache_free_memory:1031328      
Qcache_hits:0                 Qcache_not_cached:0         Qcache_inserts:0                
Handler_read_first:0          Handler_read_key71          Handler_read_next0             
Handler_read_last:0           Handler_read_prev:0         Handler_read_rnd:71             
Handler_read_rnd_next:403
Sort_rows:0                   Select_full_join:0          Select_scan:1                   
Com_commit:177                Com_rollback:0
Handler_commit:455            Handler_rollback:0
U:70      D:1       I:207     S:0       S/(U+D+I+S)(%):0.00    
TIM(temp table in mem lager)(%):100.00       SOD(sort on disk small)(%):0.00
TOH(table open hint lager)(%):100.00         BOD(binglog on disk samll)(%):0.00
--------------------------------------INNODBINFO------------------------------------------
Innodb_row_lock_time:0              Innodb_row_lock_waits:0
Innodb_log_writes:181               Innodb_log_waits:0
Innodb_buffer_pool_wait_free:0      Innodb_buffer_pool_pages_misc:380
Innodb_buffer_pool_pages_flushed:84
Innodb_dblwr_pages_written:84       Innodb_dblwr_writes:8
Innodb_os_log_pending_fsyncs:0      Innodb_os_log_pending_writes:0
Innodb_os_log_written:384512
Innodb_data_reads:21                Innodb_data_read:344064
Innodb_data_writes:273              Innodb_data_written:3137024
Innodb_buffer_pool_bytes_data:32071745536
U(rows):70      D(rows):1       I(rows):273     S(rows):71      
BPH(buffer cache hint)(%):100.00    BFP(free buffer pct)(%):0.42
BDP(dirty buffer pct)(%):0.68
---------------------------------------TOTALINFO------------------------------------------
Bytes_received:283146         Bytes_sent:11968
QPS:55        TPS:55        IOPS:96
---------------------------------------ENDL-----------------------------------------------


大部分保留了原有的status名字而没有使用简写,目的在于大家能够更快在文档中找到相应的解释
明白其中的含义。

关于指标问题,任何show global status中的都可以非常简单加入到工具中,可以联系我加入。

部分错误码
Mmonitor(16):connect mysql server error
Mmonitor(15):mysql port is number type!" ??
Mmonitor:(14)parameters must -h -u -p -P -s [-l] "
Mmonitor:(13)parameter len must>=4"
Mmonitor(12):miss -parameter= ="
Mmonitor(11):use only -u -h -p -P -s [-l]"
Mmonitor(10):miss -parameter= -"
Mmonitor(17):data global status failed no pri?
Mmonitor(18):fetch data failed!"
Mmonitor(21): cycle is number type!"
Mmonitor(22): Mmonitor cycle must lager than 3 sec!

关于内存泄露:
通过工具 valgrind 检测
==5999== HEAP SUMMARY:
==5999==     in use at exit: 51,863 bytes in 718 blocks
==5999==   total heap usage: 18,489 allocs, 17,771 frees, 2,250,709 bytes allocated
==5999== 
==5999== LEAK SUMMARY:
==5999==    definitely lost: 0 bytes in 0 blocks
==5999==    indirectly lost: 0 bytes in 0 blocks
==5999==      possibly lost: 34,651 bytes in 17 blocks
==5999==    still reachable: 17,212 bytes in 701 blocks
==5999==         suppressed: 0 bytes in 0 blocks
==5999== Rerun with --leak-check=full to see details of leaked memory
==5999== 
==5999== For counts of detected and suppressed errors, rerun with: -v


可以看到没有内存泄露

==5999==      possibly lost: 34,651 bytes in 17 blocks
==5999==    still reachable: 17,212 bytes in 701 blocks

可以写shell脚本
是我固定非配的一点内存CTRL+C后释放

如果写脚本可以如下:

export LD_LIBRARY_PATH=/dbdata/mysql3307/lib
DATE_TAG=`date +%Y%m%d`

int=1
 while(( $int<=288 ))
 do
 /root/mmon/mmon  -h=localhost -u=mmontest -p=gelc123 -s=/dbdata/mysql5800/mysql.sock -l=60 -t=5 >>/root/mmon/mmon_${DATE_TAG}.log
 let "int++"
 done

代表每次抽取为1分钟 会采样288*5=1440 次就是 刚好一天的。
1 00 * * * /root/mmon.sh

然后这样挂载脚本,就可以每天1分钟采样一次记录下所有的信息变化。

相关实践学习
如何在云端创建MySQL数据库
开始实验后,系统会自动创建一台自建MySQL的 源数据库 ECS 实例和一台 目标数据库 RDS。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
18天前
|
canal 消息中间件 关系型数据库
Canal作为一款高效、可靠的数据同步工具,凭借其基于MySQL binlog的增量同步机制,在数据同步领域展现了强大的应用价值
【9月更文挑战第1天】Canal作为一款高效、可靠的数据同步工具,凭借其基于MySQL binlog的增量同步机制,在数据同步领域展现了强大的应用价值
114 4
|
3月前
|
SQL 关系型数据库 MySQL
MySQL数据库-概括与常用图形管理工具
MySQL数据库-概括与常用图形管理工具
|
5天前
|
SQL 缓存 关系型数据库
MySQL高级篇——性能分析工具
MySQL的慢查询日志,用来记录在MySQL中响应时间超过阀值的语句,具体指运行时间超过long-query_time值的SQL,则会被记录到慢查询日志中。long_query_time的默认值为 10,意思是运行10秒以上(不含10秒)的语句,认为是超出了我们的最大忍耐时间值。它的主要作用是,帮助我们发现那些执行时间特别长的 SOL 查询,并且有针对性地进行优化,从而提高系统的整体效率。当我们的数据库服务器发生阻塞、运行变慢的时候,检查一下慢查询日志,找到那些慢查询,对解决问题很有帮助。
MySQL高级篇——性能分析工具
|
16天前
|
监控 关系型数据库 MySQL
zabbix agent集成percona监控MySQL的插件实战案例
这篇文章是关于如何使用Percona监控插件集成Zabbix agent来监控MySQL的实战案例。
28 2
zabbix agent集成percona监控MySQL的插件实战案例
|
1月前
|
SQL 监控 关系型数据库
使用 pt-query-digest 工具分析 MySQL 慢日志
【8月更文挑战第5天】使用 pt-query-digest 工具分析 MySQL 慢日志
33 3
使用 pt-query-digest 工具分析 MySQL 慢日志
|
27天前
|
SQL 关系型数据库 MySQL
在Linux中,mysql 数据备份工具有哪些?
在Linux中,mysql 数据备份工具有哪些?
|
30天前
|
SQL 存储 关系型数据库
MySQL备份:mydumper 备份恢复工具生产实战
MySQL备份:mydumper 备份恢复工具生产实战
|
30天前
|
关系型数据库 MySQL 数据库
MySQL回滚工具:binlog 闪回工具 MyFlash工具
MySQL回滚工具:binlog 闪回工具 MyFlash工具
|
1月前
|
关系型数据库 MySQL OLTP
性能工具之 MySQL OLTP Sysbench BenchMark 测试示例
【8月更文挑战第6天】使用 pt-query-digest 工具分析 MySQL 慢日志性能工具之 MySQL OLTP Sysbench BenchMark 测试示例
162 0
性能工具之 MySQL OLTP Sysbench BenchMark 测试示例
|
2月前
|
Prometheus 监控 Cloud Native
Prometheus结合Consul采集多个MySQL实例的监控指标
将 Prometheus 与 Consul 结合使用,实现对多个 MySQL 实例的自动发现与监控,不仅提高了监控的效率和准确性,也为管理动态扩缩容的数据库环境提供了强大的支持。通过细致配置每一部分,业务可以获得关键的性能指标和运行健康状况的即时反馈,进而优化资源配置,提高系统的稳定性和可用性。
68 3

热门文章

最新文章