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
48cbeb96
Commit
48cbeb96
authored
Jun 10, 2016
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(alerting): updated rule model and UI
parent
fdf051ad
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
91 additions
and
68 deletions
+91
-68
public/app/plugins/panel/graph/alert_tab_ctrl.ts
+74
-53
public/app/plugins/panel/graph/partials/tab_alerting.html
+17
-15
No files found.
public/app/plugins/panel/graph/alert_tab_ctrl.ts
View file @
48cbeb96
...
@@ -15,7 +15,6 @@ var alertQueryDef = new QueryPartDef({
...
@@ -15,7 +15,6 @@ var alertQueryDef = new QueryPartDef({
{
name
:
"queryRefId"
,
type
:
'string'
,
options
:
[
'#A'
,
'#B'
,
'#C'
,
'#D'
]},
{
name
:
"queryRefId"
,
type
:
'string'
,
options
:
[
'#A'
,
'#B'
,
'#C'
,
'#D'
]},
{
name
:
"from"
,
type
:
"string"
,
options
:
[
'1s'
,
'10s'
,
'1m'
,
'5m'
,
'10m'
,
'15m'
,
'1h'
]},
{
name
:
"from"
,
type
:
"string"
,
options
:
[
'1s'
,
'10s'
,
'1m'
,
'5m'
,
'10m'
,
'15m'
,
'1h'
]},
{
name
:
"to"
,
type
:
"string"
,
options
:
[
'now'
]},
{
name
:
"to"
,
type
:
"string"
,
options
:
[
'now'
]},
{
name
:
"aggregation"
,
type
:
"select"
,
options
:
[
'sum'
,
'avg'
,
'min'
,
'max'
,
'last'
]},
],
],
defaultParams
:
[
'#A'
,
'5m'
,
'now'
,
'avg'
]
defaultParams
:
[
'#A'
,
'5m'
,
'now'
,
'avg'
]
});
});
...
@@ -25,46 +24,44 @@ export class AlertTabCtrl {
...
@@ -25,46 +24,44 @@ export class AlertTabCtrl {
panelCtrl
:
any
;
panelCtrl
:
any
;
alerting
:
any
;
alerting
:
any
;
metricTargets
=
[{
refId
:
'- select query -'
}
];
metricTargets
=
[{
refId
:
'- select query -'
}
];
evalFunc
s
=
[
transform
s
=
[
{
{
text
:
'
Static Threshold
'
,
text
:
'
Aggregation
'
,
value
:
'static
'
,
type
:
'aggregation
'
,
},
},
{
{
text
:
'Percent Change Compared To'
,
text
:
'Linear Forecast'
,
value
:
'percent_change'
,
type
:
'forecast'
,
secondParam
:
"query"
,
},
},
{
{
text
:
'Forcast'
,
text
:
'Percent Change'
,
value
:
'forcast'
,
type
:
'percent_change'
,
secondParam
:
"duration"
,
},
}
{
text
:
'Query diff'
,
type
:
'query_diff'
,
},
];
];
aggregators
=
[
'avg'
,
'sum'
,
'min'
,
'max'
,
'
median
'
];
aggregators
=
[
'avg'
,
'sum'
,
'min'
,
'max'
,
'
last
'
];
rule
:
any
;
rule
:
any
;
valueQuery
:
any
;
query
:
any
;
evalQuery
:
any
;
queryParams
:
any
;
secondParam
:
any
;
transformDef
:
any
;
trasnformQuery
:
any
;
defaultValues
=
{
defaultValues
=
{
frequency
:
10
,
frequency
:
10
,
warning
:
{
op
:
'>'
,
level
:
10
},
warning
:
{
op
:
'>'
,
level
:
undefined
},
critical
:
{
op
:
'>'
,
level
:
20
},
critical
:
{
op
:
'>'
,
level
:
undefined
},
function
:
'static'
,
query
:
{
valueQuery
:
{
refId
:
'A'
,
queryRefId
:
'A'
,
from
:
'5m'
,
from
:
'5m'
,
to
:
'now'
,
to
:
'now'
,
agg
:
'avg'
,
},
},
evalQuery
:
{
transform
:
{
queryRefId
:
'A'
,
type
:
'aggregation'
,
from
:
'5m'
,
method
:
'avg'
,
to
:
'now'
,
agg
:
'avg'
,
},
},
evalStringParam1
:
''
,
};
};
/** @ngInject */
/** @ngInject */
...
@@ -73,53 +70,77 @@ export class AlertTabCtrl {
...
@@ -73,53 +70,77 @@ export class AlertTabCtrl {
this
.
panel
=
this
.
panelCtrl
.
panel
;
this
.
panel
=
this
.
panelCtrl
.
panel
;
$scope
.
ctrl
=
this
;
$scope
.
ctrl
=
this
;
_
.
defaults
(
this
.
panel
.
alerting
,
this
.
defaultValues
);
this
.
metricTargets
=
this
.
panel
.
targets
.
map
(
val
=>
val
);
this
.
rule
=
this
.
panel
.
alerting
;
this
.
rule
=
this
.
panel
.
alerting
=
this
.
panel
.
alerting
||
{}
;
this
.
valueQuery
=
new
QueryPart
(
this
.
rule
.
valueQuery
,
alertQueryDef
);
// set defaults
this
.
evalQuery
=
new
QueryPart
(
this
.
rule
.
evalQuery
,
alertQueryDef
);
_
.
defaults
(
this
.
rule
,
this
.
defaultValues
);
var
defaultName
=
(
this
.
panelCtrl
.
dashboard
.
title
+
' '
+
this
.
panel
.
title
+
' alert'
);
var
defaultName
=
(
this
.
panelCtrl
.
dashboard
.
title
+
' '
+
this
.
panel
.
title
+
' alert'
);
this
.
panel
.
alerting
.
name
=
this
.
panel
.
alerting
.
name
||
defaultName
;
this
.
rule
.
name
=
this
.
rule
.
name
||
defaultName
;
this
.
panel
.
alerting
.
description
=
this
.
panel
.
alerting
.
description
||
defaultName
;
this
.
rule
.
description
=
this
.
rule
.
description
||
defaultName
;
this
.
rule
.
queryRef
=
this
.
panel
.
alerting
.
queryRef
||
this
.
metricTargets
[
0
].
refId
;
this
.
panel
.
targets
.
map
(
target
=>
{
this
.
metricTargets
.
push
(
target
);
// great temp working model
});
this
.
queryParams
=
{
params
:
[
this
.
panel
.
alerting
.
queryRef
=
this
.
panel
.
alerting
.
queryRef
||
this
.
metricTargets
[
0
].
refId
;
this
.
rule
.
query
.
refId
,
this
.
rule
.
query
.
from
,
this
.
rule
.
query
.
to
]
};
// init the query part components model
this
.
query
=
new
QueryPart
(
this
.
queryParams
,
alertQueryDef
);
this
.
convertThresholdsToAlertThresholds
();
this
.
convertThresholdsToAlertThresholds
();
this
.
evalFuncChanged
();
this
.
transformDef
=
_
.
findWhere
(
this
.
transforms
,
{
type
:
this
.
rule
.
transform
.
type
});
}
queryUpdated
()
{
this
.
rule
.
query
=
{
refId
:
this
.
query
.
params
[
0
],
from
:
this
.
query
.
params
[
1
],
to
:
this
.
query
.
params
[
2
],
};
}
}
evalFuncChanged
()
{
transformChanged
()
{
var
evalFuncDef
=
_
.
findWhere
(
this
.
evalFuncs
,
{
value
:
this
.
rule
.
evalFunc
});
// clear model
console
.
log
(
evalFuncDef
);
this
.
rule
.
transform
=
{
type
:
this
.
rule
.
transform
.
type
};
this
.
secondParam
=
evalFuncDef
.
secondParam
;
this
.
transformDef
=
_
.
findWhere
(
this
.
transforms
,
{
type
:
this
.
rule
.
transform
.
type
});
switch
(
this
.
rule
.
transform
.
type
)
{
case
'aggregation'
:
{
this
.
rule
.
transform
.
method
=
'avg'
;
break
;
}
case
"forecast"
:
{
this
.
rule
.
transform
.
timespan
=
'7d'
;
break
;
}
}
}
}
convertThresholdsToAlertThresholds
()
{
convertThresholdsToAlertThresholds
()
{
if
(
this
.
panel
.
grid
if
(
this
.
panel
.
grid
&&
this
.
panel
.
grid
.
threshold1
&&
this
.
panel
.
grid
.
threshold1
&&
this
.
panel
.
alerting
.
warnLevel
===
undefined
&&
this
.
rule
.
warnLevel
===
undefined
)
{
)
{
this
.
panel
.
alerting
.
warnOperator
=
'>'
;
this
.
rule
.
warning
.
op
=
'>'
;
this
.
panel
.
alerting
.
warnL
evel
=
this
.
panel
.
grid
.
threshold1
;
this
.
rule
.
warning
.
l
evel
=
this
.
panel
.
grid
.
threshold1
;
}
}
if
(
this
.
panel
.
grid
if
(
this
.
panel
.
grid
&&
this
.
panel
.
grid
.
threshold2
&&
this
.
panel
.
grid
.
threshold2
&&
this
.
panel
.
alerting
.
critL
evel
===
undefined
&&
this
.
rule
.
critical
.
l
evel
===
undefined
)
{
)
{
this
.
panel
.
alerting
.
critOperator
=
'>'
;
this
.
rule
.
critical
.
op
=
'>'
;
this
.
panel
.
alerting
.
critL
evel
=
this
.
panel
.
grid
.
threshold2
;
this
.
rule
.
critical
.
l
evel
=
this
.
panel
.
grid
.
threshold2
;
}
}
}
}
markAsDeleted
()
{
markAsDeleted
()
{
if
(
this
.
panel
.
alerting
)
{
this
.
panel
.
alerting
=
this
.
defaultValues
;
this
.
panel
.
alerting
=
this
.
defaultValues
;
}
}
}
thresholdsUpdated
()
{
thresholdsUpdated
()
{
...
...
public/app/plugins/panel/graph/partials/tab_alerting.html
View file @
48cbeb96
...
@@ -6,32 +6,34 @@
...
@@ -6,32 +6,34 @@
<query-part-editor
<query-part-editor
class=
"gf-form-label query-part"
class=
"gf-form-label query-part"
part=
"ctrl.
valueQ
uery"
part=
"ctrl.
q
uery"
part-updated=
"ctrl.
valueQ
ueryUpdated()"
>
part-updated=
"ctrl.
q
ueryUpdated()"
>
</query-part-editor>
</query-part-editor>
</div>
</div>
<div
class=
"gf-form"
>
<div
class=
"gf-form"
>
<span
class=
"gf-form-label"
>
Evaluate Against
</span>
<span
class=
"gf-form-label"
>
Transform using
</span>
<div
class=
"gf-form-select-wrapper"
>
<div
class=
"gf-form-select-wrapper"
>
<select
class=
"gf-form-input"
<select
class=
"gf-form-input"
ng-model=
"ctrl.rule.
evalFunc
"
ng-model=
"ctrl.rule.
transform.type
"
ng-options=
"f.
value as f.text for f in ctrl.evalFunc
s"
ng-options=
"f.
type as f.text for f in ctrl.transform
s"
ng-change=
"ctrl.
evalFunc
Changed()"
ng-change=
"ctrl.
transform
Changed()"
>
>
</select>
</select>
</div>
</div>
</div>
</div>
<div
class=
"gf-form"
ng-if=
"ctrl.secondParam === 'query'"
>
<div
class=
"gf-form"
ng-if=
"ctrl.transformDef.type === 'aggregation'"
>
<query-part-editor
<span
class=
"gf-form-label"
>
Method
</span>
class=
"gf-form-label query-part"
<div
class=
"gf-form-select-wrapper"
>
part=
"ctrl.evalQuery"
<select
class=
"gf-form-input"
part-updated=
"ctrl.evalQueryUpdated()"
>
ng-model=
"ctrl.rule.transform.method"
</query-part-editor>
ng-options=
"f for f in ctrl.aggregators"
>
</select>
</div>
</div>
</div>
<div
class=
"gf-form"
ng-if=
"ctrl.
secondParam === 'duration
'"
>
<div
class=
"gf-form"
ng-if=
"ctrl.
transformDef.type === 'forecast
'"
>
<span
class=
"gf-form-label"
>
Duratio
n
</span>
<span
class=
"gf-form-label"
>
Timespa
n
</span>
<input
class=
"gf-form-input max-width-7"
type=
"text"
ng-model=
"ctrl.rule.
evalStringParam1
"
ng-change=
"ctrl.ruleUpdated()"
></input>
<input
class=
"gf-form-input max-width-7"
type=
"text"
ng-model=
"ctrl.rule.
transform.timespan
"
ng-change=
"ctrl.ruleUpdated()"
></input>
</div>
</div>
</div>
</div>
</div>
</div>
...
...
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