When metricbeat is used on a container to capture system metrics with the hostfs or --system.hostfs options set, it throws an error when trying to get its own cpu/mem stats. It seems that metricbeat is trying to gather self-monitoring data from its PID in the hostfs instead of the container.
Simple reproducer:
cat <<'EOF' > repro.yml
logging.level: error
metricbeat.modules:
- module: system
metricsets: ["cpu"]
hostfs: "/hostfs"
period: 10s
output.console:
pretty: true
EOF
docker run --rm \
--name=metricbeat \
--volume="$(pwd)/repro.yml:/usr/share/metricbeat/metricbeat.yml:ro" \
--volume="/var/run/docker.sock:/var/run/docker.sock:ro" \
--volume="/sys/fs/cgroup:/hostfs/sys/fs/cgroup:ro" \
--volume="/proc:/hostfs/proc:ro" \
--volume="/:/hostfs:ro" \
docker.elastic.co/beats/metricbeat:9.3.0 metricbeat -e
Error message:
{"log.level":"error","@timestamp":"2026-02-04T16:35:44.919Z","log.logger":"metrics","log.origin":{"function":"github.com/elastic/elastic-agent-system-metrics/report.FDUsageReporter.func2","file.name":"report/metrics_file_descriptors.go","file.line":62},"message":"Error while retrieving open FDs information: %vopen /hostfs/proc/7/fd: permission denied","service.name":"metricbeat","ecs.version":"1.6.0"}
I was able to narrow down the version where the error can be reproduced:
- v8.19.4 and later
- v9.1.4 and later
- v9.2.0 and later
- v9.3.0 and later
- main
To test this with local changes, run:
. ./dev-tools/env/bin/activate
cd metricbeat
docker rmi docker.elastic.co/beats/metricbeat-oss:9.4.0 --force; PLATFORMS=linux/amd64 PACKAGES=docker mage package
Then try re-running the repro with the docker.elastic.co/beats/metricbeat-oss:9.4.0 image.
When metricbeat is used on a container to capture system metrics with the
hostfsor--system.hostfsoptions set, it throws an error when trying to get its own cpu/mem stats. It seems that metricbeat is trying to gather self-monitoring data from its PID in the hostfs instead of the container.Simple reproducer:
Error message:
I was able to narrow down the version where the error can be reproduced:
To test this with local changes, run:
Then try re-running the repro with the
docker.elastic.co/beats/metricbeat-oss:9.4.0image.