Telegraf: Ubuntu telegraf.conf use enviornment variables

Created on 22 Sep 2016  路  9Comments  路  Source: influxdata/telegraf

I am using Telegraf - version 1.0.0
I tried using environment variables in telegraf.conf but Telegraf is not replacing them.

screen shot 2016-09-22 at 2 45 57 pm

2016/09/22 09:08:13 Tags enabled: environment=$APP_ENV host=863eeea1c23b owner=$APP_OWNER stack=$APP_STACK

need more info

Most helpful comment

Cool. That worked. Thanks danielnelson. you may need to update this information in the telegraf.conf environment variables section.

All 9 comments

Are you running telegraf as a service? does the telegraf user have these env variables? try sudo -u telegraf printenv

closing for lack of updates, feel free to reopen if it's not apermission issue

Telegraf is running as a service on Ubuntu 14.04 inside a Docker container.
printenv shows the environment variables APP_ENV, APP_OWNER, APP_STACK

that doesn't answer the question of whether the env vars are accessible to the telegraf user

This is not working for me too.

I can answer your question sparrc.
I am running telegraf as a service and when I tried the command sudo -u telegraf printenv . It doesn't print the environment variables what I export.

But in the Configuration comments It says the one below,

Environment variables can be used anywhere in this config file, simply prepend
them with $. For strings the variable must be within quotes (ie, "$STR_VAR"),
for numbers and booleans they should be plain (ie, $INT_VAR, $BOOL_VAR)

Global tags can be specified here in key="value" format.
[global_tags]
dc = "us-east-1" # will tag all metrics with dc=us-east-1
rack = "1a"
Environment variables can be used as tags, and throughout the config file
user = "$USER"

If sudo -u telegraf printenv did not print the environment variables then they are not available for telegraf. How are you defining them?

I am exporting those variables through bash. Also I tried setting manually like export VPCNAME="test" and tried overriding the hostname in configuration like hostname="$VPCNAME". How we have to make the environment available for telegraf?

If you export a variable from your shell, it will only affect that shell and child shells. Try putting the definitions in /etc/default/telegraf which gets sourced when the service starts.

Cool. That worked. Thanks danielnelson. you may need to update this information in the telegraf.conf environment variables section.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

SongYg picture SongYg  路  3Comments

robert-gomes picture robert-gomes  路  3Comments

yn1v picture yn1v  路  3Comments

efficks picture efficks  路  3Comments

mrcheeky123 picture mrcheeky123  路  3Comments