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
422234d0
Commit
422234d0
authored
May 27, 2016
by
bergquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(alerting): abstract graphite from executor
parent
3d66ec81
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
35 additions
and
23 deletions
+35
-23
pkg/models/timeseries.go
+1
-1
pkg/services/alerting/alerting.go
+1
-1
pkg/services/alerting/dummie_executor.go
+0
-4
pkg/services/alerting/executor.go
+20
-3
pkg/services/alerting/graphite/graphite.go
+13
-14
No files found.
pkg/
services/alerting/typ
es.go
→
pkg/
models/timeseri
es.go
View file @
422234d0
package
alerting
package
models
type
TimeSeries
struct
{
Name
string
`json:"name"`
...
...
pkg/services/alerting/alerting.go
View file @
422234d0
...
...
@@ -21,7 +21,7 @@ func Init() {
scheduler
:=
NewScheduler
()
go
scheduler
.
Dispatch
(
&
AlertRuleReader
{})
go
scheduler
.
Executor
(
&
GraphiteExecutor
{})
go
scheduler
.
Executor
(
&
ExecutorImpl
{})
go
scheduler
.
HandleResponses
()
}
...
...
pkg/services/alerting/dummie_executor.go
View file @
422234d0
...
...
@@ -6,10 +6,6 @@ import (
"time"
)
type
Executor
interface
{
Execute
(
rule
m
.
AlertRule
,
responseQueue
chan
*
AlertResult
)
}
type
DummieExecutor
struct
{}
func
(
this
*
DummieExecutor
)
Execute
(
rule
m
.
AlertRule
,
responseQueue
chan
*
AlertResult
)
{
...
...
pkg/services/alerting/
rule_
executor.go
→
pkg/services/alerting/executor.go
View file @
422234d0
...
...
@@ -2,17 +2,34 @@ package alerting
import
(
m
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/alerting/graphite"
)
func
(
this
*
GraphiteExecutor
)
executeRules
(
series
[]
GraphiteSerie
,
rule
m
.
AlertRule
)
*
AlertResult
{
type
Executor
interface
{
Execute
(
rule
m
.
AlertRule
,
responseQueue
chan
*
AlertResult
)
}
type
ExecutorImpl
struct
{}
func
(
this
*
ExecutorImpl
)
Execute
(
rule
m
.
AlertRule
,
responseQueue
chan
*
AlertResult
)
{
response
,
err
:=
graphite
.
GraphiteClient
{}
.
GetSeries
(
rule
)
if
err
!=
nil
{
responseQueue
<-
&
AlertResult
{
State
:
"CRITICAL"
,
Id
:
rule
.
Id
}
}
responseQueue
<-
this
.
executeRules
(
response
,
rule
)
}
func
(
this
*
ExecutorImpl
)
executeRules
(
series
m
.
TimeSeriesSlice
,
rule
m
.
AlertRule
)
*
AlertResult
{
for
_
,
v
:=
range
series
{
var
avg
float64
var
sum
float64
for
_
,
dp
:=
range
v
.
Datap
oints
{
for
_
,
dp
:=
range
v
.
P
oints
{
sum
+=
dp
[
0
]
}
avg
=
sum
/
float64
(
len
(
v
.
Datap
oints
))
avg
=
sum
/
float64
(
len
(
v
.
P
oints
))
if
float64
(
rule
.
CritLevel
)
<
avg
{
return
&
AlertResult
{
State
:
m
.
AlertStateCritical
,
Id
:
rule
.
Id
,
ActualValue
:
avg
}
...
...
pkg/services/alerting/graphite
_executor
.go
→
pkg/services/alerting/graphite
/graphite
.go
View file @
422234d0
package
alerting
package
graphite
import
(
"fmt"
...
...
@@ -11,7 +11,7 @@ import (
"time"
)
type
Graphite
Executor
struct
{}
type
Graphite
Client
struct
{}
type
GraphiteSerie
struct
{
Datapoints
[][
2
]
float64
...
...
@@ -20,17 +20,7 @@ type GraphiteSerie struct {
type
GraphiteResponse
[]
GraphiteSerie
func
(
this
*
GraphiteExecutor
)
Execute
(
rule
m
.
AlertRule
,
responseQueue
chan
*
AlertResult
)
{
response
,
err
:=
this
.
getSeries
(
rule
)
if
err
!=
nil
{
responseQueue
<-
&
AlertResult
{
State
:
"CRITICAL"
,
Id
:
rule
.
Id
}
}
responseQueue
<-
this
.
executeRules
(
response
,
rule
)
}
func
(
this
*
GraphiteExecutor
)
getSeries
(
rule
m
.
AlertRule
)
(
GraphiteResponse
,
error
)
{
func
(
this
GraphiteClient
)
GetSeries
(
rule
m
.
AlertRule
)
(
m
.
TimeSeriesSlice
,
error
)
{
query
:=
&
m
.
GetDataSourceByIdQuery
{
Id
:
rule
.
DatasourceId
,
OrgId
:
rule
.
OrgId
}
if
err
:=
bus
.
Dispatch
(
query
);
err
!=
nil
{
return
nil
,
err
...
...
@@ -61,7 +51,16 @@ func (this *GraphiteExecutor) getSeries(rule m.AlertRule) (GraphiteResponse, err
return
nil
,
fmt
.
Errorf
(
"error!"
)
}
return
response
,
nil
timeSeries
:=
make
([]
*
m
.
TimeSeries
,
0
)
for
_
,
v
:=
range
response
{
timeSeries
=
append
(
timeSeries
,
&
m
.
TimeSeries
{
Name
:
v
.
Target
,
Points
:
v
.
Datapoints
,
})
}
return
timeSeries
,
nil
}
func
getTargetFromRule
(
rule
m
.
AlertRule
)
string
{
...
...
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