目錄
1.簡介
- doDBA 工具是一個基於命令行的遠程系統監控工具。不依賴遠程服務器的軟件運行。它能實時的收集Linux和MySQL的性能數據。並可以生成一個執行文件來幫助您分析MySQL數據庫。
- 這個程序是免費軟件。
- doDBA是用go編寫的。
2.下載
wget https://raw.githubusercontent.com/dblucyne/dodba_tools/master/doDBA --no-check-certificate
wget https://raw.githubusercontent.com/dblucyne/dodba_tools/master/doDBA.conf --no-check-certificate
chmod +x doDBA
或者
git pull https://github.com/dblucyne/dodba_tools
3.使用幫助
./doDBA -help
-help # 顯示幫助
-c string # 指定配置文件 (default "doDBA.conf")
-h string # 連接的 host/IP
-sys # 打印Linux的信息
-myall # 打印Linux和MySQL的信息
-mysql # 打印MySQL的信息
-innodb # 打印InnoDB存儲引擎的信息
-mytop # 打印MySQL processlist,類似top
-i <duration> # 刷新間隔的秒數 (默認1s)
-t <int> #當MySQL Threads_running到達閾值時會輸出 show processlist和showengine innodb status到dodba.log中 (默認50)
-hP <string> # 主機端口 (默認 "22")
-hp <string> # 主機密碼
-hu <string> # 主機用戶 (默認 "root")
-mP <string> # MySQL端口 (默認 "3306")
-mp <string> # MySQL密碼
-mu <string> # MySQL用戶
-rds # 忽略Linux信息
-log # 按照日期輸出到日志文件
-nocolor # 不加顏色輸出
4.配置
4.1.模板
cat doDBA.conf
{
"Host":"",
"Huser": "root",
"Hport": "22",
"Hpwd": "",
"Muser": "dodba",
"Mpwd": "dodba",
"Mport":"3306"
}
4.2.啟動命令
./doDBA -c=doDBA.conf
5.部署流程
5.1.下載
5.2.選定被監控主機
5.3.在被監控主機上添加Linux用戶、MySQL 用戶
Linux:
groupadd dodba
useradd dodba -g dodba
echo xxxx | passwd dbdba --stdin
MySQL:
create user dodba@’xxx.xxx.xxx.%’ identified by ‘dodba’;
grant process on *.* to dodba@'xxx.xxx.xxx.%';
5.4.配置SSH互信
5.5.配置doDBA配置文件,並修改對應參數
5.6.創建日志目錄,按照業務、主機、實例等分別創建
mkdir -p /data/doDBA_log/piwik/mysql{1,2}_log/{myall,innodb}
5.7.啟動doDBA
- 建議將doDBA安裝在某一台主機上,監控其他被監控主機及數據庫
5.7.1. 啟動腳本,配置了 myall 和 innodb 數據源
cat start_doDBA.sh
#!/bin/bash
host_ip=("10.10.xx.xx")
INST_NAME="xxx"
data_source=("myall","innodb")
for IP in ${host_ip[@]}
for SRC in ${data_source[@]}
do
cd /data/doDBA_log/${inst_name}/mysql1_log/myall/
./doDBA -h ${IP} -c /data/doDBA_log/${INST_NAME}/mysql1_log/${SRC}/${INST_NAME}_doDBA.conf -$SRC -t=20 -log &
done
5.8.編輯kill doDBA和start doDBA腳本,已便每天生成一個日志文件。
cat kill_doDBA.sh
#!/bin/bash
ps -ef | grep doDBA | grep -v grep | awk '{print $2}' | xargs kill -9 >/dev/null 2>&1
5.9.配置crontab定時任務。
crontab -e
0 0 # # # sh kill_doDBA.sh
1 0 # # # sh start_doDBA.sh
6.數據源參數優先級
- 經過實際測試,一個 doDBA 進程同時只能配置一個數據源參數,配置2個及以上時,只能生效一個,說明參數有優先級的區別。
- 優先級如下:
- mysql > innodb > myall > sys
7.使用示例
7.1. 數據源:mysql
7.1.1. 啟動命令
./doDBA -c doDBA.conf -mysql -log
7.1.2.doDBA 發送給 MySQL 的查詢語句
show global status
where
Variable_name in (
"Com_select",
"Com_insert",
"Com_update",
"Com_delete",
"Innodb_buffer_pool_read_requests",
"Innodb_buffer_pool_reads",
"Innodb_rows_inserted",
"Innodb_rows_updated",
"Innodb_rows_deleted",
"Innodb_rows_read",
"Threads_running",
"Threads_connected",
"Threads_cached",
"Threads_created",
"Bytes_received",
"Bytes_sent",
"Innodb_buffer_pool_pages_data",
"Innodb_buffer_pool_pages_free",
"Innodb_buffer_pool_pages_dirty",
"Innodb_buffer_pool_pages_flushed",
"Innodb_data_reads",
"Innodb_data_writes",
"Innodb_data_read",
"Innodb_data_written",
"Innodb_os_log_fsyncs",
"Innodb_os_log_written",
"Slow_queries",
"Created_tmp_disk_tables",
"Created_tmp_tables",
"Open_tables",
"Open_files",
"Table_locks_immediate",
"Table_locks_waited"
);
7.1.3. 輸出
7.1.4.每列含義
-
mysql-status
- qps —— Com_select
- tps —— Com_insert + Com_update + Com_delete
- ins —— Com_insert
- upd —— Com_update
- del —— Com_delete
-
threads
- run —— Threads_running
- con —— Threads_connected
- cre —— Threads_created
- cac —— Threads_cached
-
slow
- sql —— Slow_queries
- tmp —— Created_tmp_tables
- dtmp —— Created_tmp_disk_tables
-
bytes
- recv —— Bytes_received
- send —— Bytes_sent
-
locks
- lockI —— Table_locks_immediate
- lockW —— Table_locks_waited
- openT —— Open_tables
- openF —— Open_files
7.2.數據源:innodb
7.2.1.啟動命令
./doDBA -c doDBA.conf -innodb -log
7.2.2.doDBA 發送給 MySQL 的查詢語句(同7.1.2)
show global status
where
Variable_name in (
"Com_select",
"Com_insert",
"Com_update",
"Com_delete",
"Innodb_buffer_pool_read_requests",
"Innodb_buffer_pool_reads",
"Innodb_rows_inserted",
"Innodb_rows_updated",
"Innodb_rows_deleted",
"Innodb_rows_read",
"Threads_running",
"Threads_connected",
"Threads_cached",
"Threads_created",
"Bytes_received",
"Bytes_sent",
"Innodb_buffer_pool_pages_data",
"Innodb_buffer_pool_pages_free",
"Innodb_buffer_pool_pages_dirty",
"Innodb_buffer_pool_pages_flushed",
"Innodb_data_reads",
"Innodb_data_writes",
"Innodb_data_read",
"Innodb_data_written",
"Innodb_os_log_fsyncs",
"Innodb_os_log_written",
"Slow_queries",
"Created_tmp_disk_tables",
"Created_tmp_tables",
"Open_tables",
"Open_files",
"Table_locks_immediate",
"Table_locks_waited"
);
7.2.3.輸出
7.2.4.每列含義
-
innodb--rows
- read —— Innodb_rows_read
- ins —— Innodb_rows_inserted
- upd —— Innodb_rows_updated
- del —— Innodb_rows_deleted
-
innodb--pages
- data —— Innodb_buffer_pool_pages_data
- free —— Innodb_buffer_pool_pages_free
- dirty —— Innodb_buffer_pool_pages_dirty
- flush —— Innodb_buffer_pool_pages_flushed
-
innodb--data
- reads —— Innodb_data_reads
- writes —— Innodb_data_writes
- read —— Innodb_data_read
- written —— Innodb_data_written
-
innodb-log
- fsyncs —— Innodb_os_log_fsyncs
- written —— Innodb_os_log_written
7.3.數據源:sys
7.3.1.命令
./doDBA -c doDBA.conf -sys -log
7.3.2.輸出
7.4.數據源:myall
7.4.1.命令
./doDBA -c doDBA.conf -myall -log
7.4.2.doDBA 發送給 MySQL 的查詢語句(同7.1.2)
show global status
where
Variable_name in (
"Com_select",
"Com_insert",
"Com_update",
"Com_delete",
"Innodb_buffer_pool_read_requests",
"Innodb_buffer_pool_reads",
"Innodb_rows_inserted",
"Innodb_rows_updated",
"Innodb_rows_deleted",
"Innodb_rows_read",
"Threads_running",
"Threads_connected",
"Threads_cached",
"Threads_created",
"Bytes_received",
"Bytes_sent",
"Innodb_buffer_pool_pages_data",
"Innodb_buffer_pool_pages_free",
"Innodb_buffer_pool_pages_dirty",
"Innodb_buffer_pool_pages_flushed",
"Innodb_data_reads",
"Innodb_data_writes",
"Innodb_data_read",
"Innodb_data_written",
"Innodb_os_log_fsyncs",
"Innodb_os_log_written",
"Slow_queries",
"Created_tmp_disk_tables",
"Created_tmp_tables",
"Open_tables",
"Open_files",
"Table_locks_immediate",
"Table_locks_waited"
);
7.4.3.輸出
7.4.5.文本輸出(GitHub示例)
7.4.5.1.普通輸出
/doDBA -h=10.1.xx.xx -myall
DoDBA tools on host 10.1.xx.xx
---------+---load--avg---+-----cpu-usage-----+-swap+----net----+----mysql-status-------+-slow---th---+---bytes---
time | 1m 5m 10m | usr sys iow ide | si so| recv send | QPS TPS ins upd del| sql run con | recv send
--------+-----------------+----------------------+------+------------+------------------------+---------------+-----------
13:52:00 | 4.00 3.68 3.60| 0.7 0.3 0.0 99.0 | 0 0 | 316K 4.3M| 203 58 22 36 0 | 0 2 52 | 86K 1.8M
13:52:01 | 4.00 3.68 3.60| 5.3 0.3 0.1 94.3 | 0 0 | 275K 2.0M| 251 67 27 40 0 | 0 3 76 | 104K 3.2M
13:52:02 | 4.00 3.68 3.60| 6.4 0.5 0.1 93.0 | 0 0 | 371K 4.1M| 380 810 24 786 0 | 0 3 40 | 311K 5.0M
13:52:03 | 4.00 3.68 3.60| 5.4 0.4 0.0 94.2 | 0 0 | 510K 4.2M| 648 283 30 253 0 | 1 3 52 | 216K 1.4M
13:52:04 | 4.00 3.68 3.60| 5.7 0.4 0.0 93.8 | 0 0 | 385K 2.7M| 108 69 45 24 0 | 0 4 48 | 71K 2.1M
13:52:05 | 3.92 3.66 3.59| 6.2 0.5 0.0 93.3 | 0 0 | 206K 2.0M| 339 96 52 44 0 | 0 3 37 | 107K 1.9M
7.4.5.2.忽略操作系統信息
./doDBA -h=10.1.xx.xx -myall -rds
DoDBA tools on host 10.1.xx.xx
---------+----load--avg----+-----cpu-usage-----+swap+----net----+-----mysql-status------+-slow---th---+---bytes---
time | 1m 5m 10m | usr sys iow ide|siso| recv send|QPS TPS ins upd del| sql run con| recv send
---------+------------------+-------------------+----+-----------+-----------------------+-------------+-----------
17:19:17 | 0.00 0.00 0.00 | 0.0 0.0 0.0 0.0 | 0 0 | 0K 0K | 144 155 73 82 0 | 0 1 5 | 113K 229K
17:19:18 | 0.00 0.00 0.00 | 0.0 0.0 0.0 0.0 | 0 0 | 0K 0K | 66 113 32 81 0 | 0 2 6 | 79K 109K
17:19:19 | 0.00 0.00 0.00 | 0.0 0.0 0.0 0.0 | 0 0 | 0K 0K | 273 117 30 87 0 | 1 2 20 | 135K 502K
17:19:20 | 0.00 0.00 0.00 | 0.0 0.0 0.0 0.0 | 0 0 | 0K 0K | 207 173 74 99 0 | 1 2 17 | 137K 279K
17:19:21 | 0.00 0.00 0.00 | 0.0 0.0 0.0 0.0 | 0 0 | 0K 0K | 161 233 105 128 0 | 0 1 5 | 146K 193K
7.4.5.3.加入 doing 選項,當 Thread_running >= 3 時,執行show processlist 和 show engine innodb status
./doDBA -h=10.1.xx.xx -myall -t=3
2016/12/14 11:47:52 ----------------processlist---------------
ID:606374462
User:ums_read
Host:10.1.xx.xx:31886
DB:mia
Command:Query
Time:3121
State:Sending data
Info:SELECT ......................
=====================================
2016-12-14 11:49:16 7f93ece24700 INNODB MONITOR OUTPUT
=====================================
Per second averages calculated from the last 1 seconds
-----------------
BACKGROUND THREAD
-----------------
srv_master_thread loops: 11256164 srv_active, 0 srv_shutdown, 27867 srv_idle
srv_master_thread log flush and writes: 11284031
----------
SEMAPHORES
----------
OS WAIT ARRAY INFO: reservation count 1562657988
OS WAIT ARRAY INFO: signal count 11589318962
Mutex spin waits 7915500772, rounds 7044249291, OS waits 29061199
RW-shared spins 15964124137, rounds 99809511531, OS waits 1188604739
RW-excl spins 1056480533, rounds 26766008869, OS waits 261290579
........................................
7.5.數據源:mytop
7.5.1.命令
./doDBA -c doDBA.conf -mytop
7.5.3.注意事項
- mytop的輸出類似 top 命令,是實時刷新的,不能加 -log 選項