Telegraf inputs.net plugin not working inside docker container

Hi,

I am trying to run telegraf inside a docker container to monitor the host system metrics and have mounted the hosts file system into the container as suggested in the documentation.

The CPU, memory, disk plugins are correctly collecting metrics for the host system, but the net plugin is collecting metrics about the container not the host. This can be seen by running telegraf on the host system and comparing the metrics.

Is this expected or am I missing some config, there was nothing suggested in the docs for the plugin?

This is my docker compose config:

telegraf-system:
    image: docker.io/library/telegraf:1.21.4
    container_name: telegraf-system
    restart: always
    privileged: true
    volumes:
      - ./telegraf/telegraf.conf:/etc/telegraf/telegraf.conf:ro
      - /var/run/docker.sock:/var/run/docker.sock
      - /:/hostfs:ro
      - /run/udev:/run/udev:ro
    depends_on:
      - "influxdb"
    environment:
      - HOST_MOUNT_PREFIX=/hostfs
      - HOST_ETC=/hostfs/etc
      - HOST_PROC=/hostfs/proc
      - HOST_SYS=/hostfs/sys
      - HOST_VAR=/hostfs/var
      - HOST_RUN=/hostfs/run

Hello @jamesgibo,
I found this:

Specifically,

NOTE: It doesn’t work for netstat. Telegraf’s inputs.netstat plugin can report values only for the container. It cannot report on the host. It does not use the HOST_PROC environmnet variable. This is because the plugin uses the gopsutil library which executes the lsof command:
gopsutil/common_unix.go at a3b23c5ccf4fb7b33d319fcaad53d7777907f4e1 · shirou/gopsutil · GitHub
And lsof always opens /proc . The string is hard-coded:
lsof/dproc.c at e4bc415f0c4659af44ed4a2ef69f87e88a8c6a0a · lsof-org/lsof · GitHub

Thanks for the response, that’s a shame. As the network metrics are key for monitoring my application I will run the telegraf app natively.

Might be worth adding a note about that to the inputs.netstat plugin docs.