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
41156835
Commit
41156835
authored
May 30, 2016
by
bergquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(alerting): revert operand positions
parent
077be210
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
47 additions
and
34 deletions
+47
-34
pkg/services/alerting/alert_rule_reader.go
+31
-20
pkg/services/alerting/executor.go
+4
-2
pkg/services/alerting/executor_test.go
+6
-6
public/app/plugins/panel/graph/partials/tab_alerting.html
+6
-6
No files found.
pkg/services/alerting/alert_rule_reader.go
View file @
41156835
package
alerting
import
(
"github.com/grafana/grafana/pkg/bus"
m
"github.com/grafana/grafana/pkg/models"
)
...
...
@@ -11,25 +12,35 @@ type RuleReader interface {
type
AlertRuleReader
struct
{}
func
(
this
AlertRuleReader
)
Fetch
()
[]
m
.
AlertRule
{
return
[]
m
.
AlertRule
{
//{Id: 1, Title: "alert rule 1", Interval: "10s", Frequency: 10},
//{Id: 2, Title: "alert rule 2", Interval: "10s", Frequency: 10},
//{Id: 3, Title: "alert rule 3", Interval: "10s", Frequency: 10},
//{Id: 4, Title: "alert rule 4", Interval: "10s", Frequency: 5},
//{Id: 5, Title: "alert rule 5", Interval: "10s", Frequency: 5},
{
Id
:
1
,
OrgId
:
1
,
Title
:
"alert rule 1"
,
Frequency
:
3
,
DatasourceId
:
1
,
WarnOperator
:
"<"
,
WarnLevel
:
3
,
CritOperator
:
"<"
,
CritLevel
:
4
,
Aggregator
:
"avg"
,
Query
:
`{"refId":"A","target":"statsd.fakesite.counters.session_start.*.count","textEditor":true}"`
,
QueryRange
:
3600
,
},
/*
return []m.AlertRule{
//{Id: 1, Title: "alert rule 1", Interval: "10s", Frequency: 10},
//{Id: 2, Title: "alert rule 2", Interval: "10s", Frequency: 10},
//{Id: 3, Title: "alert rule 3", Interval: "10s", Frequency: 10},
//{Id: 4, Title: "alert rule 4", Interval: "10s", Frequency: 5},
//{Id: 5, Title: "alert rule 5", Interval: "10s", Frequency: 5},
{
Id: 1,
OrgId: 1,
Title: "alert rule 1",
Frequency: 3,
DatasourceId: 1,
WarnOperator: "<",
WarnLevel: 3,
CritOperator: "<",
CritLevel: 4,
Aggregator: "avg",
Query: `{"refId":"A","target":"statsd.fakesite.counters.session_start.*.count","textEditor":true}"`,
QueryRange: 3600,
},
}
*/
cmd
:=
&
m
.
GetAlertsQuery
{
OrgId
:
1
,
}
bus
.
Dispatch
(
cmd
)
return
cmd
.
Result
}
pkg/services/alerting/executor.go
View file @
41156835
...
...
@@ -48,11 +48,13 @@ func (this *ExecutorImpl) ValidateRule(rule m.AlertRule, series m.TimeSeriesSlic
var
aggValue
=
aggregator
[
rule
.
Aggregator
](
serie
)
if
operators
[
rule
.
CritOperator
](
float64
(
rule
.
CritLevel
),
aggValue
)
{
//if operators[rule.CritOperator](float64(rule.CritLevel), aggValue) {
if
operators
[
rule
.
CritOperator
](
aggValue
,
float64
(
rule
.
CritLevel
))
{
return
&
AlertResult
{
State
:
m
.
AlertStateCritical
,
Id
:
rule
.
Id
,
ActualValue
:
aggValue
}
}
if
operators
[
rule
.
WarnOperator
](
float64
(
rule
.
WarnLevel
),
aggValue
)
{
//if operators[rule.WarnOperator](float64(rule.WarnLevel), aggValue) {
if
operators
[
rule
.
WarnOperator
](
aggValue
,
float64
(
rule
.
WarnLevel
))
{
return
&
AlertResult
{
State
:
m
.
AlertStateWarn
,
Id
:
rule
.
Id
,
ActualValue
:
aggValue
}
}
}
...
...
pkg/services/alerting/executor_test.go
View file @
41156835
...
...
@@ -11,7 +11,7 @@ func TestAlertingExecutor(t *testing.T) {
executor
:=
&
ExecutorImpl
{}
Convey
(
"Show return ok since avg is above 2"
,
func
()
{
rule
:=
m
.
AlertRule
{
CritLevel
:
10
,
CritOperator
:
"
<
"
,
Aggregator
:
"sum"
}
rule
:=
m
.
AlertRule
{
CritLevel
:
10
,
CritOperator
:
"
>
"
,
Aggregator
:
"sum"
}
timeSeries
:=
[]
*
m
.
TimeSeries
{
m
.
NewTimeSeries
(
"test1"
,
[][
2
]
float64
{{
2
,
0
}}),
...
...
@@ -22,7 +22,7 @@ func TestAlertingExecutor(t *testing.T) {
})
Convey
(
"Show return critical since below 2"
,
func
()
{
rule
:=
m
.
AlertRule
{
CritLevel
:
10
,
CritOperator
:
"
>
"
,
Aggregator
:
"sum"
}
rule
:=
m
.
AlertRule
{
CritLevel
:
10
,
CritOperator
:
"
<
"
,
Aggregator
:
"sum"
}
timeSeries
:=
[]
*
m
.
TimeSeries
{
m
.
NewTimeSeries
(
"test1"
,
[][
2
]
float64
{{
2
,
0
}}),
...
...
@@ -33,7 +33,7 @@ func TestAlertingExecutor(t *testing.T) {
})
Convey
(
"Show return critical since sum is above 10"
,
func
()
{
rule
:=
m
.
AlertRule
{
CritLevel
:
10
,
CritOperator
:
"
<
"
,
Aggregator
:
"sum"
}
rule
:=
m
.
AlertRule
{
CritLevel
:
10
,
CritOperator
:
"
>
"
,
Aggregator
:
"sum"
}
timeSeries
:=
[]
*
m
.
TimeSeries
{
m
.
NewTimeSeries
(
"test1"
,
[][
2
]
float64
{{
9
,
0
},
{
9
,
0
}}),
...
...
@@ -44,7 +44,7 @@ func TestAlertingExecutor(t *testing.T) {
})
Convey
(
"Show return ok since avg is below 10"
,
func
()
{
rule
:=
m
.
AlertRule
{
CritLevel
:
10
,
CritOperator
:
"
<
"
,
Aggregator
:
"avg"
}
rule
:=
m
.
AlertRule
{
CritLevel
:
10
,
CritOperator
:
"
>
"
,
Aggregator
:
"avg"
}
timeSeries
:=
[]
*
m
.
TimeSeries
{
m
.
NewTimeSeries
(
"test1"
,
[][
2
]
float64
{{
9
,
0
},
{
9
,
0
}}),
...
...
@@ -55,7 +55,7 @@ func TestAlertingExecutor(t *testing.T) {
})
Convey
(
"Show return ok since min is below 10"
,
func
()
{
rule
:=
m
.
AlertRule
{
CritLevel
:
10
,
CritOperator
:
"
<
"
,
Aggregator
:
"min"
}
rule
:=
m
.
AlertRule
{
CritLevel
:
10
,
CritOperator
:
"
>
"
,
Aggregator
:
"min"
}
timeSeries
:=
[]
*
m
.
TimeSeries
{
m
.
NewTimeSeries
(
"test1"
,
[][
2
]
float64
{{
11
,
0
},
{
9
,
0
}}),
...
...
@@ -66,7 +66,7 @@ func TestAlertingExecutor(t *testing.T) {
})
Convey
(
"Show return ok since max is above 10"
,
func
()
{
rule
:=
m
.
AlertRule
{
CritLevel
:
10
,
CritOperator
:
"
<
"
,
Aggregator
:
"max"
}
rule
:=
m
.
AlertRule
{
CritLevel
:
10
,
CritOperator
:
"
>
"
,
Aggregator
:
"max"
}
timeSeries
:=
[]
*
m
.
TimeSeries
{
m
.
NewTimeSeries
(
"test1"
,
[][
2
]
float64
{{
1
,
0
},
{
11
,
0
}}),
...
...
public/app/plugins/panel/graph/partials/tab_alerting.html
View file @
41156835
...
...
@@ -45,15 +45,15 @@
</div>
<div
class=
"gf-form"
>
<span
class=
"gf-form-label width-10"
>
Query range
</span>
<input
class=
"gf-form-input max-width-10"
type=
"
text
"
ng-model=
"ctrl.panel.alerting.queryRange"
placeholder=
"
10m
"
></input>
<span
class=
"gf-form-label width-10"
>
Query range
(seconds)
</span>
<input
class=
"gf-form-input max-width-10"
type=
"
number
"
ng-model=
"ctrl.panel.alerting.queryRange"
placeholder=
"
3600
"
></input>
</div>
<div
class=
"gf-form"
>
<span
class=
"gf-form-label width-10"
>
Interval
</span>
<input
class=
"gf-form-input max-width-10"
type=
"
text
"
ng-model=
"ctrl.panel.alerting.interval"
placeholder=
"
10s
"
></input>
<span
class=
"gf-form-label width-10"
>
Frequency (seconds)
</span>
<input
class=
"gf-form-input max-width-10"
type=
"
number
"
ng-model=
"ctrl.panel.alerting.interval"
placeholder=
"
60
"
></input>
</div>
</div>
<div
class=
"gf-form-group section"
>
...
...
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