Detailed explanation of using pt-heartbeat to monitor MySQL replication delay

Detailed explanation of using pt-heartbeat to monitor MySQL replication delay

pt-heartbeat

When the database is replicated between master and slave, the replication status and data delay are very critical indicators. So how to monitor them?

pt-heartbeat is a tool developed by PERCONA that is specifically designed to monitor replication delays in MySQL and PostgreSQL.

It is relatively mature and is used by large companies such as Uber.

Let's take a look at the detailed introduction below:

Monitoring principle

Create a heartbeat table in the master with a timestamp field. pt-heartbeat will periodically modify the timestamp value.

The slave will copy the heartbeat table, which contains the timestamp of the master's modification action, and compare it with the local time of the slave to get a difference, which is the value of the replication delay, so as to determine whether the replication status is normal and whether the delay time meets expectations.

pt-heartbeat is calculated based on the actual replication records, so it doesn't matter what method you use for replication.

pt-heartbeat can monitor any depth of replication hierarchy. Because there is a server_id field in the heartbeat table, you can specify which server_id to refer to when monitoring the latency of a slave. For example, if you want to know the latency between this slave and its master's master, just specify the server_id of the target master.

Because pt-heartbeat is strictly dependent on time, you need to make sure that the time of the master and slave are synchronized.

Usage Examples

Create a heartbeat table for the master and perform a cyclic update operation. Execute the command:

It specifies the connection information of the master. --create-table -D master1 means to create a heartbeat table in the master1 database. The following parameters specify the time interval for executing updates.

Then you can monitor the slave and execute the command:

The --monitor parameter indicates that monitoring is to be performed. The previous parameters are the information of the monitoring target, including the slave connection information, database, and table name.

Output information example:


0.00s indicates the current delay information, and [0.00s, 0.00s, 0.00s] indicates the average value of 1m, 5m, and 15m.

Installation Process

The following is the installation process under CentOS7:


The official documentation address of pt-heartbeat: https://www.percona.com/doc/percona-toolkit/2.1/pt-heartbeat.html

Summarize

The above is the full content of this article. I hope that the content of this article can bring some help to your study or work. If you have any questions, you can leave a message to communicate. Thank you for your support of 123WORDPRESS.COM.

You may also be interested in:
  • The MySQL server is running with the --read-only option so it cannot execute this statement
  • mysql databasemysql: [ERROR] unknown option ''--skip-grant-tables''
  • Detailed explanation of ensuring the consistency of MySQL views (with check option)
  • Solution to the error message "java.sql.SQLException: Incorrect string value:'\xF0\x9F\x92\xA9\x0D\x0A...'" when storing emoticons in MySQL
  • NULL and Empty String in Mysql
  • An example of connecting mysql with php via odbc to any database
  • Detailed explanation of installing and completely uninstalling mysql with apt-get under Ubuntu
  • Examples of the correct way to use AES_ENCRYPT() and AES_DECRYPT() to encrypt and decrypt MySQL
  • mysql server is running with the --skip-grant-tables option
  • Introduction to the use of MySQL pt-slave-restart tool

<<:  Detailed explanation of destructuring assignment syntax in Javascript

>>:  Use .Htaccess to prevent malicious IP attacks on websites, prohibit access to specified domain names, prohibit machine crawlers, and prohibit hotlinking

Recommend

CSS box hide/show and then the top layer implementation code

.imgbox{ width: 1200px; height: 612px; margin-rig...

Using NTP for Time Synchronization in Ubuntu

NTP is a TCP/IP protocol for synchronizing time o...

Detailed tutorial on compiling and installing MySQL 5.7.24 on CentOS7

Table of contents Install Dependencies Install bo...

SQL query for users who have placed orders for at least seven consecutive days

Create a table create table order(id varchar(10),...

VMware Tools installation and configuration tutorial for Ubuntu

Some time ago, the blogger installed the Ubuntu s...

JavaScript+html implements random QR code verification on front-end pages

Share the cool front-end page random QR code veri...

Summary of 6 Linux log viewing methods

As a backend programmer, you deal with Linux in m...

Vue sample code for easily implementing virtual scrolling

Table of contents Preface Rolling principle accom...

Analysis of MySQL example DTID master-slave principle

Table of contents 1. Basic Concepts of GTID 2. GT...

js+css to realize three-level navigation menu

This article example shares the specific code of ...

Three methods to modify the hostname of Centos7

Method 1: hostnamectl modification Step 1 Check t...