-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
health.go
41 lines (34 loc) · 1005 Bytes
/
health.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package mysqlctl
import (
"fmt"
"html/template"
"time"
"github.com/youtube/vitess/go/vt/health"
)
// mysqlReplicationLag implements health.Reporter
type mysqlReplicationLag struct {
mysqld *Mysqld
}
// Report is part of the health.Reporter interface
func (mrl *mysqlReplicationLag) Report(isSlaveType, shouldQueryServiceBeRunning bool) (time.Duration, error) {
if !isSlaveType {
return 0, nil
}
slaveStatus, err := mrl.mysqld.SlaveStatus()
if err != nil {
return 0, err
}
if !slaveStatus.SlaveRunning() {
return 0, fmt.Errorf("Replication is not running")
}
return time.Duration(slaveStatus.SecondsBehindMaster) * time.Second, nil
}
// HTMLName is part of the health.Reporter interface
func (mrl *mysqlReplicationLag) HTMLName() template.HTML {
return template.HTML("MySQLReplicationLag")
}
// MySQLReplicationLag lag returns a reporter that reports the MySQL
// replication lag.
func MySQLReplicationLag(mysqld *Mysqld) health.Reporter {
return &mysqlReplicationLag{mysqld}
}