Skip to content

Commit 926d817

Browse files
author
Guillaume Lefranc
committed
Consolidate display
1 parent 659c7ce commit 926d817

File tree

1 file changed

+33
-31
lines changed

1 file changed

+33
-31
lines changed

mariadb-repmgr/repmgr.go

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -250,17 +250,7 @@ func main() {
250250
for exit == false {
251251
select {
252252
case <-ticker.C:
253-
drawHeader()
254-
master.refresh()
255-
master.CheckMaster()
256-
vy = 6
257-
for k, _ := range slaves {
258-
slaves[k].refresh()
259-
slaves[k].drawSlave(&vy)
260-
}
261-
drawFooter(&vy)
262-
tlog.Print(&vy)
263-
termbox.Flush()
253+
display()
264254
case event := <-termboxChan:
265255
switch event.Type {
266256
case termbox.EventKey:
@@ -733,7 +723,7 @@ func getSeqFromGtid(gtid string) uint64 {
733723
return s
734724
}
735725

736-
func drawHeader() {
726+
func display() {
737727
termbox.Clear(termbox.ColorWhite, termbox.ColorBlack)
738728
headstr := fmt.Sprintf(" MariaDB Replication Monitor and Health Checker version %s ", repmgrVersion)
739729
if *failover != "" {
@@ -743,10 +733,7 @@ func drawHeader() {
743733
}
744734
printfTb(0, 0, termbox.ColorWhite, termbox.ColorBlack|termbox.AttrReverse|termbox.AttrBold, headstr)
745735
printfTb(0, 5, termbox.ColorWhite|termbox.AttrBold, termbox.ColorBlack, "%15s %6s %7s %12s %20s %20s %20s %6s %3s", "Slave Host", "Port", "Binlog", "Using GTID", "Current GTID", "Slave GTID", "Replication Health", "Delay", "RO")
746-
}
747-
748-
// Check Master Status and print it out to terminal. Increment failure counter if needed.
749-
func (master *ServerMonitor) CheckMaster() {
736+
// Check Master Status and print it out to terminal. Increment failure counter if needed.
750737
err := master.refresh()
751738
if err != nil && err != sql.ErrNoRows && failCount < 4 {
752739
failCount++
@@ -761,6 +748,36 @@ func (master *ServerMonitor) CheckMaster() {
761748
}
762749
printfTb(0, 2, termbox.ColorWhite|termbox.AttrBold, termbox.ColorBlack, "%15s %6s %41s %20s %12s", "Master Host", "Port", "Current GTID", "Binlog Position", "Strict Mode")
763750
printfTb(0, 3, termbox.ColorWhite, termbox.ColorBlack, "%15s %6s %41s %20s %12s", master.Host, master.Port, master.CurrentGtid, master.BinlogPos, master.Strict)
751+
vy = 6
752+
for _, slave := range slaves {
753+
printfTb(0, vy, termbox.ColorWhite, termbox.ColorBlack, "%15s %6s %7s %12s %20s %20s %20s %6d %3s", slave.Host, slave.Port, slave.LogBin, slave.UsingGtid, slave.CurrentGtid, slave.SlaveGtid, slave.healthCheck(), slave.Delay.Int64, slave.ReadOnly)
754+
vy++
755+
}
756+
vy++
757+
for _, server := range servers {
758+
f := false
759+
if server.State == STATE_UNCONN {
760+
if f == false {
761+
printfTb(0, vy, termbox.ColorWhite|termbox.AttrBold, termbox.ColorBlack, "%15s %6s %41s %20s %12s", "Standalone Host", "Port", "Current GTID", "Binlog Position", "Strict Mode")
762+
f = true
763+
vy++
764+
}
765+
server.refresh()
766+
printfTb(0, vy, termbox.ColorWhite|termbox.AttrBold, termbox.ColorBlack, "%15s %6s %41s %20s %12s", "Master Host", "Port", "Current GTID", "Binlog Position", "Strict Mode")
767+
printfTb(0, vy, termbox.ColorWhite, termbox.ColorBlack, "%15s %6s %41s %20s %12s", server.Host, server.Port, server.CurrentGtid, server.BinlogPos, server.Strict)
768+
vy++
769+
}
770+
771+
}
772+
vy++
773+
if master.CurrentGtid != "MASTER FAILED" {
774+
printTb(0, vy, termbox.ColorWhite, termbox.ColorBlack, " Ctrl-Q to quit, Ctrl-S to switchover")
775+
} else {
776+
printTb(0, vy, termbox.ColorWhite, termbox.ColorBlack, " Ctrl-Q to quit, Ctrl-F to failover")
777+
}
778+
vy = vy + 3
779+
tlog.Print(&vy)
780+
termbox.Flush()
764781
}
765782

766783
func (s *ServerMonitor) hasSiblings(sib []*ServerMonitor) bool {
@@ -772,21 +789,6 @@ func (s *ServerMonitor) hasSiblings(sib []*ServerMonitor) bool {
772789
return true
773790
}
774791

775-
func (slave *ServerMonitor) drawSlave(vy *int) {
776-
printfTb(0, *vy, termbox.ColorWhite, termbox.ColorBlack, "%15s %6s %7s %12s %20s %20s %20s %6d %3s", slave.Host, slave.Port, slave.LogBin, slave.UsingGtid, slave.CurrentGtid, slave.SlaveGtid, slave.healthCheck(), slave.Delay.Int64, slave.ReadOnly)
777-
*vy++
778-
}
779-
780-
func drawFooter(vy *int) {
781-
*vy++
782-
if master.CurrentGtid != "MASTER FAILED" {
783-
printTb(0, *vy, termbox.ColorWhite, termbox.ColorBlack, " Ctrl-Q to quit, Ctrl-S to switch over")
784-
} else {
785-
printTb(0, *vy, termbox.ColorWhite, termbox.ColorBlack, " Ctrl-Q to quit, Ctrl-F to fail over")
786-
}
787-
*vy = *vy + 3
788-
}
789-
790792
func NewTermLog(sz int) TermLog {
791793
tl := make(TermLog, sz)
792794
return tl

0 commit comments

Comments
 (0)