How to rename fields from multiple input processors with identical names

2.4k Views Asked by At

I am using Telegraf and I have multiple input.http plugins returning the same field names and want to distinguish between them.

I am calling ElasticSearch for different search criteria, the JSON structure returned is always the same, so while I can define the measurement at the input.http level (name_override or name_suffix), I would like to change the field value which is always "doc_count".

Sample Output (structure is the same regardless of query params):

{
    "took": 487,
    "timed_out": false,
    "_shards": {
        "total": 707,
        "successful": 707,
        "skipped": 610,
        "failed": 0
    },
    "hits": {
        "total": 14,
        "max_score": 0.0,
        "hits": []
    },
    "aggregations": {
        "3": {
            "doc_count_error_upper_bound": 0,
            "sum_other_doc_count": 0,
            "buckets": [
                {
                    "key": "logging-fluentd-jkq66",
                    "doc_count": 8
                },
                {
                    "key": "logging-fluentd-4vz58",
                    "doc_count": 4
                },
                {
                    "key": "logging-fluentd-4bh8j",
                    "doc_count": 2
                }
            ]
        }
    }
}

I have played around with processes.rename and I can get this to work (including filtering based on measurement name) but this only works for one measurement. It ignores multiple porcesses.rename definitions.

The following definition only honours the first section.

[[processors.rename]]
  namepass = "_http_elasticsearch_logs_dropping"
  [[processors.rename.replace]]
    measurement = "_http_elasticsearch_logs_dropping"
    dest = "_http_elastic"

  [[processors.rename.replace]]
    field = "doc_count"
    dest = "buffer_flush_or_queue_size_errors"

[[processors.rename]]
  namepass = "_http_elasticsearch_microservice_logs"
  [[processors.rename.replace]]
    measurement = "_http_elasticsearch_microservice_logs"
    dest = "_http_elastic"

  [[processors.rename.replace]]
    field = "doc_count"
    dest = "log_count"

I'm sure there's a way to achieve what I'm trying to do but haven't stumbled upon it yet.

1

There are 1 best solutions below

0
On

Ok, my mistake. The processors.rename can have multiple instances, my issue was with the namepass argument should be an array. Working config based on the above scenario:

[[processors.rename]]
  namepass = ["_http_elasticsearch_logs_dropping"]
  [[processors.rename.replace]]
    measurement = "_http_elasticsearch_logs_dropping"
    dest = "_http_elastic"

  [[processors.rename.replace]]
    field = "doc_count"
    dest = "buffer_flush_or_queue_size_errors"

[[processors.rename]]
  namepass = ["_http_elasticsearch_microservice_logs"]
  [[processors.rename.replace]]
    measurement = "_http_elasticsearch_microservice_logs"
    dest = "_http_elastic"

  [[processors.rename.replace]]
    field = "doc_count"
    dest = "log_count"