Telegraph config setup

Hi, I am new to telegraf and i need help to understand how can i read the MQTT data, parse and send to influxdb.

data in MQTT explorer looks like
![image|578x500](upload://3tI3ycheStbT9DIgQkfANAOaBjV.png

I have been trying and below is my conf file

# # Read metrics from MQTT topic(s)
 [[inputs.mqtt_consumer]]
servers = ["tcp://mqtt:1883"]
 topics = [
   "$SYS/#",
   ]
client_id = "Telegraf"
 username = "******"
 password = "******"
data_format = "influx"

[[outputs.influxdb_v2]]

urls = ["http://127.0.0.1:8086"]
 token = "**********************************************************"
organization = "*****"
bucket = "power"

When i test the conf file, below is the result

PS C:\Program Files\InfluxData\telegraf> C:\"Program Files"\InfluxData\telegraf\telegraf.exe --config C:\"Program Files"\InfluxData\telegraf\telegraf.conf --test
2023-03-22T12:09:59Z I! Loading config file: C:\Program Files\InfluxData\telegraf\telegraf.conf
2023-03-22T12:09:59Z I! Starting Telegraf 1.26.0
2023-03-22T12:09:59Z I! Available plugins: 235 inputs, 9 aggregators, 27 processors, 22 parsers, 57 outputs, 2 secret-stores
2023-03-22T12:09:59Z I! Loaded inputs: cpu disk diskio kernel mem mqtt_consumer processes swap system
2023-03-22T12:09:59Z I! Loaded aggregators:
2023-03-22T12:09:59Z I! Loaded processors:
2023-03-22T12:09:59Z I! Loaded secretstores:
2023-03-22T12:09:59Z W! e[31mOutputs are not used in testing mode!e[0m
2023-03-22T12:09:59Z I! Tags enabled: host=MAPPG0001
2023-03-22T12:09:59Z W! [inputs.processes] Current platform is not supported
2023-03-22T12:09:59Z W! [inputs.kernel] current platform is not supported
2023-03-22T12:10:01Z E! [agent] Starting input inputs.mqtt_consumer: network Error : dial tcp: lookup mqtt: no such host
> mem,host=MAPPG0001 available=5317537792i,available_percent=61.91276023969116,total=8588759040i,used=3271221248i,used_percent=38.08723976030884 1679487001000000000
> disk,device=C:,fstype=NTFS,host=MAPPG0001,mode=rw,path=\C: free=89986056192i,inodes_free=0i,inodes_total=0i,inodes_used=0i,total=135771664384i,used=45785608192i,used_percent=33.72250638579901 1679487001000000000
> disk,device=D:,fstype=NTFS,host=MAPPG0001,mode=rw,path=\D: free=15751868416i,inodes_free=0i,inodes_total=0i,inodes_used=0i,total=17177767936i,used=1425899520i,used_percent=8.300842841238392 1679487001000000000
> disk,device=S:,fstype=NTFS,host=MAPPG0001,mode=rw,path=\S: free=68599078912i,inodes_free=0i,inodes_total=0i,inodes_used=0i,total=68701646848i,used=102567936i,used_percent=0.14929472684538114 1679487001000000000
> diskio,host=MAPPG0001,name=S: io_time=0i,iops_in_progress=0i,merged_reads=0i,merged_writes=0i,read_bytes=12288i,read_time=0i,reads=3i,weighted_io_time=0i,write_bytes=0i,write_time=0i,writes=0i 1679487001000000000
> diskio,host=MAPPG0001,name=C: io_time=0i,iops_in_progress=0i,merged_reads=0i,merged_writes=0i,read_bytes=2963092480i,read_time=366i,reads=192569i,weighted_io_time=0i,write_bytes=1678793216i,write_time=72i,writes=43477i 1679487001000000000
> diskio,host=MAPPG0001,name=D: io_time=0i,iops_in_progress=0i,merged_reads=0i,merged_writes=0i,read_bytes=27181568i,read_time=0i,reads=966i,weighted_io_time=0i,write_bytes=204251136i,write_time=4i,writes=4235i 1679487001000000000
> system,host=MAPPG0001 load1=0,load15=0,load5=0,n_cpus=2i 1679487001000000000
> system,host=MAPPG0001 uptime=7028i 1679487001000000000
> system,host=MAPPG0001 uptime_format=" 1:57" 1679487001000000000
> swap,host=MAPPG0001 free=7029841920i,total=9930936320i,used=2901094400i,used_percent=29.212697640175783 1679487001000000000
> swap,host=MAPPG0001 in=0i,out=0i 1679487001000000000
> cpu,cpu=cpu0,host=MAPPG0001 usage_guest=0,usage_guest_nice=0,usage_idle=69.6969696969697,usage_iowait=0,usage_irq=0,usage_nice=0,usage_softirq=0,usage_steal=0,usage_system=12.121212121212121,usage_user=18.181818181818183 1679487002000000000
> cpu,cpu=cpu1,host=MAPPG0001 usage_guest=0,usage_guest_nice=0,usage_idle=60.60606060606061,usage_iowait=0,usage_irq=0,usage_nice=0,usage_softirq=0,usage_steal=0,usage_system=24.242424242424242,usage_user=15.151515151515152 1679487002000000000
> cpu,cpu=cpu-total,host=MAPPG0001 usage_guest=0,usage_guest_nice=0,usage_idle=65.15151515151516,usage_iowait=0,usage_irq=0,usage_nice=0,usage_softirq=0,usage_steal=0,usage_system=18.181818181818183,usage_user=16.666666666666668 1679487002000000000
2023-03-22T12:10:03Z E! [inputs.mqtt_consumer] Error in plugin: network Error : dial tcp: lookup mqtt: no such host
2023-03-22T12:10:03Z E! [telegraf] Error running agent: input plugins recorded 1 errors

Now i updated my conf file and below is the test result in powershell and nothing comes in the influxdb

# # Read metrics from MQTT topic(s)
 [[inputs.mqtt_consumer]]
servers = ["mqtt://ipaddress:1883"]
 topics = [
   "$SYS/#",
   ]
client_id = "Telegraf"
 username = "******"
 password = "******"
data_format = "influx"

[[outputs.influxdb_v2]]

urls = ["http://127.0.0.1:8086"]
 token = "**********************************************************"
organization = "*****"
bucket = "power"
PS C:\Program Files\InfluxData\telegraf> C:\"Program Files"\InfluxData\telegraf\telegraf.exe --config C:\"Program Files"\InfluxData\telegraf\telegraf.conf --test
2023-03-22T12:23:25Z I! Loading config file: C:\Program Files\InfluxData\telegraf\telegraf.conf
2023-03-22T12:23:25Z I! Starting Telegraf 1.26.0
2023-03-22T12:23:25Z I! Available plugins: 235 inputs, 9 aggregators, 27 processors, 22 parsers, 57 outputs, 2 secret-stores
2023-03-22T12:23:25Z I! Loaded inputs: mqtt_consumer
2023-03-22T12:23:25Z I! Loaded aggregators:
2023-03-22T12:23:25Z I! Loaded processors:
2023-03-22T12:23:25Z I! Loaded secretstores:
2023-03-22T12:23:25Z W! e[31mOutputs are not used in testing mode!e[0m
2023-03-22T12:23:25Z I! Tags enabled: host=MAPPG0001
2023-03-22T12:23:25Z I! [inputs.mqtt_consumer] Connected [mqtt://ipaddress:1883]
PS C:\Program Files\InfluxData\telegraf>

I’ve got just two suggestions

  • running telegraf --test doesn’t run outputs (for that use --once), therefore no data will be sent to InfluxDB.
  • to serialize the data properly you need to define fields and tags. Since you are using the json data format have a look at the JSON parser. if not set up properly you might “miss” some data (you need to specify the json keys to be turned into tags, and also specify text fields if any. Numeric fields will be present by default)

This is the data in MQTT explorer, Since i am very much new, can you just show me an example to extract the data

Thanks for the suggestions. You made my day :slight_smile: