Search code examples
grafanainfluxdbtelegraf

Telegraf to InfluxDB - JSON Nested object property


I've been struggling already for few days to get this one working. All the solutions that I found from people with same problem did not work for me.

I am parsing data from JSON file through Telegraf using [inputs.file] and using this data later on in Grafana from InfluxDB.

My problem: All key-value pairs where value is in a form of a number are working as they should and are showing correctly in InfluxDB. However, all key-value pairs where value is a string or boolean are not working.

  1. [processors.converter] I have tried it and no success, whatever example I have followed I am not getting any new fields in the InfluxDB, also logs from telegram are not showing any of the keys or values that I declare in the converter.
  2. [inputs.file]-json_strings_fields I have tried to add json_string_fields as well, many examples how other guys did it and no success.

Part of my json:

 },
"electricChargingState": {
  "chargingConnectionType": "UNKNOWN",
  "chargingLevelPercent": 77,
  "chargingStatus": "CHARGING",
  "chargingTarget": 100,
  "isChargerConnected": true,
  "range": 205

From the above code I am getting "charginLevelPercent", "chargingTarget" and "range", I cannot get "ChargingStatus" and "isChargerConnected".

In telegraf [inputs.file] I tried, but without success:

json_string_fields = ["chargingStatus"]

Also, in [processors.converter] I tried, but without success:

   [[processors.converter]]

   [processors.converter.tags]
      string = ["chargingStatus*"]
      boolean = ["isChargerConnected"]

   [processors.converter.fields]
      tag = ["chargingStatus"]
      string = ["chargingStatus"]
      boolean = ["isChargerConnected"]

Thanks to everyone who spare some of their valuable time to help me find solution.


Solution

  • problem has been solved by using the underscores and in json_string_fields declare full path of the key-value pair. Hope this sort problem for someone else as well. For instance:

       json_string_fields = ["state_electricChargingState_isChargerConnected"]