iT邦幫忙

2017 iT 邦幫忙鐵人賽
DAY 25
0
自我挑戰組

MariaDB 的使用與管理系列 第 25

DBA Daily Check Report 的製作 [8]

各位朋友聖誕節快樂!

今天是 DBA Daily Check Report 這個系列的最後一篇文章,說明 Replication Status。

這個是說希望能在報表中知道 Slave 的基本狀況,尤其是 Slave 如果發生 Error,會卡在那邊,如果 binlog 有 expire 時間的話,太晚知道問題解決完後 binlog 因 expire 會不見,就有機會無法復原。

首先,先透過 information_schema.GLOBAL_STATUS SLAVE_RUNNING 看該台機器是 Master 還是 Slave (在 CheckSlave.sql中)

select case variable_value when 'ON' then 'O' else '' end from information_schema.GLOBAL_STATUS where variable_name='SLAVE_RUNNING';

如果是的話就是 Slave。

看 Slave 狀態,指令是 show slave status (在 ShowSlaveStatus.sql 中),但這個指令筆者找了很久,完全不知道是 reference 哪個 table 或是 variable,於是只能自己 Parsing 了。


$Html = $Html + "<h2>Slave Status</h2>"
& $mysqlexe -u $rptuser --password=$rptpass -h $ServerIP -sN -e "source .\ShowSlaveStatus.sql" > out.html

if ((Get-Item .\out.html).length -gt 0)
{
$Html = $Html + "<table>
<tr>
<th>Master Host</th>
<th>Master Log File</th>
<th>Relay Master Log File</th>
<th>Slave IO State</th>
<th>Last Errno</th>
<th>Last Error</th>
<th>Last IO Errno</th>
<th>Last IO Error</th>
<th>Last SQL Errno</th>
<th>Last SQL Error</th>
</tr>"

$stat = [string[]](Get-Content .\out.html)

$Html = $Html + "<tr><td>" + $stat[2] + "</td><td>" + $stat[6] + "</td><td>" + $stat[10] + "</td><td>" + $stat[1] + "</td><td>"

if ($stat[19] -eq "0") {$Html = $Html + $stat[19] + "</td><td>" + $stat[20] + "</td><td>"}
else {$Html = $Html + "<div class=""Critical"">" + $stat[19] + "</div></td><td><div class=""Critical"">" + $stat[20] + "</div></td><td>"}

if ($stat[35] -eq "0") {$Html = $Html + $stat[35] + "</td><td>" + $stat[36] + "</td><td>"}
else {$Html = $Html + "<div class=""Critical"">" + $stat[35] + "</div></td><td><div class=""Critical"">" + $stat[36] + "</div></td><td>"}

if ($stat[37] -eq "0") {$Html = $Html + $stat[37] + "</td><td>" + $stat[38] + "</div></td></tr></table>"}
else {$Html = $Html + "<div class=""Critical"">" + $stat[37] + "</div></td><td><div class=""Critical"">" + $stat[38] + "</div></td></tr></table>"}
}
else {
$Html = $Html + "<span class=""Critical"">No Slave Status</span><br/>"
}

基本上就是分開數位子,就完成了。


上一篇
DBA Daily Check Report 的製作 [7]
下一篇
Audit Log Parser 的實做 [1]
系列文
MariaDB 的使用與管理30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言