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
c133a001
Commit
c133a001
authored
May 17, 2016
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(alerting): minor progress on scheduler
parent
fa19e0d9
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
116 additions
and
34 deletions
+116
-34
pkg/api/alerting/alerting.go
+0
-34
pkg/cmd/grafana-server/main.go
+2
-0
pkg/services/alerting/alerting.go
+114
-0
No files found.
pkg/api/alerting/alerting.go
deleted
100644 → 0
View file @
fa19e0d9
package
alerting
import
(
"time"
m
"github.com/grafana/grafana/pkg/models"
)
func
Init
()
{
go
dispatcher
()
}
func
dispatcher
()
{
ticker
:=
time
.
NewTicker
(
time
.
Second
)
for
{
select
{
case
<-
ticker
.
C
:
scheduleJobs
()
}
}
}
func
scheduleJobs
()
{
}
type
Scheduler
interface
{
}
type
Executor
interface
{
Execute
(
rule
*
m
.
AlertRule
)
}
pkg/cmd/grafana-server/main.go
View file @
c133a001
...
@@ -16,6 +16,7 @@ import (
...
@@ -16,6 +16,7 @@ import (
"github.com/grafana/grafana/pkg/login"
"github.com/grafana/grafana/pkg/login"
"github.com/grafana/grafana/pkg/metrics"
"github.com/grafana/grafana/pkg/metrics"
"github.com/grafana/grafana/pkg/plugins"
"github.com/grafana/grafana/pkg/plugins"
"github.com/grafana/grafana/pkg/services/alerting"
"github.com/grafana/grafana/pkg/services/eventpublisher"
"github.com/grafana/grafana/pkg/services/eventpublisher"
"github.com/grafana/grafana/pkg/services/notifications"
"github.com/grafana/grafana/pkg/services/notifications"
"github.com/grafana/grafana/pkg/services/search"
"github.com/grafana/grafana/pkg/services/search"
...
@@ -64,6 +65,7 @@ func main() {
...
@@ -64,6 +65,7 @@ func main() {
social
.
NewOAuthService
()
social
.
NewOAuthService
()
eventpublisher
.
Init
()
eventpublisher
.
Init
()
plugins
.
Init
()
plugins
.
Init
()
alerting
.
Init
()
if
err
:=
notifications
.
Init
();
err
!=
nil
{
if
err
:=
notifications
.
Init
();
err
!=
nil
{
log
.
Fatal
(
3
,
"Notification service failed to initialize"
,
err
)
log
.
Fatal
(
3
,
"Notification service failed to initialize"
,
err
)
...
...
pkg/services/alerting/alerting.go
0 → 100644
View file @
c133a001
package
alerting
import
(
"time"
"github.com/grafana/grafana/pkg/log"
m
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/setting"
)
func
Init
()
{
if
!
setting
.
AlertingEnabled
{
return
}
log
.
Info
(
"Alerting: Initializing scheduler..."
)
scheduler
:=
NewScheduler
()
go
scheduler
.
Dispatch
()
go
scheduler
.
Executor
()
}
type
Scheduler
struct
{
jobs
[]
*
AlertJob
runQueue
chan
*
AlertJob
}
func
NewScheduler
()
*
Scheduler
{
return
&
Scheduler
{
jobs
:
make
([]
*
AlertJob
,
0
),
runQueue
:
make
(
chan
*
AlertJob
,
1000
),
}
}
func
(
s
*
Scheduler
)
Dispatch
()
{
reschedule
:=
time
.
NewTicker
(
time
.
Second
*
10
)
secondTicker
:=
time
.
NewTicker
(
time
.
Second
)
s
.
updateJobs
()
for
{
select
{
case
<-
secondTicker
.
C
:
s
.
queueJobs
()
case
<-
reschedule
.
C
:
s
.
updateJobs
()
}
}
}
func
(
s
*
Scheduler
)
updateJobs
()
{
log
.
Info
(
"Scheduler:updateJobs()"
)
jobs
:=
make
([]
*
AlertJob
,
0
)
jobs
=
append
(
jobs
,
&
AlertJob
{
name
:
"ID_1_Each 10s"
,
frequency
:
10
,
offset
:
1
,
})
jobs
=
append
(
jobs
,
&
AlertJob
{
name
:
"ID_2_Each 10s"
,
frequency
:
10
,
offset
:
2
,
})
jobs
=
append
(
jobs
,
&
AlertJob
{
name
:
"ID_3_Each 10s"
,
frequency
:
10
,
offset
:
3
,
})
jobs
=
append
(
jobs
,
&
AlertJob
{
name
:
"ID_4_Each 5s"
,
frequency
:
5
,
})
s
.
jobs
=
jobs
}
func
(
s
*
Scheduler
)
queueJobs
()
{
log
.
Info
(
"Scheduler:queueJobs()"
)
now
:=
time
.
Now
()
.
Unix
()
for
_
,
job
:=
range
s
.
jobs
{
if
now
%
job
.
frequency
==
0
{
log
.
Info
(
"Scheduler: Putting job on to run queue: %s"
,
job
.
name
)
s
.
runQueue
<-
job
}
}
}
func
(
s
*
Scheduler
)
Executor
()
{
for
job
:=
range
s
.
runQueue
{
log
.
Info
(
"Executor: queue length %d"
,
len
(
s
.
runQueue
))
log
.
Info
(
"Executor: executing %s"
,
job
.
name
)
time
.
Sleep
(
1000
)
}
}
type
AlertJob
struct
{
id
int64
name
string
frequency
int64
offset
int64
delay
bool
}
type
RuleReader
interface
{
}
type
Executor
interface
{
Execute
(
rule
*
m
.
AlertRule
)
}
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