Hey all over there,
I have an unexpected behavior when using $HOSTNAME as a tag in telegraf:
So $HOSTNAME is used as string, although other env vars are replaced by their content.
root@docker2:~# head /etc/telegraf/telegraf.conf
[global_tags]
datacenter = "$DATACENTER"
fqdn = "$FQDN"
location = "$LOCATION"
engine = "$HOSTNAME"
# Configuration for telegraf agent
[agent]
interval = "15s"
round_interval = true
root@docker2:~# telegraf --config /etc/telegraf/telegraf.conf --config-directory /etc/telegraf/telegraf.d/ --input-filter cpu --test
* Plugin: inputs.cpu, Collection 1
* Plugin: inputs.cpu, Collection 2
> cpu,location=development,host=docker2,engine=$HOSTNAME,datacenter=mbr,fqdn=docker2.mbr.intern,cpu=cpu0 usage_irq=0,usage_softirq=0,usage_steal=0,usage_guest=0,usage_guest_nice=0,usage_user=0,usage_idle=98.03921568448419,usage_iowait=0,usage_system=1.9607843136879006,usage_nice=0 1507314594000000000
> cpu,cpu=cpu1,engine=$HOSTNAME,datacenter=mbr,fqdn=docker2.mbr.intern,location=development,host=docker2 usage_system=0,usage_iowait=0,usage_irq=0,usage_guest=0,usage_guest_nice=0,usage_user=0,usage_idle=100,usage_nice=0,usage_softirq=0,usage_steal=0 1507314594000000000
> cpu,engine=$HOSTNAME,cpu=cpu2,datacenter=mbr,fqdn=docker2.mbr.intern,location=development,host=docker2 usage_nice=0,usage_iowait=0,usage_irq=0,usage_guest=0,usage_guest_nice=0,usage_user=0,usage_system=0,usage_steal=0,usage_idle=100,usage_softirq=0 1507314594000000000
> cpu,host=docker2,cpu=cpu3,engine=$HOSTNAME,datacenter=mbr,fqdn=docker2.mbr.intern,location=development usage_nice=0,usage_system=0,usage_idle=100,usage_irq=0,usage_softirq=0,usage_steal=0,usage_guest=0,usage_guest_nice=0,usage_user=0,usage_iowait=0 1507314594000000000
> cpu,engine=$HOSTNAME,datacenter=mbr,fqdn=docker2.mbr.intern,location=development,host=docker2,cpu=cpu-total usage_iowait=0,usage_user=0,usage_idle=99.50248756460951,usage_irq=0,usage_softirq=0,usage_steal=0,usage_guest=0,usage_guest_nice=0,usage_system=0.4975124378339072,usage_nice=0 1507314594000000000
root@docker2:~# echo $HOSTNAME
docker2
root@docker2:~# telegraf version
Telegraf v1.4.1 (git: release-1.4 2de7aa23d7d3c3bcf639d417129ab7c17d83399b)
Telegraf is running natively on the docker host here and not in a docker container.
//edited:
When using without " , an error occures, which is expected, of course:
root@docker2:~# head /etc/telegraf/telegraf.conf
[global_tags]
datacenter = "$DATACENTER"
fqdn = "$FQDN"
location = "$LOCATION"
engine = $HOSTNAME
# Configuration for telegraf agent
[agent]
interval = "15s"
round_interval = true
root@docker2:~# telegraf --config /etc/telegraf/telegraf.conf --config-directory /etc/telegraf/telegraf.d/ --input-filter cpu --test
2017/10/06 20:43:33 E! Error parsing /etc/telegraf/telegraf.conf, toml: line 5: parse error
//edited:
Just commented the (very old) issue here: Hostname is not passed as a tag · Issue #29 · influxdata/telegraf · GitHub