Menu Close

部署doDBA工具

1. 简介

doDBA 工具是一个基于控制台的远程系统监视器。 不需要远程系统上的特殊软件。 它从 linux 和 MySQL 收集实时性能数据。 并且可以生成doing文件来帮助你分析MySQL数据库。 该程序是免费软件。doDBA 是用 go 编写的。

file

2. 下载

下载地址: https://github.com/dblucyne/dodba_tools

解压文件后只有三个文件,分别为:doDBA(运行程序)、doDBA.conf(配置文件)、README.md(使用说明)

3. 部署方式

3.1. 选择部署的服务

doDBA不需要部署在数据库服务器上,建议将doDBA安装在某一台主机上(该主机不需要安装MySQL数据库),监控其他被监控主机及数据库。

3.2. 创建目录

按照业务、主机、[实例] 等分别创建,例如:

mkdir -p /data/dodba_tools-master/easytong_cloud/{121,122,123}

我这里 easytong_cloud 表示监控的业务名,121,122,123分别为三台服务器的主机IP地址。

3.3. 拷贝 doDBA 程序到每个子目录中

对于监控多个数据库必须运行多个 doDBA 进程,这样需要将doDBA运行程序以及配置文件拷贝到 3.2. 创建的目录中:

# 修改 doDBA 为可执行程序
chmod u+x doDBA
# 批量拷贝
echo /data/dodba_tools-master/easytong_cloud/{121,122,123} |xargs -n 1 cp -v ./doDBA*

3.4. 在被监控的数据库中添加用户账号

在被监控的数据库中添加用户账号,以及授予相应的权限,例如:

create user dodba@'%' identified by "dodba!123";
grant all privileges on *.* to dodba@'%';
grant process on *.* to 'dodba'@'%';
flush privileges;

3.5. 配置 doDBA.conf

doDBA.conf的配置文件非常简单,下面给出注释

]# cat doDBA.conf
{
"Host":"172.16.4.121",    # 被监控主机的IP地址
"Huser": "root",          # 访问被监控主机操作系统的用户名
"Hport": "22",            # 访问被监控主机操作系统的端口
"Hpwd":  "XXXXXX",        # 访问被监控主机操作系统的密码
"Muser": "dodba",         # 访问被监控主机数据库的用户名
"Mpwd":  "dodba!123",     # 访问被监控主机数据库的密码
"Mport":"6006"            # 访问被监控主机数据库的端口
}

对 3.2. 目录下的 doDBA.conf 做相应的修改。

3.6. 编写启动脚本

需要批量运行各个目录下的 doDBA 程序,编写的脚本如下:

~]# cat start_doDBA.sh
#!/bin/bash
inst_name=("easytong_cloud")
host_name=("121 122 123")
for SRC in ${host_name[@]}
  do
    cd /data/dodba_tools-master/${inst_name}/${SRC}/
    ./doDBA -c /data/dodba_tools-master/${inst_name}/${SRC}/doDBA.conf -myall -t=8 -log  &
  done

<span style='color:red'>-t 参数根据实际情况设置,如果同一时刻的并发本身就很大,可以将该值设置大一些,反之就设置小一些。</span>

3.7. 编写停止脚本

编辑kill doDBA脚本,已便每天生成一个日志文件,同时删除7天以前产生的日志文件,示例如下:

~]# cat kill_doDBA.sh
#!/bin/bash
ps -ef | grep doDBA | grep -v grep | awk '{print $2}' | xargs kill -9 >/dev/null 2>&1
find /data/dodba_tools-master/ -name "*.log" -type f -mtime +7 -exec rm -f {} \;

注意避免与其他 doDBA 同名的文件冲突。

3.8. 创建crontab定时任务

~]# crontab -e
59 23 * * * sh /data/dodba_tools-master/kill_doDBA.sh
0 0 * * * sh /data/dodba_tools-master/start_doDBA.sh

4. 使用帮助

./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  # 不加颜色输出

5. 使用示例

5.1. 数据源:mysql

  • 启动命令
./doDBA -c doDBA.conf -mysql -log
  • 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"
  );
  • 输出

  • 每列含义
# 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

5.2.数据源:innodb

  • 启动命令
./doDBA -c doDBA.conf -innodb -log
  • 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"
  );
  • 输出

  • 每列含义
# 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

5.3.数据源:sys

  • 命令
./doDBA -c doDBA.conf -sys -log
  • 输出

5.4.数据源:myall

  • 命令
./doDBA -c doDBA.conf -myall -log
  • 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"
  );
  • 输出

5.5. 加入 doing 选项

使用【-t】参数可以基于Threads_running的数量设置阈值,设置后可记录「processlist,engine innodb status」信息到 <span style='color:red'>dodba.log</span> 日志中,重现现场。

  • 命令
    当 Thread_running >= 3 时,执行show processlist 和 show engine innodb status
./doDBA -c doDBA.conf -myall -t=3
  • 输出

5.6. 数据源:mytop

  • 命令
./doDBA -c doDBA.conf -mytop
  • 输出

  • 注意事项
    mytop的输出类似 top 命令,是实时刷新的,不能加 -log 选项

附录

另一方式监控多个数据库运行情况,见文档:https://www.cnblogs.com/zetanchen/p/14101089.html