时间:2021-07-01 10:21:17 帮助过:30人阅读
目前在Linux跑MySQL是大多数互联网公司的标配,以上图片的性能数据指标项是我认为在Linux,MySQL,InnoDB中较为重要的实时状态数据,然而在以上图片Doing一栏其实更为重要,之所以把它叫做Doing,是因为「processlist,engine innodb status,locks」等指标项才真正反映了MySQL此时正在做什么。
我们来对标Oracle数据库看一下,在Oracle数据库中提供了「AWR,ASH,SQL Monitor」等众多诊断工具,可以一眼望穿数据库正在做什么,甚至都可以知道在过去30天内任何一个时间区间的性能负载和当时数据库正在做什么。
在MySQL中虽然有像「zabbix,PMM」等优秀的监控工具,但它们只能反映数据库历史的一些性能数据曲线,例如,TPS高了,临时表使用多了,有InnoDB Deadlocks,但对于MySQL当时的Doing,我只能说不够直接。如果你在现场,你可以抓到MySQL正在做什么,但是,你总有不在现场的时候,如果问你昨天晚上数据库的性能抖动是什么原因?怎样快速重现现场找到引起抖动的原因呢?
基于golang语言开发
可收集Linux、MySQL相关性能数据
可本地或远程收集,可多台
mytop --Like Linux TOP
基于并发生成Doing日志,复现现场
可记录到日志文件
doDBA tools 工作原理
远程收集系统信息是通过ssh(用户名密码或建立信任)的方式连接到远程服务器上收集,收集的方法都是通过读取Linux的proc下的等meminfo,diskstats,uptime,net,vmstat ,cpuinfo ,loadavg等文件,这和pmm,zabbix收集方式一致。
远程收集MySQL信息是通过 MySQL tcp连接到MySQL数据库上收集,只需要授予连接用户PROCESS、SELECT权限即可。
系统信息和MySQL信息的收集可以分离,如果只想收集系统信息,只需要提供系统用户名密码即可,如果只收集MySQL可以只提供MySQL连接信息,如果是rds用户,可以使用-rds参数,在使用mytop时会自动忽略系统信息的收集。
- <code class="hljs cpp" style="margin: 0px; padding: 0px; display: inline"><span style="margin: 0px; padding: 0px; color: #dd1144">https:<span style="margin: 0px; padding: 0px; color: #999988; font-style: italic"><span class="hljs-comment">//github.com/dblucyne/dodba_tools</span></span></span></code>
- <code class="hljs nginx" style="margin: 0px; padding: 0px; display: inline"><span class="hljs-attribute">wget http<span style="margin: 0px; padding: 0px; color: #008080">s://raw.githubusercontent.<span style="margin: 0px; padding: 0px; font-weight: bold">com/dblucyne/dodba_tools/master/doDBA --<span style="margin: 0px; padding: 0px; font-weight: bold"><span class="hljs-literal">no-check-certificate
- wget http<span style="margin: 0px; padding: 0px; color: #008080">s://raw.githubusercontent.<span style="margin: 0px; padding: 0px; font-weight: bold">com/dblucyne/dodba_tools/master/doDBA.<span style="margin: 0px; padding: 0px; font-weight: bold">conf --<span style="margin: 0px; padding: 0px; font-weight: bold"><span class="hljs-literal">no-check-certificate
- chmod +<span style="margin: 0px; padding: 0px; font-weight: bold">x doDBA<br style="margin: 0px; padding: 0px">
- 下载下来就可以直接使用,不依赖于任何环境。</span></span></span></span></span></span></span></span></span></span></span></code>
- <code class="hljs sql" style="margin: 0px; padding: 0px; display: inline">./doDBA -<span style="margin: 0px; padding: 0px"><span style="margin: 0px; padding: 0px; font-weight: bold"><span class="hljs-keyword">help
- -<span style="margin: 0px; padding: 0px; font-weight: bold">c <span style="margin: 0px; padding: 0px; font-weight: bold"><span class="hljs-keyword">string
- configuration <span style="margin: 0px; padding: 0px; font-weight: bold">file.(<span style="margin: 0px; padding: 0px; font-weight: bold"><span class="hljs-keyword">default <span style="margin: 0px; padding: 0px; color: #dd1144"><span class="hljs-string">"doDBA.conf")
- -h <span style="margin: 0px; padding: 0px; font-weight: bold"><span class="hljs-keyword">string
- <span style="margin: 0px; padding: 0px; font-weight: bold"><span class="hljs-keyword">Connect <span style="margin: 0px; padding: 0px; font-weight: bold"><span class="hljs-keyword">to host/IP.
- -<span style="margin: 0px; padding: 0px; font-weight: bold"><span class="hljs-keyword">sys
- Print linux info.
- -myall
- Print linux <span style="margin: 0px; padding: 0px; font-weight: bold"><span class="hljs-keyword">and mysql info.
- </span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></code><code class="hljs diff" style="margin: 0px; padding: 0px; display: inline"><span class="hljs-deletion">-mysql</span></code><code class="hljs nginx" style="margin: 0px; padding: 0px; display: inline">
- <span class="hljs-attribute">Print mysql <span class="hljs-literal">info.
- -<span style="margin: 0px; padding: 0px; font-weight: bold">innodb
- Print <span style="margin: 0px; padding: 0px; font-weight: bold">innodb <span class="hljs-literal">info.
- -mytop
- Print mysql prcesslist,<span style="margin: 0px; padding: 0px; font-weight: bold">like top.
- -<span style="margin: 0px; padding: 0px; font-weight: bold">i <span style="margin: 0px; padding: 0px; font-weight: bold">duration
- <span style="margin: 0px; padding: 0px; font-weight: bold">refresh <span style="margin: 0px; padding: 0px; color: #0086b3">interval <span style="margin: 0px; padding: 0px; font-weight: bold">in seconds.(<span style="margin: 0px; padding: 0px; color: #008080"><span class="hljs-number">1<span class="hljs-number">s)
- -<span style="margin: 0px; padding: 0px; font-weight: bold">t <span style="margin: 0px; padding: 0px; color: #0086b3">int
- doing <span style="margin: 0px; padding: 0px; font-weight: bold"><span class="hljs-literal">on Threads_running.(<span style="margin: 0px; padding: 0px; color: #008080"><span class="hljs-number">50)</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></code><code class="hljs perl" style="margin: 0px; padding: 0px; display: inline"> <br style="margin: 0px; padding: 0px">
- -rds <br style="margin: 0px; padding: 0px">
- Ignore <span class="hljs-keyword">system info.</span></code><code class="hljs php" style="margin: 0px; padding: 0px; display: inline">
- -<span style="margin: 0px; padding: 0px; font-weight: bold">log
- <span class="hljs-keyword">Print <span style="margin: 0px; padding: 0px; font-weight: bold">to <span style="margin: 0px; padding: 0px; font-weight: bold">file <span style="margin: 0px; padding: 0px; font-weight: bold">by <span style="margin: 0px; padding: 0px; font-weight: bold">day.
- -nocolor
- <span class="hljs-keyword">Print <span style="margin: 0px; padding: 0px; font-weight: bold">to nocolor.</span></span></span></span></span></span></span></span></code>
2. 收集MySQL性能数据
- <code class="hljs css" style="margin: 0px; padding: 0px; display: inline">10<span style="margin: 0px; padding: 0px"><span class="hljs-selector-class">.1<span style="margin: 0px; padding: 0px"><span class="hljs-selector-class">.x<span style="margin: 0px; padding: 0px"><span class="hljs-selector-class">.x1<br style="margin: 0px; padding: 0px"><span class="hljs-selector-class">10<span style="margin: 0px; padding: 0px"><span class="hljs-selector-class">.1<span style="margin: 0px; padding: 0px"><span class="hljs-selector-class">.x<span style="margin: 0px; padding: 0px"><span class="hljs-selector-class">.x2</span></span></span></span></span></span></span></span></span></span></span></span></span></code>
- <code class="hljs bash" style="margin: 0px; padding: 0px; display: inline">cat ip.txt | <span style="margin: 0px; padding: 0px; font-weight: bold"><span class="hljs-keyword">while <span class="hljs-built_in">read ip;
- <span class="hljs-keyword">do
- <span class="hljs-built_in">echo <span style="margin: 0px; padding: 0px; color: #008080"><span class="hljs-variable">$ip;
- ./<span class="hljs-keyword">doDBA -h=<span style="margin: 0px; padding: 0px; color: #008080"><span class="hljs-variable">$ip -mysql -log </dev/null &
- <span class="hljs-keyword">done</span></span></span></span></span></span></span></span></span></span></span></code>
使用【-t】参数可以基于Threads_running的数量设置阈值,设置后可记录「processlist,engine innodb status」信息到dodba.log日志中,--复现现场。
MySQL 的实时性能监控利器
标签:监控工具 log 数据库 size 抖动 help use inno uil