Kapacitor - Converting tag value into field name

Hi,

I have some data in InfluxDB where the field name is simply “value” with a tag instance = temperature_sensor .

I would like to convert this instead into: a field name of “temperature_sensor”, and I’m not fussed about the tag.

I thought to do this as follows:

var phidget_points = stream
    |from()
        .measurement('phidget_value')

var phidgets_as_fields = phidget_points
    |eval(lambda: "value")
    .as('{{index .Tags "instance"}}')

However I was sad to see that the templating doesn’t work within “as” methods, or perhaps the tag is already gone by this time.

Do you have any advice on this?

If you just want to rename the field “value” to “temperature_sensor” you could try the rename processor

Then you’re data would have the right field name without having to do anything with TICK script.

If you wanted to do it in TICK you could try

|eval(lambda: "value")
.as('temperature_sensor')

To drop the “instance” tag if you don’t want it, you can simply add

|delete()
.tag('tag_value') 

Before you call the influxDBOut node.

You can also convert fields to tags

|eval(lambda: string("your_field")
as.('new_tag')
.tags('new_tag')
.keep('your_field')

that would give you a new tag and keep the original field in tact.

The rename option might be better, it will rename the field before it arrives in the InfluxDB - removing the need for the Kapacitor TICK script.

Hope that helps