数据库MySQL的监控

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_26346457/article/details/79839331

对什么进行监控

A、监控数据库MySQL的可用性

数据库进程或是端口存在,并不意味着数据库是可用的。通过网络连接到数据库并且确定数据库是对外提供服务的。

B、对数据库性能进行监控

QPS和TPS,MySQL并发线程数量,如何对Innodb阻塞和死锁进行监控。

C、对主从复制进行监控

D、对服务器资源的监控

磁盘空间,服务器磁盘空间大并不意味着MySQL数据库服务能使用的空间就足够大。

CPU的使用情况,内存的使用情况,Swap分区的使用情况以及网路IO的情况等。

一、数据库可用性监控

1、如何确认数据库是否可以通过网络连接,MySQL本地的SQL文件连接到数据库服务器,并不意味着能通过网络TCP/IP协议能连接到MySQL。

mysqladmin -umonitor_user -p -h ping

telnet ip db_port

使用程序通过网络建立数据库连接

2、如何确认数据库是否可读写

检查数据库的read_ony参数是否为off

建立监控表对表中数据进行更新

执行简单的查询select @@version;

3、如何监控数据库的连接数

show variables like 'max_connections';

show global status like 'Threads_connected';

根据Threads_connected / max_connections的值判断是否需要向管理员报警。

4、数据库性能监控

记录性能监控过程中所采集到的数据库的状态

如何计算QPS和TPS

QPS=(Queries2-Queries1)/(Uptime_since_flush_status2-Uptime_since_flush_status1)

TPS=((Com_insert2+Com_update2+Com_delete2)-(Com_insert1+Com_update1+Com_delete1))/(Uptime_since_flush_status2-Uptime_since_flush_status1)

如何监控数据库的并发请求数量,数据库性能的性能会随着并发处理请求数量的增加而下降。

CPU使用率

show global status like 'Threads_running';

并发处理的数量通常会远小于同一时间连接到数据库的线程的数量。

数据库出现大量阻塞。

如何监控Innodb的阻塞

select b.trx_mysql_thread_id as '被阻塞线程'

,b.trx_query as '被阻塞SQL'

,c.trx_mysql_thread_id as '阻塞线程'

,c.trx_query as '阻塞SQL'

,(unix_timestamp()-unix_timestamp(c.trx_started)) as '阻塞时间'

from information_schema.innodb_lock_waits as

join information_schema.innodb_trx b on a.requestion_trx_id=b.trx_id

join information_schema.innodb_trx c on a.blocking_trx_id=c.trx_id

where (unix_timestamp()-unix_timestamp(c.trx_started))>60

显示连接ID

select connection_id();

设置锁的超时时间

set global innodb_lock_wait_timeout=180;

5、如何监控主从复制链路的状态

如何监控主从复制延迟

show slave status \G

show master status \G

如何验证主从复制的数据是否一致

 pt-table-checksum u=dba,p='PassWord'\

--databases mysql \

--replicate test.checksums


grant select,process,super,replication salve on *.* to 'dba'@'ip' identified by 'PassWord'


猜你喜欢

转载自blog.csdn.net/qq_26346457/article/details/79839331