We are having few problems writing the timestamp from mqtt to InfluxDB through Telegraf.
This is the part of the configuration file that applies the input from mqtt queue:
[[inputs.mqtt_consumer]]
## Broker URLs for the MQTT server or cluster. To connect to multiple
servers = ["tcp://*********"]
## Topics that will be subscribed to.
topics = ["SQLSERVER/#"]
qos = 0
# Enable extracting tag values from MQTT topics
data_format = "json_v2"
[inputs.mqtt_consumer.tags]
BucketDestino = "Ordenes"
[[inputs.mqtt_consumer.topic_parsing]]
data_format = "json_v2"
topic = "SQLSERVER/#"
[[inputs.mqtt_consumer.json_v2]]
[[inputs.mqtt_consumer.json_v2.field]]
path = "vnivelc"
type = "string"
Where can we indicate that the timestamp is “FecAsig”?
The topic is " SQLSERVER" and this is the following structure from mqtt:
You can use any time format supported by GO, not only the unix ones (which are the simplest even if not human readable), the GO docs are not very helpful unless you know what to look for, but any of the strings in the link will work.
here is the list of supported formats (extracted by the GO docs)
Layout = "01/02 03:04:05PM '06 -0700" // The reference time, in numerical order.
ANSIC = "Mon Jan _2 15:04:05 2006"
UnixDate = "Mon Jan _2 15:04:05 MST 2006"
RubyDate = "Mon Jan 02 15:04:05 -0700 2006"
RFC822 = "02 Jan 06 15:04 MST"
RFC822Z = "02 Jan 06 15:04 -0700" // RFC822 with numeric zone
RFC850 = "Monday, 02-Jan-06 15:04:05 MST"
RFC1123 = "Mon, 02 Jan 2006 15:04:05 MST"
RFC1123Z = "Mon, 02 Jan 2006 15:04:05 -0700" // RFC1123 with numeric zone
RFC3339 = "2006-01-02T15:04:05Z07:00"
RFC3339Nano = "2006-01-02T15:04:05.999999999Z07:00"
Kitchen = "3:04PM"
// Handy time stamps.
Stamp = "Jan _2 15:04:05"
StampMilli = "Jan _2 15:04:05.000"
StampMicro = "Jan _2 15:04:05.000000"
StampNano = "Jan _2 15:04:05.000000000"
DateTime = "2006-01-02 15:04:05"
DateOnly = "2006-01-02"
TimeOnly = "15:04:05"
Another question that comes to mind; we have two topics (“SQLSERVER” and “Linea Piloto”).
How can we add two topic data into the same bucket???
The fields “vnivelc” and “FecAsig” comes from SQLSERVER and we have a field “Maquina” that comes from “Linea Piloto”. Looking on the code from above how can we assign each field,tag and timestamp to each topic???