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
7d2b9894
Commit
7d2b9894
authored
Sep 29, 2017
by
Carl Bergquist
Committed by
GitHub
Sep 29, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #9386 from shanhuhai5739/master
add diff and pdiff for conditions
parents
992cc1b6
68ed4d45
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
60 additions
and
0 deletions
+60
-0
pkg/services/alerting/conditions/reducer.go
+47
-0
pkg/services/alerting/conditions/reducer_test.go
+11
-0
public/app/features/alerting/alert_def.ts
+2
-0
No files found.
pkg/services/alerting/conditions/reducer.go
View file @
7d2b9894
...
...
@@ -94,6 +94,53 @@ func (s *SimpleReducer) Reduce(series *tsdb.TimeSeries) null.Float {
value
=
(
values
[(
length
/
2
)
-
1
]
+
values
[
length
/
2
])
/
2
}
}
case
"diff"
:
var
(
points
=
series
.
Points
first
float64
i
int
)
// get the newest point
for
i
=
len
(
points
)
-
1
;
i
>=
0
;
i
--
{
if
points
[
i
][
0
]
.
Valid
{
allNull
=
false
first
=
points
[
i
][
0
]
.
Float64
break
}
}
// get other points
points
=
points
[
0
:
i
]
for
i
:=
len
(
points
)
-
1
;
i
>=
0
;
i
--
{
if
points
[
i
][
0
]
.
Valid
{
allNull
=
false
value
=
first
-
points
[
i
][
0
]
.
Float64
break
}
}
case
"percent_diff"
:
var
(
points
=
series
.
Points
first
float64
i
int
)
// get the newest point
for
i
=
len
(
points
)
-
1
;
i
>=
0
;
i
--
{
if
points
[
i
][
0
]
.
Valid
{
allNull
=
false
first
=
points
[
i
][
0
]
.
Float64
break
}
}
// get other points
points
=
points
[
0
:
i
]
for
i
:=
len
(
points
)
-
1
;
i
>=
0
;
i
--
{
if
points
[
i
][
0
]
.
Valid
{
allNull
=
false
val
:=
(
first
-
points
[
i
][
0
]
.
Float64
)
/
points
[
i
][
0
]
.
Float64
*
100
value
=
math
.
Abs
(
val
)
break
}
}
}
if
allNull
{
...
...
pkg/services/alerting/conditions/reducer_test.go
View file @
7d2b9894
...
...
@@ -80,6 +80,17 @@ func TestSimpleReducer(t *testing.T) {
So
(
reducer
.
Reduce
(
series
)
.
Float64
,
ShouldEqual
,
float64
(
3
))
})
Convey
(
"diff"
,
func
()
{
result
:=
testReducer
(
"diff"
,
30
,
40
)
So
(
result
,
ShouldEqual
,
float64
(
10
))
})
Convey
(
"percent_diff"
,
func
()
{
result
:=
testReducer
(
"percent_diff"
,
30
,
40
)
So
(
result
,
ShouldEqual
,
float64
(
33.33333333333333
))
})
})
}
...
...
public/app/features/alerting/alert_def.ts
View file @
7d2b9894
...
...
@@ -49,6 +49,8 @@ var reducerTypes = [
{
text
:
'count()'
,
value
:
'count'
},
{
text
:
'last()'
,
value
:
'last'
},
{
text
:
'median()'
,
value
:
'median'
},
{
text
:
'diff()'
,
value
:
'diff'
},
{
text
:
'percent_diff()'
,
value
:
'percent_diff'
},
];
var
noDataModes
=
[
...
...
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