Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
flame-clmc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
flame
flame-clmc
Commits
d638b408
Commit
d638b408
authored
6 years ago
by
Nikolay Stanchev
Browse files
Options
Downloads
Patches
Plain Diff
Updates relative template
parent
35880b56
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/service/clmcservice/alertsapi/utilities.py
+12
-9
12 additions, 9 deletions
src/service/clmcservice/alertsapi/utilities.py
src/service/resources/TICKscript/relative-template.tick
+12
-16
12 additions, 16 deletions
src/service/resources/TICKscript/relative-template.tick
with
24 additions
and
25 deletions
src/service/clmcservice/alertsapi/utilities.py
+
12
−
9
View file @
d638b408
...
...
@@ -137,7 +137,7 @@ class TICKScriptTemplateFiller:
# a class variable used to hold the comparison operator used to build the where clause in TICK script templates,
# these differ if the where clause is built as a string opposed to when it is build as a lambda
_TEMPLATE_COMPARISON_OPERATOR
=
{
"
threshold
"
:
"
=
"
,
"
relative
"
:
"
=
=
"
,
"
deadman
"
:
"
==
"
}
_TEMPLATE_COMPARISON_OPERATOR
=
{
"
threshold
"
:
"
=
"
,
"
relative
"
:
"
=
"
,
"
deadman
"
:
"
==
"
}
@staticmethod
def
get_comparison_operator
(
template_type
):
...
...
@@ -186,7 +186,7 @@ class TICKScriptTemplateFiller:
:return: a dictionary object ready to be posted to kapacitor to create a
"
threshold
"
task from template.
"""
comparison_lambda
=
"
\
"
real_value
\
"
{0} {1}
"
.
format
(
comparison_operator
,
critical_value
)
# build up lambda string, e.g. "real_value" >= 10
comparison_lambda
=
'
"
real_value
"
{0} {1}
'
.
format
(
comparison_operator
,
critical_value
)
# build up lambda string, e.g. "real_value" >= 10
template_vars
=
{
"
db
"
:
{
...
...
@@ -228,7 +228,7 @@ class TICKScriptTemplateFiller:
return
template_vars
@staticmethod
def
_fill_relative_template_vars
(
db
=
None
,
measurement
=
None
,
field
=
None
,
critical_value
=
None
,
comparison_operator
=
None
,
def
_fill_relative_template_vars
(
db
=
None
,
measurement
=
None
,
field
=
None
,
influx_function
=
None
,
critical_value
=
None
,
comparison_operator
=
None
,
alert_period
=
None
,
topic_id
=
None
,
where_clause
=
None
,
**
kwargs
):
"""
Creates a dictionary object ready to be posted to kapacitor to create a
"
relative
"
task from template.
...
...
@@ -236,6 +236,7 @@ class TICKScriptTemplateFiller:
:param db: db name
:param measurement: measurement name
:param field: field name
:param influx_function: influx function to use for querying
:param critical_value: critical value to compare with
:param comparison_operator: type of comparison
:param alert_period: alert period to use for relative comparison
...
...
@@ -245,8 +246,6 @@ class TICKScriptTemplateFiller:
:return: a dictionary object ready to be posted to kapacitor to create a
"
relative
"
task from template.
"""
select_lambda
=
'"
{0}
"'
.
format
(
field
)
comparison_lambda
=
'"
diff
"
{0} {1}
'
.
format
(
comparison_operator
,
critical_value
)
template_vars
=
{
...
...
@@ -258,9 +257,13 @@ class TICKScriptTemplateFiller:
"
type
"
:
"
string
"
,
"
value
"
:
measurement
},
"
selectLambda
"
:
{
"
type
"
:
"
lambda
"
,
"
value
"
:
select_lambda
"
field
"
:
{
"
type
"
:
"
string
"
,
"
value
"
:
field
},
"
influxFunction
"
:
{
"
type
"
:
"
string
"
,
"
value
"
:
influx_function
},
"
comparisonLambda
"
:
{
"
type
"
:
"
lambda
"
,
...
...
@@ -278,7 +281,7 @@ class TICKScriptTemplateFiller:
if
where_clause
is
not
None
:
template_vars
[
"
whereClause
"
]
=
{
"
type
"
:
"
lambda
"
,
"
type
"
:
"
string
"
,
"
value
"
:
where_clause
}
...
...
This diff is collapsed.
Click to expand it.
src/service/resources/TICKscript/relative-template.tick
+
12
−
16
View file @
d638b408
...
...
@@ -4,9 +4,11 @@ var rp = 'autogen' // default value for the retention policy
var measurement string
var
selectLambda lambda // must be a lambda specifying the field to select e.g. "requests"
var
field string
var whereClause = lambda: TRUE // default value is a function which returns TRUE, hence no filtering of the query result
var influxFunction string
var whereClause = 'TRUE' // default value is TRUE, hence no filtering of the query result
var messageValue = 'TRUE' // default value is TRUE, as this is what SFEMC expects as a notification for an event rule
...
...
@@ -17,25 +19,19 @@ var alertPeriod duration
var topicID string
var data = stream
| from()
.database(db)
.retentionPolicy(rp)
.measurement(measurement)
.where(whereClause)
| eval(selectLambda)
.as('value')
var past = data
| shift(alertPeriod)
var current = batch
|query('SELECT ' + influxFunction + '(' + field + ') AS value FROM "' + db + '"."' + rp + '"."' + measurement + '" WHERE ' + whereClause)
.period(alertPeriod)
.every(alertPeriod)
var current = data
var past = current
.offset(alertPeriod)
| shift(alertPeriod)
past
| join(current)
// NOTE: join buffers a given data point until a point with the correct timestamp to join on arrives
| join(current)
.as('past', 'current')
| eval(lambda: float("current.value" - "past.value"))
.keep()
.as('diff')
| alert()
.id(topicID)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment