Add Dynamic Tags Based on Field


Problem: I’m using telegraf’s win_services plugin which has field “state” with values “1 2 3 4 5 6 7”. I want to add text explanation of this numbers as a tag. Example: if 4 > "Running" if 1 > "Stopped"

Can you help me to with an example config? I searched this question and found enum processor but I’m not sure if it’s the solution.

  1. As far as I understand, enum works across the config file. I need it for only “win_services” measurement.
  2. I need to create tags from field values.

You could use the enum processor, I think something like this might do what you want:

namepass = “win_services”
field = “state”
dest = “state_label”
1 = “Stopped”
4 = “Running”

The namepass parameter will limit the plugin to only run against the win_services measurement.

You can also convert your state field into a tag in Telegraf with the converter plugin:

tag = [“state”]

Then in your Flux query you can change the value from a number to a human-readable label.

1 Like

Very cool @mhall119 !

This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.

First of all thanks for your reply.

I wonder if I can set “state_label” as a tag instead of field while the “state” is field.
I’ve tried to combine “converter” with “enum” but no luck. Generated “state_label” field with enum then tried to convert it into a tag with “converter” but telegraf telegraf doesn’t run processor plugins in the order of their place in the config file. I’m not sure if I can create a pipeline in telegraf or is there a simpler way?

I don’t use flux for now. So, I want to add the tag into the data points itself.

You can force the order that Processors are run by giving them an order = # parameter: telegraf/ at master · influxdata/telegraf · GitHub

1 Like

Cool Thanks!

  namepass = "win_services"
  order = 1
    field = "state"
    dest = "state_label"
      1 = "Stopped"
      4 = "Running"
      2 = "Start Pending"
      3 = "Stop Pending" 
      5 = "Continue Pending"
      6 = "Pause Pending"
      7 = "Paused"

  namepass = "win_services"
  order = 2
    tag = ["state_label"]
1 Like

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.