doDBA工具的使用

to_be_Dba發表於2021-11-29

1.簡介

  • doDBA 工具是一個基於命令列的遠端系統監控工具。不依賴遠端伺服器的軟體執行。它能實時的收集Linux和MySQL的效能資料。並可以生成一個執行檔案來幫助您分析MySQL資料庫。
  • 這個程式是免費軟體。
  • doDBA是用go編寫的。

2.下載

wget 
wget 
chmod +x doDBA
或者
git pull

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 dodbaecho 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/bashhost_ip=("10.10.xx.xx")
INST_NAME="xxx"data_source=("myall","innodb")for IP in ${host_ip[@]}for SRC in ${data_source[@]}docd /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/bashps -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.sh1 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 statuswhere
  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 statuswhere
  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 statuswhere
  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 選項


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26451536/viewspace-2844519/,如需轉載,請註明出處,否則將追究法律責任。