Open violet-day opened 8 years ago
This is what the on property on the join node is for. But is currently has a bug where you need to use at least two tags to get it to work.
This TICkscript should work for you:
var inner = batch
|query('select sum("count") as count from "hestia"."default"."eleme_order_invalid_description"')
.every(1d)
.period(1d)
.groupBy('come_from', 'desc')
.align()
.fill(0)
var total = batch
|query('select sum("count") as count from "hestia"."default"."eleme_order_invalid_description"')
.every(1d)
.period(1d)
.groupBy('come_from')
.align()
.fill(0)
|log()
.level('debug')
.prefix('total')
total
|join(inner)
.tolerance(1d)
.as('total', 'inner')
.fill(0.0)
.on('come_from')
|log()
.level('debug')
.prefix('after join')
|eval(lambda: "inner.count" / "total.count")
.as('rate')
|log()
.level('debug')
.prefix('after evel')
|influxDBOut()
.database('hestia')
.retentionPolicy('default')
.measurement('downsample_marco_invalid_order_description')
The join node only joins points that have the same group unless you specify the on
property to tell it how to join across groups. In this case you are telling it to join points tagged with come_from,desc
to points tagged with come_from
on the come_from
tag. As a result the points tagged with only the come_from
tag are duplicated for each of the matching come_from,desc
points. Thus allowing you to calculate percentage of totals.
Also note that I removed the time(1d)
from the group by since it isn't necessary since your period and every durations are also 1d.
I have a measurement like this:
In this measurement,I'd like to calculate each
desc
's percent in total. Below is the tickStrange thing is the
total
not match theinner
though the same time .Here is the logs:But if I just add
come_from
within groupBy intotal
andinner
,it works.Is there any way to calculate percent the
desc
tag?Kapacitor version is
Kapacitor 1.0.2 (git: master 1011dba109bf3d83366c87873ec285c7f9140d34)