Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
a1f97e0b
Commit
a1f97e0b
authored
Jun 09, 2016
by
bergquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(alerting): add heartbeat writer
parent
a6602783
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
0 deletions
+51
-0
pkg/models/alerts.go
+7
-0
pkg/services/sqlstore/alert_rule.go
+44
-0
No files found.
pkg/models/alerts.go
View file @
a1f97e0b
...
...
@@ -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
...
...
pkg/services/sqlstore/alert_rule.go
View file @
a1f97e0b
...
...
@@ -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
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment