Percona-Tookit工具包之pt-heartbeat
pt-heartbeat [OPTIONS] [DSN] --update|--monitor|--check|--stop
--check //Specify the check mode to slave delay.It only checks once then exits.
--monitor //Specify the monitor mode to slave delay.
--update //Specify the update mode on master.
--check-read-only //It skips insert operations if the server is read-only status.
--create-table //Create a heartbeat table.
--table //Specify the heartbeat table(default "heartbeat").
--daemonize //Run it as background process.
--dbi-driver //Specify the drive of database(default "mysql",other value is "pg").
--file //Specify a output file when using --monitor.
--log //Print all output to the file when using --daemonize
--master-server-id //Calculate delay from this master server id.
--interval //Specify the frequency to update or check the heartbeat table(default "1.0").
--run-time //Specify the period of time to run(default suffix is "s",if you set 60,it means 60s). Notice:
Specify at least one of --stop, --update, --monitor, or --check.
--update, --monitor, and --check are mutually exclusive.
--daemonize and --check are mutually exclusive.
[root@zlm2 :: ~]
#pt-heartbeat --database=sysbench --create-table --table=hb --daemonize -h192.168.1. -P3306 -uzlm -pzlmzlm --update [root@zlm2 :: ~]
# (zlm@192.168.1.101 )[sysbench]>show tables like 'hb';
+-------------------------+
| Tables_in_sysbench (hb) |
+-------------------------+
| hb |
+-------------------------+
row in set (0.00 sec) (zlm@192.168.1.101 )[sysbench]>select * from hb;
+----------------------------+-----------+------------------+----------+-----------------------+---------------------+
| ts | server_id | file | position | relay_master_log_file | exec_master_log_pos |
+----------------------------+-----------+------------------+----------+-----------------------+---------------------+
| --19T03::07.005490 | | mysql-bin. | | NULL | NULL |
+----------------------------+-----------+------------------+----------+-----------------------+---------------------+
row in set (0.00 sec) //The operation above will create a heartbeat table "hb" in database "sysbench" if the target table not exist.
//It will update the table which contains the heartbeat info of master every time you execute with "--update".
[root@zlm2 :: ~]
#pt-heartbeat --database=sysbench -h192.168.1. -P3306 -uzlm -pzlmzlm --check
DBD::mysql::db selectrow_arrayref failed: Table 'sysbench.heartbeat' doesn't exist [for Statement "SHOW CREATE TABLE `sysbench`.`heartbeat`"] at /usr/bin/pt-heartbeat line 5873. [root@zlm2 :: ~]
#pt-heartbeat --database=sysbench --create-table --table=hb -h192.168.1. -P3306 -uzlm -pzlmzlm --check
0.00 (zlm@192.168.1.102 )[sysbench]>show tables like 'hb';
+-------------------------+
| Tables_in_sysbench (hb) |
+-------------------------+
| hb |
+-------------------------+
row in set (0.00 sec) (zlm@192.168.1.102 )[sysbench]>select * from hb;
+----------------------------+-----------+------------------+----------+-----------------------+---------------------+
| ts | server_id | file | position | relay_master_log_file | exec_master_log_pos |
+----------------------------+-----------+------------------+----------+-----------------------+---------------------+
| --19T03::53.005890 | | mysql-bin. | | NULL | NULL |
| -- :: | | NULL | NULL | NULL | NULL |
+----------------------------+-----------+------------------+----------+-----------------------+---------------------+
rows in set (0.00 sec) //The connection option refers to slave.
//It will also create the same heartbeat table on the slave.
//The output will show the delay time.
[root@zlm2 :: ~]
#pt-heartbeat --database=sysbench --create-table --table=hb --daemonize --log=/root/monitor.log -h192.168.1. -P3306 -uzlm -pzlmzlm --monitor [root@zlm2 :: ~]
#ls -l|grep monitor
-rw-r--r-- root root Jul : monitor.log [root@zlm2 :: ~]
#cat monitor.log
*******************************************************************
Using the default of SSL_verify_mode of SSL_VERIFY_NONE for client
is deprecated! Please set SSL_verify_mode to SSL_VERIFY_PEER
possibly with SSL_ca_file|SSL_ca_path for verification.
If you really don't want to verify the certificate and keep the
connection open to Man-In-The-Middle attacks please set
SSL_verify_mode explicitly to SSL_VERIFY_NONE in your application.
*******************************************************************
at /usr/bin/pt-heartbeat line .
*******************************************************************
Using the default of SSL_verify_mode of SSL_VERIFY_NONE for client
is deprecated! Please set SSL_verify_mode to SSL_VERIFY_PEER
possibly with SSL_ca_file|SSL_ca_path for verification.
If you really don't want to verify the certificate and keep the
connection open to Man-In-The-Middle attacks please set
SSL_verify_mode explicitly to SSL_VERIFY_NONE in your application.
*******************************************************************
at /usr/bin/pt-heartbeat line . # A software update is available:
# * The current version for Percona::Toolkit is 3.0. .00s [ .00s, .00s, .00s ]
.00s [ .00s, .00s, .00s ]
.00s [ .00s, .00s, .00s ]
.00s [ .00s, .00s, .00s ]
.00s [ .00s, .00s, .00s ]
.00s [ .00s, .00s, .00s ]
.00s [ .00s, .00s, .00s ]
.00s [ .00s, .00s, .00s ]
.00s [ .00s, .00s, .00s ] [root@zlm2 :: ~]
# //The output will be write into the logfile sepcified by option "--log".
//The logfile will be continuously written unless you've specified th option "--run-time".
//It seems no delay between master and slave at all.We can use sysbench generate some transactions to observe the difference.
[root@zlm2 :: ~/sysbench-1.0/src/lua]
#sysbench oltp_read_write.lua --mysql-host=192.168.1.101 --mysql-port= --mysql-user=zlm --mysql-password=zlmzlm --mysql-db=sysbench --tables= --table-size= --mysql-storage-engine=innodb prepare
sysbench 1.0. (using bundled LuaJIT 2.1.-beta2) Creating table 'sbtest1'...
Inserting records into 'sbtest1'
FATAL: mysql_drv_query() returned error (The table 'sbtest1' is full) for query 'INSERT INTO sbtest1(k, c, pad) VALUES(5007652, '---------', '----'),(4980838, '---------', '----'),(4369690, '---------', '----'),(4980019, '---------', '----'),(4997783, '---------', '----'),(4996542, '---------', '----'),(5016589, '---------', '----'),(4994933, '---------', '----'),(5024203, '---------', '----'),(4162450, '---------', '----'),(4995444, '---------', '----'),(5014023, '---------', '----'),(5024261, '---------', '----'),(5024236, '---------', '----'),(5049980, '---------', '----'),(5471904, '---------', '----'),(5019788, '---------', '----'),(5021303, '---------', '----'),(5015123, '---------', '----'),(3676715, '---------', '----'),(5236763, '----FATAL: `sysbench.cmdline.call_command' function failed: ./oltp_common.lua:230: db_bulk_insert_next() failed //Master
[root@zlm2 :: ~/sysbench-1.0/src/lua]
#df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root .4G .4G 68M % / //The disk space of master is full.
devtmpfs 488M 488M % /dev
tmpfs 497M 497M % /dev/shm
tmpfs 497M 6.6M 491M % /run
tmpfs 497M 497M % /sys/fs/cgroup
/dev/sda1 497M 118M 379M % /boot
none 87G 80G .6G % /vagrant //Slave
[root@zlm3 :: ~]
#df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root .4G .4G 20K % / //The disk space of slave is full,too.
devtmpfs 488M 488M % /dev
tmpfs 497M 497M % /dev/shm
tmpfs 497M 6.5M 491M % /run
tmpfs 497M 497M % /sys/fs/cgroup
/dev/sda1 497M 118M 379M % /boot
none 87G 80G .6G % /vagrant //Check the output logfile.
[root@zlm2 :: ~]
#tail monitor.log
.00s [ .40s, .65s, .55s ]
.00s [ .26s, .65s, .55s ]
.99s [ .13s, .65s, .55s ]
.99s [ .00s, .66s, .55s ]
.99s [ .86s, .67s, .56s ]
.99s [ .73s, .68s, .56s ]
.99s [ .59s, .70s, .57s ]
.00s [ .46s, .72s, .57s ]
.01s [ .29s, .73s, .58s ]
.99s [ .16s, .75s, .58s ] //Long time later. [root@zlm2 :: ~]
#tail monitor.log
.00s [ .50s, .50s, .50s ]
.99s [ .50s, .50s, .50s ]
.99s [ .50s, .50s, .50s ]
.99s [ .50s, .50s, .50s ]
.99s [ .50s, .50s, .50s ]
.99s [ .50s, .50s, .50s ]
.99s [ .50s, .50s, .50s ]
.99s [ .50s, .50s, .50s ]
.99s [ .50s, .50s, .50s ]
.00s [ .50s, .50s, .50s ] [root@zlm2 :: ~]
#tail monitor.log
.00s [ .50s, .50s, .50s ]
.00s [ .50s, .50s, .50s ]
.00s [ .50s, .50s, .50s ]
.00s [ .50s, .50s, .50s ]
.00s [ .50s, .50s, .50s ]
.00s [ .50s, .50s, .50s ]
.99s [ .50s, .50s, .50s ]
.00s [ .50s, .50s, .50s ]
.99s [ .50s, .50s, .50s ]
.00s [ .50s, .50s, .50s ] (zlm@192.168.1.102 )[sysbench]>show slave status\G
ERROR (HY000): Lost connection to MySQL server during query
(zlm@192.168.1.102 )[sysbench]>show slave status\G
ERROR (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id:
Current database: sysbench //The slave has hung because of the lack of disk space.
//The delay continuously increasing what can be seen in the logfile on master. # :: server id end_log_pos Table_map: `sysbench`.`hb` mapped to number
# at
# :: server id end_log_pos Update_rows: table id flags: STMT_END_F
### UPDATE `sysbench`.`hb`
### WHERE
### @='2018-07-19T04:31:55.004000' /* VARSTRING(78) meta=78 nullable=0 is_null=0 */
### @= /* INT meta=0 nullable=0 is_null=0 */
### @='mysql-bin.000019' /* VARSTRING(765) meta=765 nullable=1 is_null=0 */
### @= /* LONGINT meta=0 nullable=1 is_null=0 */
### @=NULL /* VARSTRING(765) meta=765 nullable=1 is_null=1 */
### @=NULL /* LONGINT meta=0 nullable=1 is_null=1 */
### SET
### @='2018-07-19T04:31:55.004400' /* VARSTRING(78) meta=78 nullable=0 is_null=0 */
### @= /* INT meta=0 nullable=0 is_null=0 */
### @='mysql-bin.000019' /* VARSTRING(765) meta=765 nullable=1 is_null=0 */
### @= /* LONGINT meta=0 nullable=1 is_null=0 */
### @=NULL /* VARSTRING(765) meta=765 nullable=1 is_null=1 */
### @=NULL /* LONGINT meta=0 nullable=1 is_null=1 */
# at
# :: server id end_log_pos Xid =
COMMIT/*!*/; //The output above is the detail of updating heartbeat table "hb" on master.
- pt-heartbeat is rather useful in checking replica lag of MySQL and it also support PostgreSQL.
- pt-heartbeat will read connection options in my.cnf by default if you do not specify them.
- If you've executed the pt-heartbeat with option "--daemonize",don't forget to kill the redundant processes.
- We can retrieve these lag information in heartbeat table using our monitor tool or script.
Percona-Tookit工具包之pt-heartbeat的更多相关文章
- Linux后台开发工具箱
https://files-cdn.cnblogs.com/files/aquester/Linux后台开发工具箱.pdf 目录 目录 1 1. 前言 3 2. 脚本类工具 3 2.1. sed命令- ...
- Mysql: pt-table-checksum 和 pt-table-sync 检查主从一致性,实验过程
一.安装 percona 包 1.安装仓库的包 https://www.percona.com/doc/percona-repo-config/yum-repo.html sudo yum insta ...
- Linux后台开发工具箱-葵花宝典
Linux后台开发工具箱-葵花宝典 一见 2016/11/4 目录 目录 1 1. 前言 4 2. 脚本类工具 4 2.1. 双引号和单引号 4 2.2. 取脚本完整文件路径 5 2.3. 环境变量和 ...
- 推荐几款MySQL相关工具
前言: 随着互联网技术的不断发展, MySQL 相关生态也越来越完善,越来越多的工具涌现出来.一些公司或个人纷纷开源出一些不错的工具,本篇文章主要介绍几款 MySQL 相关实用工具.提醒下,这里并不介 ...
- [知识库分享系列] 二、.NET(ASP.NET)
最近时间又有了新的想法,当我用新的眼光在整理一些很老的知识库时,发现很多东西都已经过时,或者是很基础很零碎的知识点.如果分享出去大家不看倒好,更担心的是会误人子弟,但为了保证此系列的完整,还是选择分享 ...
- SQL慢查询安装过程
SQL慢查询 基本操作 打开防火墙 firewall-cmd --zone=public --add-port=3306/tcp --permanent firewall-cmd --reload 安 ...
- 快速安装Percona pt工具
yum install perl-DBI perl-DBD-MySQL perl-Time-HiRes perl-Time-HiRes perl-IO-Socket-SSLwget http://pk ...
- Percona 工具包 pt-online-schema-change 简介
mysql的在线表结构修改,因为低效和阻塞读写.一直被诟病.至于ALTER TABLE 的原理,参看我上一篇文章.MySQL在线修改大表结构.看完后,发现的问题是还是会锁的,且对于在线更新的这块也是不 ...
- 安装percona工具包
1.安装percona源 sudo yum install http://www.percona.com/downloads/percona-release/redhat/0.1-4/percona- ...
- percona pt toolkit 总结
##=====================================================##pt-osc之工作流程:1.检查更改表是否有主键或唯一索引,是否有触发器2.检查修改表 ...
随机推荐
- java ——String , StringBuffer, StringBuilder类
一.String类概述 1.String对象一旦创建就不能改变. 2.字符串常量池. 字符串常量池的特点:池中有则直接使用,池中没有则创建新的字符串常量. 例1: “==” 比较两个对象是否引用同一 ...
- Javascript作业—数字转化为大写
开始学javascript,写作业. <script type="text/javascript"> function toChinese(money){ var ch ...
- Spring MVC的一些学习笔记-入门配置和HttpMessageConverter
1.初步配置 [1]. 配置web.xml以及在web.xml中配置DispatcherServlet: <context-param> <param-name>context ...
- Spring转换编码utf-8方式
方式一:修改Spring配置文件(建议使用) <mvc:annotation-driven> <mvc:message-converters register-defaults=&q ...
- 使用C#的新特性:可空类型
随着C#语言最新标准的出炉,现在它也提供了对可空类型的支持.这个小变化将会在处理那些包括可选项的数据库记录时非常有用.当然在其他地方,它也是非常有用的. 简单说来,可空数据类型就是包含了所定义的数据类 ...
- Python,针对指定文件类型,过滤空行和注释,统计行数
参考网络上代码编辑而成,无技术含量,可自行定制: 目前亲测有效,若有待完善之处,还望指出! 强调:将此统计py脚本放置项目的根目录下执行即可. 1.遍历文件,递归遍历文件夹中的所有 def getFi ...
- 自定义动画函数JQuery实现
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- js | javascript改变style样式和css样式
转载 在很多情况下,都需要对网页上元素的样式进行动态的修改.在JavaScript中提供几种方式动态的修改样式,下面将介绍方法的使用.效果.以及缺陷. 1.使用obj.className来修改样式表的 ...
- 一行代码搞定checkbox全选和全不选
<!DOCTYPE html><html> <head> <meta charset="utf-8" /> <title> ...
- js 判断function是否存在
function myFunction(){ }//方法一 if(typeof(myFunction) == 'function'){ //function }else{ //undefined }/ ...