Skip to main content

Configuring Telegraf

To configure Telegraf to collect metrics from your application or service, follow the steps below.

1. Create a Telegraf Configuration File

Create a new configuration file in the /etc/telegraf/telegraf.d/ directory. For example, you might name it DaFT.conf.

Add the following content to the file:

[[inputs.http]]
  name = "<identifier>"
  urls = ["http://<YOUR_HOST>/<identifier>/telegraf"]
  method = "GET"
  response_timeout = "55s"
  interval = "1m"
  • Replace <identifier> with a meaningful name for your input, such as my-application.
  • Replace <YOUR_HOST> with the hostname or IP address of your target service.

2. Apply the Configuration

After saving the configuration file, reload the Telegraf service to apply the changes:

systemctl reload telegraf

Telegraf will now begin collecting metrics from the configured endpoint.


Troubleshooting & Common Mistakes

Here are some common issues you might encounter, along with tips to resolve them:

Incorrect File Location or Permissions

Ensure your .conf file is placed in the correct directory:
/etc/telegraf/telegraf.d/

Also, verify the file has the proper read permissions for the Telegraf service.

Missing Port Number

Do not forget to specify the port if your application is not running on the default HTTP port (80).

Example:

urls = ["http://example.com:8080/my-application/telegraf"]

Wrong URL Path

Confirm the path in the urls field matches the endpoint your application exposes. Test manually with:

curl http://<YOUR_HOST>/<identifier>/telegraf

If you receive a proper metrics response, the URL is correct.

Forgetting to Reload Telegraf

Telegraf does not automatically pick up new configurations. Always reload the service:

systemctl reload telegraf

Timeout Too Short

If your service takes a bit longer to respond, consider increasing the response_timeout value.

Useful Tip: Validate Configuration

Before reloading, you can check the validity of your Telegraf config:

telegraf --config /etc/telegraf/telegraf.d/DaFT.conf --test

This will execute the config and show the output, helping you confirm everything is working as expected.