I am having trouble reloading a task that’s based on a template and variable file. The relevant files are:
├── etc
│ ├── kapacitor
│ │ └── load
│ │ ├── tasks
│ │ │ ├── project_4_sigma_windspeed.json
│ │ └── templates
│ │ └── sigma_template.tick
The kapacitor service loads it correctly and it runs fine, but if I want to change a variable in the json file, I need to restart the kapacitor service for the changes to be realized. It seems like there should be some sort of reloading process or redefining
sigma_template.tick
// measurement
var measurement = ''
// tags to group by
var groupby = [*]
// field
var field = ''
// How many stddevs away from the mean will trigger a critical alert
var crit_sigma_level = 3.0
// How many stddevs away from the mean will trigger a warning alert
var warn_sigma_level = 1.5
// Window for computing sigma
var sigma_window = 10s
// critical alert message
var crit_message = 'Critical sigma level'
// warn alert message
var warn_message = 'Warning sigma level'
// critical alert message
var ok_message = 'OK'
// PROCESSING
var data = stream
|from()
.measurement(measurement)
.groupBy(groupby)
|window()
.period(sigma_window)
.align()
var mean_field = data
|mean(field)
.as('mean_field')
var last_field = data
|last(field)
.as('last_field')
var stddev_field = data
|stddev(field)
.as('stddev_field')
var sigma_field = mean_field
|join(last_field, stddev_field)
.as('A', 'B', 'C')
|eval(lambda: abs("B.last_field"-"A.mean_field")/"C.stddev_field")
.as('sigma_field')
sigma_field
|influxDBOut()
.create()
.database('debugging')
.retentionPolicy('autogen')
.measurement('debug2')
.precision('s')
project_4_sigma_windspeed.json
{
"dbrps": [{"db": "project_4", "rp": "thirty_days"}],
"template-id": "sigma_template",
"vars": {
"measurement": {"type": "string", "value": "project_4"},
"field": {"type": "string", "value": "windspeed"},
"crit_sigma_level": {"type": "float", "value": 8.0},
"warn_sigma_level": {"type": "float", "value": 3.3},
"sigma_window": {"type": "duration", "value": "20s"}
}
}
define template
./kapacitor define-template sigma_template -tick ../../etc/kapacitor/load/templates/sigma_template.tick
define task
./kapacitor define project_4_sigma_windspeed -template sigma_template -vars ../../etc/kapacitor/load/tasks/project_4_sigma_windspeed.json
show task (the relevant bits)
Vars:
Name Type Value
crit_sigma_level float 8
field string windspeed
measurement string project_4
sigma_window duration 20s
warn_sigma_level float 3.3
All works fine at this point. But if I want to change a value in the variable json, like change “warn_sigma_level” to 5.0, the only thing that works to register this change is to restart the kapacitord process.
reload tasks
I tried reloading the tasks:
./kapacitor reload project_4_sigma_windspeed
./kapacitor show project_4_sigma_windspeed
> Vars: > Name Type Value > crit_sigma_level float 8 > field string windspeed > measurement string project_4 > sigma_window duration 20s > warn_sigma_level float 3.3
redefine template
I tried re-defining the template:
./kapacitor define-template sigma_template -tick
../../etc/kapacitor/load/templates/sigma_template.tick
./kapacitor show project_4_sigma_windspeed
Vars:
Name Type Value
crit_sigma_level float 8
field string windspeed
measurement string project_4
sigma_window duration 20s
warn_sigma_level float 3.3
restart kapacitord
The only thing that works is to restart the kapacitor service.
Then, the changes are realized:
./kapacitor show project_4_sigma_windspeed
Vars: Name Type Value crit_sigma_level float 8 field string windspeed measurement string project_4 sigma_window duration 20s warn_sigma_level float 5
Having to restart the kapacitor service every time I change a variable seems kinda kludgy. Is there another way to reload a task that’s defined by a template and json variable file?
Thanks
edit: sorry about formatting. I don’t know how to do it.