Search code examples
time-seriesinfluxdbtelegraf

Telegraf Processor value to fieldname


I have points from my Input like these two:

http,Location=Foo Key="Humidity",Value=68 1659704523000000000
http,Location=Foo Key="Temperature",Value=24,1 1659704523000000000

But I have to store them like these:

http,Location=Foo Humidity=68 1659704523000000000
http,Location=Foo Temperature=24,1 1659704523000000000

I saw almost all of Processor plugin docs, but I still not sure it is possible to use field value as a field name. Isn't it?


Solution

  • I still not sure it is possible to use field value as a field name. Isn't it?

    Yep! The starlark processor will do this. The 'pivot' example is what you are after.

    The following will create a new field based on the values of Key and Value and then remove the original values:

    [[processors.starlark]]
      source = '''
    def apply(metric):
      metric.fields[str(metric.fields['Key'])] = metric.fields['Value']
      metric.fields.pop('Key',None)
      metric.fields.pop('Value',None)
      return metric
    '''