Repository navigation
Labels
bugunexpected problem or unintended behavior
Description
Relevant telegraf.conf
[agent]
...
statefile = "/telegraf_state/statefile"
...
# Read logging output from the Docker engine
[[inputs.docker_log]]
from_beginning = false
container_state_include = ["created", "restarting", "running", "removing"]
source_tag = true
[[outputs.file]]
files = ["stdout"]
data_format = "json"Logs from Telegraf
telegraf-1 | id: cannot find name for group ID 988
telegraf-1 | 2025-11-25T19:27:24Z I! Loading config: /etc/telegraf/telegraf.conf
telegraf-1 | 2025-11-25T19:27:24Z I! Starting Telegraf 1.36.4 brought to you by InfluxData the makers of InfluxDB
telegraf-1 | 2025-11-25T19:27:24Z I! Available plugins: 239 inputs, 9 aggregators, 35 processors, 26 parsers, 65 outputs, 6 secret-stores
telegraf-1 | 2025-11-25T19:27:24Z I! Loaded inputs: cpu disk diskio docker docker_log internal kernel mem processes swap system temp
telegraf-1 | 2025-11-25T19:27:24Z I! Loaded aggregators:
telegraf-1 | 2025-11-25T19:27:24Z I! Loaded processors:
telegraf-1 | 2025-11-25T19:27:24Z I! Loaded secretstores:
telegraf-1 | 2025-11-25T19:27:24Z I! Loaded outputs: http
telegraf-1 | 2025-11-25T19:27:24Z I! Tags enabled: host=november
telegraf-1 | 2025-11-25T19:27:24Z I! [agent] Config: Interval:1m0s, Quiet:false, Hostname:"november", Flush Interval:1m5s
telegraf-1 | 2025-11-25T19:27:24Z W! [agent] The default value of 'skip_processors_after_aggregators' will change to 'true' with Telegraf v1.40.0! If you need the current default behavior, please explicitly set the option to 'false'!
telegraf-1 | 2025-11-25T19:27:24Z D! [agent] Initializing plugins
telegraf-1 | 2025-11-25T19:27:24Z D! [agent] Initializing plugin states
telegraf-1 | 2025-11-25T19:27:24Z D! [agent] Connecting outputs
telegraf-1 | 2025-11-25T19:27:24Z D! [agent] Attempting connection to [outputs.http]
telegraf-1 | 2025-11-25T19:27:24Z D! [agent] Successfully connected to outputs.http
telegraf-1 | 2025-11-25T19:27:24Z D! [agent] Starting service inputs
telegraf-1 | 2025-11-25T19:28:00Z D! [inputs.disk] [SystemPS] => unable to get disk usage ("/hostfs/run/docker/netns/71becc55e5ea"): permission denied
telegraf-1 | 2025-11-25T19:28:00Z D! [inputs.disk] [SystemPS] => unable to get disk usage ("/hostfs/run/docker/netns/418befc732bb"): permission denied
telegraf-1 | 2025-11-25T19:28:00Z D! [inputs.disk] [SystemPS] => unable to get disk usage ("/hostfs/run/docker/netns/5c7fd9cf95af"): permission denied
telegraf-1 | 2025-11-25T19:28:00Z D! [inputs.disk] [SystemPS] => unable to get disk usage ("/hostfs/run/docker/netns/6415ee35e679"): permission denied
telegraf-1 | 2025-11-25T19:28:00Z D! [inputs.disk] [SystemPS] => unable to get disk usage ("/hostfs/run/docker/netns/e83a954390a8"): permission denied
telegraf-1 | 2025-11-25T19:28:00Z D! [inputs.disk] [SystemPS] => unable to get disk usage ("/hostfs/run/docker/netns/a6d42e49677f"): permission denied
telegraf-1 | 2025-11-25T19:28:00Z D! [inputs.system] Reading users: open /hostfs/var/run/utmp: no such file or directory
telegraf-1 | 2025-11-25T19:28:29Z D! [outputs.http] Wrote batch of 197 metrics in 153.718499ms
telegraf-1 | 2025-11-25T19:28:29Z D! [outputs.http] Buffer fullness: 0 / 1000000 metrics
System info
Telegraf 1.36.4, Ubuntu 24.04, Docker version 29.0.4, build 3247a5a
Docker
services:
telegraf:
image: "telegraf:1.36.4"
group_add:
- "988" # docker group to query docker socket
privileged: true
restart: unless-stopped
volumes:
- ./telegraf.conf:/etc/telegraf/telegraf.conf:ro
- ./telegraf_state:/telegraf_state
- /:/hostfs:ro
- /run/udev:/run/udev:ro # -> diskio
- /var/run/docker.sock:/var/run/docker.sock:ro # -> docker_log
environment:
HOST_ETC: /hostfs/etc
HOST_PROC: /hostfs/proc
HOST_SYS: /hostfs/sys
HOST_VAR: /hostfs/var
HOST_RUN: /hostfs/run
HOST_MOUNT_PREFIX: /hostfs
HOSTNAME: "november"
command: ["telegraf", "--config", "/etc/telegraf/telegraf.conf"]
Steps to reproduce
- Deploy a server with docker installed
- Create the compose file as described above
- Create a folder "telegraf_state" in the directory where the compose.yml resides and give it group and owner of 999 (telegraf inside the container)
- Create the "statefile" with the content of "{}" and same permission as the folder
- Start the stack
Expected behavior
- After the first start you will see no logging of telegraf about a missing statefile which means it could read it and start successfully.
- After the first container starts it will write the initial offset in the statefile
- Now produce logs on a different container
- The statefile should after every submitted line update the statefile to the last read offset (in the case of this plugin the timestamp)
Actual behavior
It does not update the timestamp and after every restart it sends all logs of the container again from this once written timestamp on.
Metrics arrive successfully and no collection errors are logged, just the persistence seems to be broken.
Additional info
It is not connected to docker 29 because I fight with this behavior already for months.
Restarts produce these kinds of spikes for restarts in this graph you can see nine restarts which afterwards always send logs from containers running for multiple days.

Activity
[-]inputs.docker_log only persists state once at start then stales[/-][+][inputs.docker_log] only persists state once at start then stales[/+]srebhan commentedon Dec 4, 2025
@iCaotix states are written on shutdown of Telegraf so you should see the update in the file after stopping Telegraf in the container. Can you please post the (redacted) log output of the Telegraf shutdown?
iCaotix commentedon Dec 4, 2025
@srebhan
The log says that the states persisted without logging an error but the statefile still is untouched
iCaotix commentedon Jan 7, 2026
@srebhan
After further experimenting I found out that the statefile gets written when I change the way the container is restarted / updated.
Usually I did normal
docker compose up -dordocker compose downto restart with a new version. In that case the statefile is not written at all. Probably the compose down has a race condition with persisting plugin state.So I tried a
docker compose stopfirst and after that telegraf writes something to the file and also the file modified time is updated. But the content is somehow offset. Sometimes only by a couple hours, but some containers are dated back by multiple days. And it's not the case that the container didn't log something in that time. After the restart multiple log lines are sent again which were already sent before the restart.I tried adding
to the compose file which now consistently updates the statefile (even with compose down without prior explicit stopping) but the content issue still exists.
Probably a fix would be to allow starting from the current timestamp if persistence is disabled instead of always from unix timestamp 0
See code in
telegraf/plugins/inputs/docker_log/docker_log.go
Lines 284 to 291 in b89f119
Which could be changed to start from "now" if there is no state to load or the load fails.