'Best way to reload telegraf configuration when running in a container

I'm running telegraf in a container on my Synlogy NAS. Just asking out there what is the best way to reload the configuration when I make some changes in telegraf.conf.

I have seen a suggestion to restart the whole container, here: https://hub.docker.com/_/telegraf

Like this:

$ docker restart telegraf

How about just executing a kill command with SIGHUP for the telegraf process within the container?

Something like this:

admin@Docker:~% sudo docker ps | grep telegraf
Password:
4c69a263326d        telegraf:latest                       "/entrypoint.sh tele…"   3 weeks ago         Up 20 minutes                           telegraf
admin@Docker:~% sudo docker exec -it -u 0 4c69a263326d kill -1 1
admin@Docker:~% sudo docker ps | grep telegraf
4c69a263326d        telegraf:latest                       "/entrypoint.sh tele…"   3 weeks ago         Up 21 minutes                           telegraf
admin@Docker:~% sudo docker logs --tail 10 4c69a263326d
2020-06-09T11:50:37Z I! [agent] Hang on, flushing any cached metrics before shutdown
2020-06-09T11:50:37Z I! Starting Telegraf 1.14.2
2020-06-09T11:50:37Z I! Using config file: /etc/telegraf/telegraf.conf
2020-06-09T11:50:37Z I! Loaded inputs: snmp
2020-06-09T11:50:37Z I! Loaded aggregators:
2020-06-09T11:50:37Z I! Loaded processors:
2020-06-09T11:50:37Z I! Loaded outputs: influxdb
2020-06-09T11:50:37Z I! Tags enabled: host=Docker
2020-06-09T11:50:37Z I! [agent] Config: Interval:10s, Quiet:false, Hostname:"Docker", Flush Interval:10s
2020-06-09T11:50:37Z W! [outputs.influxdb] When writing to [https://127.0.0.1:8086]: database "telegraf" creation failed: 403 Forbidden


Solution 1:[1]

Telegraf can reload the modified config itself using the --watch-config command-line option:

  --watch-config                 Telegraf will restart on local config changes. Monitor changes
                                 using either fs notifications or polling.  Valid values: 'inotify' or 'poll'.
                                 Monitoring is off by default.

Solution 2:[2]

I believe the above could work. telegraf always seems to be pid 1, so a SIGHUP to pid 1 should reload config. However I think the design is to just restart the container.

Solution 3:[3]

I followed below steps & it worked!

  1. Go inside the telegraf container using:
    "docker exec -it container_id bash"

  2. Then start telegraf service using:
    "service telegraf restart"

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 vlasta
Solution 2 MikeKulls
Solution 3 Vikas Bahuguna