Telegraf error: systemctl start telegraf

Hi, I’m using a raspberry with Ubuntu 22.04.4 LTS.
I can’t start telegraf with the command " systemctl start telegraf ".
I’ve already made sure that I’ve edited the configuration file correctly.
The two plugins I’m using are [inputs.modbus] and [outputs.influxdb_v2].
The output of journalctl -eu telegraf is the following:

telegraf.service: Main process exited, code=exited, status=1/FAILURE
systemd[1]: telegraf.service: Failed with result ‘exit-code’.
systemd[1]: Failed to start Telegraf.
systemd[1]: telegraf.service: Consumed 1.164s CPU time.
systemd[1]: telegraf.service: Scheduled restart job, restart counter is at 2.
systemd[1]: Stopped Telegraf.
systemd[1]: telegraf.service: Consumed 1.164s CPU time.
systemd[1]: Starting Telegraf…
telegraf[6699]: time=“2024-08-09T10:53:32+02:00” level=warning msg=“DBUS_SESSION_BUS_ADDRESS envvar looks to be not set, this can lead to runaway dbus-daemon processes. To avoid this, set envvar DBUS_SESSION_BUS_ADDRESS=$XDG_RUNTIME_DIR/bus (if it exists) or DBUS_SESSION_BUS_ADDRESS=/dev/null.” func=“gosnowflake.(*defaultLogger).Warn” file=“log.go:244”
telegraf[6699]: 2024-08-09T08:53:32Z I! Loading config: /etc/telegraf/telegraf.conf
telegraf[6699]: 2024-08-09T08:53:32Z E! [telegraf] Error running agent: no outputs found, did you provide a valid config file?
systemd[1]: telegraf.service: Main process exited, code=exited, status=1/FAILURE
systemd[1]: telegraf.service: Failed with result ‘exit-code’.
systemd[1]: Failed to start Telegraf.

How can i fix it?

From the logs:

The default config does not come with an output defined. You need to define an output.

The two plugins I’m using are [inputs.modbus] and [outputs.influxdb_v2].

Are you sure you added them correctly and fully?

Hi, thank you very much for your reply! I think I compiled the plugins correctly because if I start telegraf with the command " telegraf --config telegraf.conf " , everything works and I can also view the graphs on Influx.

Excuse me for the question, i’m new, what do you mean by " default config" ?

You are running telegraf as a service under systemd, that means by default it will run the command in the service file. This command is:

/usr/bin/telegraf --config /etc/telegraf/telegraf.conf --configuration-directory /etc/telegraf/telegraf.conf.d

You have to tell Telegraf which config file to use, and when run as a service it will use the above by default. It seems likely that you have not updated them.

When I run the command “sudo systemctl edit telegraf” and enter “ExecStart=/usr/bin/telegraf --config /etc/telegraf/telegraf.conf --configuration-directory /etc/telegraf/telegraf.conf.d”, after having saved it tells me " Editing “/etc/systemd/system/telegraf.service.d/override.conf” canceled: temporary file is empty."

What am I doing wrong?

You should not need to edit service file, that is already the default! What you need to edit is the file at /etc/telegraf/telegraf.conf

Again, going back to your original error message, the configuration file that telegraf is trying to read, /etc/telegraf/telegraf.conf does not have any outputs. You have some telegraf.conf file somewhere that you have not specified and need to update /etc/telegraf/telegraf.conf to have the same config or replace it with your file.

Thank you very much JPower, now everything is clear!
I had two telegraf.conf files: one updated and one not!
Thanks for your time

1 Like