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

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
云数据库 RDS MySQL Serverless,价值2615元额度,1个月
简介: 工具用于查看指定时间内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分钟采样一次记录下所有的信息变化。

相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
22天前
|
监控 关系型数据库 MySQL
《MySQL 简易速速上手小册》第7章:MySQL监控和日志分析(2024 最新版)
《MySQL 简易速速上手小册》第7章:MySQL监控和日志分析(2024 最新版)
41 3
|
1月前
|
存储 监控 关系型数据库
轻松入门Mysql:MySQL性能优化与监控,解锁进销存系统的潜力(23)
轻松入门Mysql:MySQL性能优化与监控,解锁进销存系统的潜力(23)
|
2月前
|
关系型数据库 MySQL
elasticsearch对比mysql以及使用工具同步mysql数据全量增量
elasticsearch对比mysql以及使用工具同步mysql数据全量增量
26 0
|
2月前
|
SQL 监控 关系型数据库
MySQL性能调优:监控和优化
MySQL性能调优:监控和优化
66 1
|
3月前
|
监控 关系型数据库 MySQL
HeartBeat监控Mysql状态
HeartBeat监控Mysql状态
|
3月前
|
关系型数据库 MySQL 数据库
rds迁移数据迁移工具选择
rds迁移数据迁移工具选择
78 3
|
2月前
|
关系型数据库 MySQL 数据库
rds安装数据库客户端工具
安装阿里云RDS的数据库客户端涉及在本地安装对应类型(如MySQL、PostgreSQL)的客户端工具。对于MySQL,可选择MySQL Command-Line Client或图形化工具如Navicat,安装后输入RDS实例的连接参数进行连接。对于PostgreSQL,可以使用`psql`命令行工具或图形化客户端如PgAdmin。首先从阿里云控制台获取连接信息,然后按照官方文档安装客户端,最后配置客户端连接以确保遵循安全指引。
112 1
|
5天前
|
Prometheus 监控 Cloud Native
使用mysqld_exporter监控所有MySQL实例
使用mysqld_exporter监控所有MySQL实例
35 2
|
5天前
|
存储 安全 关系型数据库
MySQL中使用percona-xtrabackup工具 三种备份及恢复 (超详细教程)
MySQL中使用percona-xtrabackup工具 三种备份及恢复 (超详细教程)
|
10天前
|
SQL 关系型数据库 MySQL
【MySQL-3】图形化界面工具DataGrip安装&配置&使用
【MySQL-3】图形化界面工具DataGrip安装&配置&使用