Telegraf - ignoring measurement_name

Hello Experts,

I’m trying to change the measurement name, but I still can’t. I think that according to this manual I have everything OK. Don’t you know where the mistake could be?

How to Parse JSON with Telegraf

telegraf.conf

[[inputs.mqtt_consumer]]
    servers = ["tcp://192.168.2.16:1883"]
    topics = [
      "tele/+/STATE",
    ]
    data_format = "json_v2"
    [[inputs.mqtt_consumer.json_v2]]
        measurement_name = "zigbee"
        [[inputs.mqtt_consumer.json_v2.field]]
            path = "POWER"
            type = "string"
        [[inputs.mqtt_consumer.json_v2.field]]
            path = "UptimeSec"
            type = "int"
        [[inputs.mqtt_consumer.json_v2]]
        [[inputs.mqtt_consumer.json_v2.object]]
            path = "Wifi"
            included_keys = ["RSSI", "Signal"]

thank you for answer

Mirino

Seems right to me, the only question is which version of telegraf are you using?
I’ll have to look into it.

In the meanwhile you can use :
name_override - Override the base name of the measurement. (Default is the name of the input).

put it at input level like this:

[[inputs.mqtt_consumer]]
  name_override = "zigbee"
  servers = ["tcp://192.168.2.16:1883"]
  {...}
ubuntu@raspberry1:~$ /usr/bin/telegraf --version
**Telegraf 1.24.1** (git: HEAD@bd7d53fb)

I just updateted to version Telegraf 1.24.2 (git: HEAD@9550e7a5) but same problem.

name_override = “zigbee”
That option works OK but all parsing fields go to one measurement “zigbee”

Now I will try to divide the fields
“POWER” , “UptimeSec” → measurement “zigbee”
“RSSI”, “Signal” → measurement_name = “wifi”
but all fields go to one measurement “wifi” and ignoring “zigbee”

[[inputs.mqtt_consumer]]
    servers = ["tcp://192.168.2.16:1883"]
    topics = [
      "tele/+/STATE",
    ]
    data_format = "json_v2"
    [[inputs.mqtt_consumer.json_v2]]
        measurement_name = "zigbee"
        [[inputs.mqtt_consumer.json_v2.field]]
            path = "POWER"
            type = "string"
        [[inputs.mqtt_consumer.json_v2.field]]
            path = "UptimeSec"
            type = "int"
        [[inputs.mqtt_consumer.json_v2]]
            measurement_name = "wifi"
        [[inputs.mqtt_consumer.json_v2.object]]
            path = "Wifi"
            included_keys = ["RSSI", "Signal"]

measurement_name cannot be redefined multiple times for a parser as you have above. Effectively what you want is to create 2 measurements. To do that means having the mqtt_consumer read twice, one for each, or using the starlark processor to split the one metric into a second (e.g. example showing the creating of a second metric).

Another option is to have a single measurement with all this data:

zigbee,POWER="",Signal="" "UptimeSec"=VAL,RSSI=VAL

Or something similar to that rather than breaking them apart.

1 Like

@jpowers I chose the option number 1 and everything works :slight_smile: , thx
But I would also be interested in possibility number 2.(example) Could you write it down for me in Starlank language?

[[inputs.mqtt_consumer]]
    servers = ["tcp://192.168.2.16:1883"]
    topics = [
      "tele/+/STATE",
    ]
    data_format = "json_v2"
    [[inputs.mqtt_consumer.json_v2]]
        measurement_name = "zigbee"
        [[inputs.mqtt_consumer.json_v2.field]]
            path = "POWER"
            type = "string"
        [[inputs.mqtt_consumer.json_v2.field]]
            path = "UptimeSec"
            type = "int"
[[inputs.mqtt_consumer]]
    servers = ["tcp://192.168.2.16:1883"]
    topics = [
      "tele/+/STATE",
    ]
    data_format = "json_v2"
    [[inputs.mqtt_consumer.json_v2]]
        measurement_name = "wifi"
        [[inputs.mqtt_consumer.json_v2.object]]
            path = "Wifi"
            included_keys = ["RSSI", "Signal"]

You can also use standard processors to clone/split/edit your data, I’m thinking a mix of metric filters with the processor.override. You should be able to get the existing point (clone it?), drop fields and change the measurement name.
A clone is probably needed 8as there are 2 separate branches) but it’s pretty easy anyway as we got [processor.clone]

I’ve never used starlark so I’m not sure which way is easier

@sspaink do you want to try to come up with a starlark script for this?