telegraf
Install Telegraf from this official site: https://www.influxdata.com/get-telegraf/
For Ubunbu:
- after install, edit conf file in /etc/telegraf/telegraf.conf
- test the conf by: telegraf –config /etc/telegraf/telegraf.conf –test
- start the service: sudo systemctl restart telegraf
For Windows:
- after install, edit the conf file in where telegraf was extracted
- install telegraf as a service (follow the instruction)
- test conf via powershell: & “C:\Program Files\Telegraf\telegraf.exe” –config “C:\Program Files\Telegraf\telegraf.conf”
- start the service from Windows service
Sample working conf:
[agent]
interval = "1s" # Frequent checks for internal housekeeping
flush_interval = "1s" # Push to MySQL every 1 second (or as soon as data exists)
flush_jitter = "0s" # Ensure no random delay in flushing
precision = "1ms" # High-precision timestamps
debug = true
omit_hostname = true
# ------------------------------------------------------------------------------
# INPUTS
# ------------------------------------------------------------------------------
# Input 1: Alerts
[[inputs.mqtt_consumer]]
servers = ["tcp://localhost:1883"]
topics = ["grocery/fdas/alerts"]
name_override = "sbifdas_alerts" # Unique name for internal routing
data_format = "json"
json_string_fields = ["desc"]
tagexclude = ["topic", "host"]
# Input 2: Response
[[inputs.mqtt_consumer]]
servers = ["tcp://localhost:1883"]
topics = ["grocery/fdas/response"]
name_override = "sbifdas_response" # Unique name for internal routing
data_format = "json"
tagexclude = ["topic", "host", "measurement"]
fieldexclude = ["ip"]
# ------------------------------------------------------------------------------
# PROCESSORS
# ------------------------------------------------------------------------------
# Applies only to the Alerts input
[[processors.rename]]
namepass = ["sbifdas_alerts"]
[[processors.rename.replace]]
field = "desc"
dest = "name"
[[processors.rename.replace]]
field = "id"
dest = "senderid"
# Applies only to the Response input
[[processors.unpivot]]
namepass = ["sbifdas_response"]
tag_key = "name"
value_key = "val"
[[processors.strings]]
# This targets the text inside the fields/tags named "name" and "senderid"
[[processors.strings.uppercase]]
field = "name"
[[processors.strings.uppercase]]
tag = "name"
[[processors.strings.uppercase]]
field = "senderid"
[[processors.strings.uppercase]]
tag = "senderid"
# Applies only to the Response input (after unpivot)
[[processors.template]]
namepass = ["sbifdas_response"]
tag = "senderid"
template = "{{ .Tag \"name\" }}"
# Final Rename: Both inputs are renamed to match your SQL table name
[[processors.rename]]
[[processors.rename.replace]]
measurement = "sbifdas_alerts"
dest = "sbifdas"
[[processors.rename.replace]]
measurement = "sbifdas_response"
dest = "sbifdas"
# ------------------------------------------------------------------------------
# OUTPUTS
# ------------------------------------------------------------------------------
[[outputs.sql]]
driver = "mysql"
data_source_name = "iottest:iottester@tcp(localhost:3306)/iot?sql_mode=ANSI_QUOTES&time_zone='%2B08:00'"
timestamp_column = "dummy"
fieldinclude = ["senderid", "name", "val"]
taginclude = []
telegraf.txt · Last modified: by jwan
