Adding dynamic tags to telegraf input

Yossale picture Yossale · Jul 18, 2017 · Viewed 7.3k times · Source

We're using telegraf to collect CloudWatch data from AWS and output it to InfluxDB.

We need to add dynamic tags to the input, s.t if "instancId == 12345", add tag "user = 3"

Is there a way to do this?

Answer

Stoinov picture Stoinov · Nov 12, 2018

Take a look at the processors. If you have just a set of known values that you want to work with, I think enum would be the best option. Here is the example updated for your case:

[[processors.enum]]
  [[processors.enum.mapping]]
    ## Name of the field to map
    field = "instancId"

    ## Destination field to be used for the mapped value.  By default the source
    ## field is used, overwriting the original value.
    dest = "user"

    ## Default value to be used for all values not contained in the mapping
    ## table.  When unset, the unmodified value for the field will be used if no
    ## match is found.
    default = 0

    ## Table of mappings
    [processors.enum.mapping.value_mappings]
      123 = 1
      1234 = 2
      12345 = 3