mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
feat(alerting): add heartbeat writer
This commit is contained in:
parent
a66027830b
commit
a1f97e0b77
@ -52,6 +52,13 @@ type AlertingClusterInfo struct {
|
||||
UptimePosition int
|
||||
}
|
||||
|
||||
type HeartBeat struct {
|
||||
Id int64
|
||||
ServerId string
|
||||
Updated time.Time
|
||||
Created time.Time
|
||||
}
|
||||
|
||||
type HeartBeatCommand struct {
|
||||
ServerId string
|
||||
|
||||
|
@ -17,8 +17,52 @@ func init() {
|
||||
bus.AddHandler("sql", GetAlertById)
|
||||
bus.AddHandler("sql", DeleteAlertById)
|
||||
bus.AddHandler("sql", GetAllAlertQueryHandler)
|
||||
//bus.AddHandler("sql", HeartBeat)
|
||||
}
|
||||
|
||||
/*
|
||||
func HeartBeat(query *m.HeartBeatCommand) error {
|
||||
return inTransaction(func(sess *xorm.Session) error {
|
||||
now := time.Now().Sub(0, 0, 0, 5)
|
||||
activeTime := time.Now().Sub(0, 0, 0, 5)
|
||||
ownHeartbeats := make([]m.HeartBeat, 0)
|
||||
err := x.Where("server_id = ?", query.ServerId).Find(&ownHeartbeats)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if (len(ownHeartbeats)) > 0 && ownHeartbeats[0].Updated > activeTime {
|
||||
//update
|
||||
x.Insert(&m.HeartBeat{ServerId: query.ServerId, Created: now, Updated: now})
|
||||
} else {
|
||||
thisServer := ownHeartbeats[0]
|
||||
thisServer.Updated = now
|
||||
x.Id(thisServer.Id).Update(&thisServer)
|
||||
}
|
||||
|
||||
activeServers := make([]m.HeartBeat, 0)
|
||||
err = x.Where("server_id = ? and updated > ", query.ServerId, now.String()).OrderBy("id").Find(&activeServers)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for i, pos := range activeServers {
|
||||
if pos.ServerId == query.ServerId {
|
||||
query.Result = &m.AlertingClusterInfo{
|
||||
ClusterSize: len(activeServers),
|
||||
UptimePosition: i,
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
}
|
||||
*/
|
||||
|
||||
func GetAlertById(query *m.GetAlertByIdQuery) error {
|
||||
alert := m.AlertRule{}
|
||||
has, err := x.Id(query.Id).Get(&alert)
|
||||
|
Loading…
Reference in New Issue
Block a user