Hosts hostname in docker swarm mode for telegraf


What would be the easiest way to get the hosts hostname to telegraf container in docker swarm mode? The stack yml can’t get the hosts hostname in swarm mode. Or if you mount the /etc/hostname to the container, how can you get that info to telegraf?

A quick look at the os.Hostname() call in Go shows that it reads /proc/sys/kernel/hostname, I think it is not safe to mount the hosts /proc on the containers /proc though, so maybe it is better to set an environment variable and use that in the Telegraf config:

  hostname = "${ENGINE_HOST}

Then maybe you can add this environment variable when starting the container, not sure how to do this with docker swarm but using plain docker:

 docker run -e ENGINE_HOST=$(hostname) telegraf env


Try to following your advices , but in a swarm mode based on docker EE . I’m not able to get the hosts hostname when I’m running a telegraf container.


I tried also to map the etc/hostname and the /proc/sys/kernel/hosntame through an env variable HOSTNAME=$(cat /etc/hostname) but Influx did not interpret the bash output.

Please some one can give some feedback ?