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
69229211
Commit
69229211
authored
Jun 01, 2016
by
bergquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(alerting): move backend to seperate file
parent
4e1f801f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
13 deletions
+30
-13
pkg/services/alerting/datasources/backends.go
+14
-0
pkg/services/alerting/datasources/graphite.go
+0
-0
pkg/services/alerting/executor.go
+16
-13
No files found.
pkg/services/alerting/datasources/backends.go
0 → 100644
View file @
69229211
package
graphite
import
(
"fmt"
m
"github.com/grafana/grafana/pkg/models"
)
func
GetSeries
(
job
*
m
.
AlertJob
)
(
m
.
TimeSeriesSlice
,
error
)
{
if
job
.
Datasource
.
Type
==
m
.
DS_GRAPHITE
{
return
GraphiteClient
{}
.
GetSeries
(
job
)
}
return
nil
,
fmt
.
Errorf
(
"Grafana does not support alerts for %s"
,
job
.
Datasource
.
Type
)
}
pkg/services/alerting/
graphite
/graphite.go
→
pkg/services/alerting/
datasources
/graphite.go
View file @
69229211
File moved
pkg/services/alerting/executor.go
View file @
69229211
...
...
@@ -2,8 +2,10 @@ package alerting
import
(
"fmt"
"github.com/grafana/grafana/pkg/log"
m
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/alerting/graphite
"
b
"github.com/grafana/grafana/pkg/services/alerting/datasources
"
"math"
)
...
...
@@ -11,6 +13,10 @@ type Executor interface {
Execute
(
rule
*
m
.
AlertJob
,
responseQueue
chan
*
m
.
AlertResult
)
}
var
(
ResultLogFmt
=
"%s executor: %s %1.2f %s %1.2f : %v"
)
type
ExecutorImpl
struct
{}
type
compareFn
func
(
float64
,
float64
)
bool
...
...
@@ -23,7 +29,6 @@ var operators map[string]compareFn = map[string]compareFn{
"<="
:
func
(
num1
,
num2
float64
)
bool
{
return
num1
<=
num2
},
""
:
func
(
num1
,
num2
float64
)
bool
{
return
false
},
}
var
aggregator
map
[
string
]
aggregationFn
=
map
[
string
]
aggregationFn
{
"avg"
:
func
(
series
*
m
.
TimeSeries
)
float64
{
sum
:=
float64
(
0
)
...
...
@@ -71,16 +76,8 @@ var aggregator map[string]aggregationFn = map[string]aggregationFn{
},
}
func
(
this
*
ExecutorImpl
)
GetSeries
(
job
*
m
.
AlertJob
)
(
m
.
TimeSeriesSlice
,
error
)
{
if
job
.
Datasource
.
Type
==
m
.
DS_GRAPHITE
{
return
graphite
.
GraphiteClient
{}
.
GetSeries
(
job
)
}
return
nil
,
fmt
.
Errorf
(
"Grafana does not support alerts for %s"
,
job
.
Datasource
.
Type
)
}
func
(
this
*
ExecutorImpl
)
Execute
(
job
*
m
.
AlertJob
,
responseQueue
chan
*
m
.
AlertResult
)
{
response
,
err
:=
this
.
GetSeries
(
job
)
response
,
err
:=
b
.
GetSeries
(
job
)
if
err
!=
nil
{
responseQueue
<-
&
m
.
AlertResult
{
State
:
"PENDING"
,
Id
:
job
.
Rule
.
Id
,
Rule
:
job
.
Rule
}
...
...
@@ -96,8 +93,11 @@ func (this *ExecutorImpl) ValidateRule(rule m.AlertRule, series m.TimeSeriesSlic
}
var
aggValue
=
aggregator
[
rule
.
Aggregator
](
serie
)
var
critOperartor
=
operators
[
rule
.
CritOperator
]
var
critResult
=
critOperartor
(
aggValue
,
rule
.
CritLevel
)
if
operators
[
rule
.
CritOperator
](
aggValue
,
rule
.
CritLevel
)
{
log
.
Debug
(
ResultLogFmt
,
"Crit"
,
serie
.
Name
,
aggValue
,
rule
.
CritOperator
,
rule
.
CritLevel
,
critResult
)
if
critResult
{
return
&
m
.
AlertResult
{
State
:
m
.
AlertStateCritical
,
Id
:
rule
.
Id
,
...
...
@@ -107,7 +107,10 @@ func (this *ExecutorImpl) ValidateRule(rule m.AlertRule, series m.TimeSeriesSlic
}
}
if
operators
[
rule
.
WarnOperator
](
aggValue
,
rule
.
WarnLevel
)
{
var
warnOperartor
=
operators
[
rule
.
CritOperator
]
var
warnResult
=
warnOperartor
(
aggValue
,
rule
.
CritLevel
)
log
.
Debug
(
ResultLogFmt
,
"Warn"
,
serie
.
Name
,
aggValue
,
rule
.
WarnOperator
,
rule
.
WarnLevel
,
warnResult
)
if
warnResult
{
return
&
m
.
AlertResult
{
State
:
m
.
AlertStateWarn
,
Id
:
rule
.
Id
,
...
...
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