Error in plugin: metric parse error: expected tag at "..."

Hey guys, im getting a error i cant fix. My telagraf shows the following error:

Aug 16 15:09:13 IOTRPI202 telegraf[5488]: 2021-08-16T14:09:13Z E! [inputs.mqtt_consumer] Error in plugin: metric parse error: expected tag at 1:7: "lunch, user=krebsnoe place=Dabei"

My config:

[[inputs.mqtt_consumer]]
  servers = ["tcp://127.0.0.1:1883"]
  topics = [ "lunch/#", ]
  data_format = "influx"

I tried data_typ string and data_format value but then grafana could not read the data anymore.

thx for your help

Hello @Eon_Sberk,
you can add a constant tag like so:

[[inputs.mqtt_consumer]]
  servers = ["tcp://127.0.0.1:1883"]
  topics = [ "lunch/#", ]
  data_format = "influx"
  [inputs.mqtt.tags]
     mytag = "mytagvalue"

You’ll also have to get rid of the space between fields as fields are comma separated.

To solve this type of problems I recommend using the --test flag when running your config to make sure that your output matches correct line protocol format.

Hello @Anaisdg,

Thank you for your fast answer!

Could you give me a example with my tags? Also for the seperation of the values because i could not figure it out.

Thanks :slight_smile:

@Eon_Sberk

You have influx configured as the input data_format, but I suspect the payload of the mqtt messages does not contain valid influx line protocol format.
Please post an example of your mqtt payload.

1 Like

I found out it works if i do:

lunch, user=krebsnoe place=1 but that dose not fix my Problem

Hello @Eon_Sberk,
Can you explain your mqtt payload further? What do you want to be tags and what do you want to be fields?
Can you might have to use a different input format like grok and then parse the output:

OR you could use the execd processor plugin.

@popey are there any quick fixes with the mqtt plugin that I’m not aware of?

Hello @Anaisdg

lunch is my topic, user and place are tag’s and krebsnoe and Dabei are the fields.

Im not sure if i understand Tags and Fields right so what i want would look like this in SQL:

INSERT INTO lunch(user, place) VALUES("krebsnoe", "Dabei"); 

I’m sorry, I don’t understand.
What works?
What is the problem?

I assume you have control over the mqtt payload? Then I would first create valid influx line protocol format as mqtt payload.

lunch, user=krebsnoe place=Dabei Dose not work and thats my Problem. In the end i just want to raed the place of each user

Yes, because it is not valid influx line protocol format.
See the format specification here:

This could be valid:

lunch,user=krebsnoe place="Dabei"

or

lunch,user=krebsnoe place=1u

Be aware that influx line protocol format is whitespace sensitive.

1 Like

Hello everyone,

I have come to this thread due to a problem similar to the one discussed here, and I would like to please, if you would be so kind to help me or guide me in this regard.

I’m trying to run a monitoring stack that I successfully developed and implemented in another infrastructure at the time.

However, I am getting an error similar to the one reported in this thread. In this new infrastructure where I am trying to make the code I had developed work, I am getting errors from the telegraf agent since it cannot ingest the data into the influx database:

[inputs.exec] Error in plugin: metric parse error: expected tag at 1: 7: "ERROR:"

The funny thing about the case is that if I do a test of my configuration file, telegraf reads and executes the script that generates the metric, correctly, but if I let the system run on its own, it gives the error that I indicated before.

Doing a test of the configuration file I get an output like this:

[root@ip-XXX-31-XX-XXX oracle]# telegraf -config /etc/telegraf/telegraf.conf -config-directory /etc/telegraf/telegraf.d --test --input-filter="exec"
2021-09-27T23:45:09Z I! Starting Telegraf 1.20.0
> oracle_bbdd_pga_usage,db_name=ORCL,host=ip-XXX-31-XXX-XXX.eu-west-1.compute.internal,pga_usage_stat=session_pga_memory,product=orards pga_usage_amount=490618600 1632786309000000000
> oracle_bbdd_pga_usage,db_name=ORCL,host=ip-XXX-31-XXX-XXX.eu-west-1.compute.internal,pga_usage_stat=session_pga_memory_max,product=orards pga_usage_amount=644279672 1632786309000000000

From the telegraf configuration file, I call the script that generates the metric, like this:

[[inputs.exec]]
  commands = ["/etc/telegraf/telegraf.d/plugins/oracle/telegraf_call_ora_metric_queries oracle_bbdd_instance_sum_pga_usages.sql"]
  timeout = "40s"
  interval = "60s"
  data_format = "influx"

Please, could you help me determine what is the reason why influx rejects the metric?

Thank you so much in advance for any help you could give me in this regard.