bugfix: server hearbeat

This commit is contained in:
Ulric Qin 2022-08-27 10:35:15 +08:00
parent 3963470603
commit a38e50d6b8
3 changed files with 13 additions and 2 deletions

View File

@ -72,7 +72,7 @@ func AlertingEngineGetsInstances(where string, args ...interface{}) ([]string, e
return arr, err
}
func AlertingEngineHeartbeat(instance string) error {
func AlertingEngineHeartbeat(instance, cluster string) error {
var total int64
err := DB().Model(new(AlertingEngines)).Where("instance=?", instance).Count(&total).Error
if err != nil {
@ -83,6 +83,7 @@ func AlertingEngineHeartbeat(instance string) error {
// insert
err = DB().Create(&AlertingEngines{
Instance: instance,
Cluster: cluster,
Clock: time.Now().Unix(),
}).Error
} else {

View File

@ -74,6 +74,11 @@ func MustLoad(fpaths ...string) {
C.ReaderFrom = "config"
}
if C.ReaderFrom == "config" && C.ClusterName == "" {
fmt.Println("configuration ClusterName is blank")
os.Exit(1)
}
if C.Heartbeat.IP == "" {
// auto detect
// C.Heartbeat.IP = fmt.Sprint(GetOutboundIP())

View File

@ -37,7 +37,12 @@ func loopHeartbeat() {
}
func heartbeat() error {
err := models.AlertingEngineHeartbeat(config.C.Heartbeat.Endpoint)
cluster := ""
if config.C.ReaderFrom == "config" {
cluster = config.C.ClusterName
}
err := models.AlertingEngineHeartbeat(config.C.Heartbeat.Endpoint, cluster)
if err != nil {
return err
}