MySQL監控指標及採集方法

2021-10-03 07:31:35 字數 2230 閱讀 7126

mysql監控指標及採集方法

背景:線上生產環境mysql的架構是一主雙從,為了更好了解mysql集群執行狀況,我們需要對以下指標進行監控!

1一、對資料庫服務可用性進行監控

思路:1.1 通過測試賬號ping命令返回的資訊判斷資料庫可以通過網路連線

[root@host-39-108-217-12 scripts]# /usr/bin/mysqladmin -uroot -p123456 ping

mysqld is alive

1.2 確認資料庫是否可讀寫

a.檢查資料庫的read_only引數是否為off

[root@host-47-106-141-17 scripts]# mysql -uroot -p123456 -p3306 -e "show global variables like 'read_only'" | grep read_only

read_only   off

b.執行簡單的資料庫查詢,如:select @@version;

[root@host-47-106-141-17 scripts]# mysql -uroot -p123456 -p3306 -e "select @@version"  | grep mariadb

5.5.56-mariadb

二、對資料庫效能進行監控

2.1 監控資料庫連線數可用性

a.資料庫最大連線數

[root@host-47-106-141-17 scripts]# mysql -uroot -p123456 -e "show variables like 'max_connections'"

+-----------------+-------+

| variable_name   | value |

+-----------------+-------+

| max_connections | 151   |

+-----------------+-------+

b.資料庫當前開啟的連線數

[root@host-47-106-141-17 scripts]# mysqladmin -uroot -p123456 extended-status | grep -w "threads_connected"

| threads_connected                        | 1           |

注:如何計算當前開啟的連線數占用最大連線數的比例呢?

result=threads_connected/max_connections,在做監控報警或視覺化監控時能夠很好的根據這個比例及時調整最大連線數。

2.2 資料庫效能監控

a.qps:每秒的查詢數

qps計算方法

questions = show global status like 'questions';

uptime = show global status like 'uptime';

qps=questions/uptime

b.tps:每秒的事物量(commit與rollback的之和)

tps計算方法

com_commit = show global status like 'com_commit';

com_rollback = show global status like 'com_rollback';

uptime = show global status like 'uptime';

tps=(com_commit + com_rollback)/uptime

2.3 資料庫併發請求數量

mariadb [(none)]>  show global status like 'threads_running';

+-----------------+-------+

| variable_name   | value |

+-----------------+-------+

| threads_running | 3     |

+-----------------+-------+

1 row in set (0.00 sec)

注:併發請求數量通常會遠小於同一時間內連線到資料庫的連線數數量。

2.4 監控innodb阻塞情況

a. innodb

三、對主從複製進行監控

3.1 主從複製鏈路狀態的監控

3.2 主從複製延遲時間的監控

3.3 定期確認主從複製的資料是否一致

MySql效能監控指標(部分)

1.當前啟用的連線數 select from global status where variable name threads running 2.當前開啟的連線數 select from global status where variable name threads connected 3....

效能測試指標及常用監控工具

監控指標 效能測試通常需要監控的指標包括 1.伺服器linux 包括cpu memory load i o 2.資料庫 1.mysql 2.oracle 快取命中 索引 單條sql效能 資料庫 url 執行緒數 資料池連線數 3.中介軟體 1.jboss 2.apache 包括執行緒數 連線數 日誌...

Mysql 效能監控及調優

死鎖概念 兩個或兩個以上的程序在執行過程中,因爭奪資源而造成的一種互相等待的現象 1.監控死鎖 innotop 1 啟用 innodb status file 在 etc my.cnf新增如下 mysqld innodb status file 1 於 var lib mysql 下檢視.err日誌...