in a simple tick script, how can i query points and edit some key/values ?
i have this tick script:
var data = batch
|query(''' SELECT * FROM "telegraf"."autogen"."cpu" ''')
.period(5m)
.every(10s)
.groupBy(*)
|influxDBOut()
.database('telegraf)
.retentionPolicy('autogen')
.measurement('modified_data)
that queries some data, i want to change the CPU field on each point and add 5 to its value.
how can i do that ?
thanks.
Dave.
Normally, you change the fields inside CPU measurement.
For example, let's say your CPU measurement contains a field named time_idle, then you just have to insert an "eval" node before the output node.
var data = batch
|query(''' SELECT * FROM "telegraf"."autogen"."cpu" ''')
.period(5m)
.every(10s)
.groupBy(*)
|eval(lambda: "time_idle" + 5)
.as('time_idle_plus_5')
|influxDBOut()
.database('telegraf')
.retentionPolicy('autogen')
.measurement('modified_data')
Would be a good idea to read more about eval node here and about TICKScript nodes in general.
Related
I'm trying to off set my kapacitor query to look for a period of 5 mins but start 10 secs in the past. so the query would be for (now - 10s) to (now - 5m10s). This is to offset the the delay in data.
dbrp "telegraf"."Raw"
var process_load = batch
|query('''SELECT sum("ProcessTime")
FROM "telegraf"."Raw".Document
WHERE ("Application" = 'AMP' AND "Environment" = 'test' )
''')
.period(5m)
.every(10s)
.groupBy( 'GroupID' , 'Thread' , time(5m))
|alert()
.stateChangesOnly()
.warn(lambda: "sum" > 90000)
.crit(lambda: "sum" > 240000)
.log('/tmp/document.test.log')
Currently the influxdb is getting it's data from telegraf but the delay is causing the query to send a warning message even when it should be at critical. currently it sends an warning and a critical switching between the two. It should get a critical and then stay there until a document thread stops.
found the issue I needed to add the .align() and the .aligngroup() to the query node
I'm using Kapacitor to pre-process complex regex searches to optimise my Grafana rendering performance.
This is my Kapacitor script:
dbrp "telegraf"."autogen"
stream
|from()
.database('telegraf')
.measurement('access-log')
.where(lambda: ("request" =~ /\/service\/endpoint1.*/ OR "request" =~ /\/service\/.*\/endpoint1.*/ ))
|eval(lambda: 'endpoint1')
.as('service')
.keep('service','request')
|influxDBOut()
.database('telegraf')
.retentionPolicy('autogen')
.measurement('access-log')
.tag('kapacitor', 'true')
The issue comes when I check the database and Kapacitor has created new points or entries in the database for the processed entries instead of adding the new field to the existing Points.
Is there any way of making Kapacitor to enrich the data instead of duplicating?
Good afternoon,
I have created the following tickscript with a standard tickstack setup.
Which includes: InfluxDB(latest version) and kapacitor(latest version):
dbrp "derivatives"."default"
var data = batch
|query('select sum(value) from "derivatives"."default".derivative_test where time > now() - 10m')
.every(1m)
.period(2m)
var slope = data
|derivative('value')
.as('slope')
.unit(2m)
slope
|eval(lambda: ("slope" - "value") / "value")
.as('percentage')
|alert()
.crit(lambda: "percentage" <= -50)
.id('derivative_test_crit')
.message('{{ .Level }}: DERIVATIVE FOUND!')
.topic('derivative')
// DEBUGGING
|influxDBOut()
.database('derivatives')
.measurement('derivative_logs')
.tag('sum', 'sum')
.tag('slope', 'slope')
.tag('percentage', 'percentage')
But every time i want to define it i get the following message:
batch query is not allowed to request data from "derivatives"."autogen"
I never had this problem before with stream's but every batch tick script i write returns the same message.
My kapacitor user has full admin privs and i am able to get the data via a curl request, does anyone have any idea what could possibly be the problem here?
My thanks in advance.
Change this
dbrp "derivatives"."default"
var data = batch
|query('select sum(value) from "derivatives"."default".derivative_test where time > now() - 10m')
to this:
dbrp "derivatives"."autogen"
var data = batch
|query('select sum(value) from "derivatives"."autogen".derivative_test where time > now() - 10m')
It might not be obvious, but the retention policy is most likely incorrect.
If you run SHOW RETENTION POLICIES on the derivatives database you will see the RP's. I suspect you have an RP of autogen, which is the default RP. However "default" doesn't normally exist as an RP unless you create it, it just signifies that it is the default RP, if that makes sense?
RP Documentation might help clear it up Database Documentation.
default autogen RP
I’m trying to aggregate data over the previous week hourly, and compute summary statistics like median, mean, etc.
I’m using something like this:
var weekly_median = batch
|query('''SELECT median("duration") as week_median
FROM "db"."default"."profiling_metrics"''')
.period(1w)
.every(1h)
.groupBy(*)
.align()
|influxDBOut()
.database('default')
.measurement('summary_metrics')
The query works as expected, except that when recording and replaying data to test with
kapacitor record batch -task medians -past 30d
kapacitor replay -task medians -recording $rid -rec-time
the data is missing for the last period (1 week in this case). If I change the period to 1 day, all data is replayed except the final day’s worth.
Is this a problem with my tickscript, the way I’m recording data, or the way I’m replaying it?
I see, I need to do the aggregation in Kapacitor, not Influx. This seems to be a known issue, but finding documentation on it was tricky. https://github.com/influxdata/kapacitor/issues/1257 and https://github.com/influxdata/kapacitor/issues/1258 were helpful. The solution is to instead do something like:
var weekly_median = batch
|query('''SELECT "duration"
FROM "db"."default"."profiling_metrics"
WHERE "result" =~ /passed/''')
.period(1w)
.every(1h)
.groupBy(*)
.align()
|median('duration')
.as('week_median')
|influxDBOut()
.database('default')
.measurement('summary_metrics')
I have two variables (id and Var1) in SPSS as below. I want to sort Var1 as descending order but other variables do not change accordingly with Var1. i.e. other variable will remain same as before sort.
My data is...
id Var1
-- ----
M-1 3
M-2 4
M-3 2
M-4 7
But I want like this..
id Var1
-- ----
M-1 7
M-2 4
M-3 3
M-4 2
My Syntax/code is...
data list list
/id(A3) Var1(F2.0).
begin data.
M-1 3
M-2 4
M-3 2
M-4 7
end data.
sort cases by BY Var1(D).
execute.
When I run this code it also sort id according to Var1. But I do not want to expand this sort command for entire variables. I only want to sort for current selection variable in SPSS.
Can anyone help using SPSS Syntax?
You Could split the dataset sort the Var1 variable and then merge them together. One way to do so would be this:
* create data.
data list list
/id(A3) Var1(F2.0).
begin data.
M-1 3
M-2 4
M-3 2
M-4 7
end data.
DATASET NAME ids.
DATASET COPY sortvar.
* Delete sort variable (Var1) from dataset "ids".
DELETE VARIABLES Var1.
* Keep only sort variable in dataset "sortvars".
DATASET ACTIVATE sortvar.
DELETE VARIABLES id.
* sort Var1.
SORT CASES BY Var1(D).
* Merge datasets.
MATCH FILES
/FILE ids
/FILE sortvar.
EXECUTE.
If you have lots of variables to delete in the sortvar dataset you could also use the MATCH CASES command:
* Delete all variables but Var1.
DATASET ACTIVATE sortvar.
MATCH CASES
/FILE *
/KEEP Var1.
Alternativly you can use the SAVE command in combination with the KEEP or DROP options in order to split the dataset.