1.数据库监控
QPS:Queries Per Second 查询量/秒,是一台服务器每秒能够相应的查询次数,是对一个特定的查询服务器在规定时间内所处理查询量多少的衡量标准
TPS : Transactions Per Second 是事务数/秒,是一台数据库服务器在单位时间内处理的事务的个数。
如何监控数据库的连接数
show variables like 'max_connections';
show global status like 'Threads_connected';
Threads_connected/max_connections>0.8 报警
(1)QPS(每秒Query量)
QPS = Questions(or Queries) / seconds
mysql > show global status like 'Question%';
(2)TPS(每秒事务量)
TPS = (Com_commit + Com_rollback) / seconds
mysql > show global status like 'Com_commit';
mysql > show global status like 'Com_rollback';
(3)key Buffer 命中率
mysql>show global status like 'key%';
key_buffer_read_hits = (1-key_reads / key_read_requests) * 100%
key_buffer_write_hits = (1-key_writes / key_write_requests) * 100%
(4)InnoDB Buffer命中率
mysql> show status like 'innodb_buffer_pool_read%';
innodb_buffer_read_hits = (1 - innodb_buffer_pool_reads / innodb_buffer_pool_read_requests) * 100%
(5)Query Cache命中率
mysql> show status like 'Qcache%';
Query_cache_hits = (Qcahce_hits / (Qcache_hits + Qcache_inserts )) * 100%;
如何计算 QPS和 TPs
QPS=(Queries2-Queriesl)/(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)
(6)如何监控数据库的并发请求数量
数据库系统的性能会随着并发处理请求数量的增加而下降
show global status like 'Threads_running';
并发处理的数量通常会远小于同一时间连接到数据库的线程的数量(数据库出现大量阻塞)
(7)如何监控 Innodb 的阻塞
SELECT b.trx_mysql_thread_idAS'被阻塞线程',
b.trx_queryAs'被阻塞 SQL',
c.trx_mysql_thread_idas'阻塞线程',
c.trx_queryas'阻塞SQL',
(UNIX_TIMESTAMP() -UNIX_TIMESTAMP( c.trx_started))AS'阻塞时间'
FROM information_schema.innodb_lock_waits a
JOIN information_schema.innodb_trx boN a.requestingtrx_id=b.trx_id
JOIN information_schema_innodb_trx coN a.blocking_trx_id=c.trx_id
WHERE(UNIX_TIMESTAMP()-UNIX_TIMESTAMP(c. trx_started))>60;
网友评论