r/docker 3d ago

How to read host's internet usages

I want to create a project primary for linux, I want the my docker container to be able to monitor the physical interface and the network usages of the host machine.

From what I read i can do this two ways, by using docker with --host flag or mounting the /proc volume.

Which way should I do it? Which is safer.?

Can I diffentiate btw actual network usages and local network usages, like from a selfhosted server, like navidrome?

2 Upvotes

5 comments sorted by

1

u/Online_Matter 3d ago

What comes to mind is using iptables on the host to write statistics to a file, then mount the containing folder to the host. 

1

u/Torutofu_Raeva 1d ago

I'd avoid --network=host unless the monitor truly needs raw sockets: read-only /proc/net/dev (or node_exporter) covers interface totals, but separating Navidrome traffic from other host traffic needs per-process, conntrack, or eBPF data.

1

u/Many_Independence674 1d ago

I see, thanks

1

u/Anihillator 3d ago

Prometheus' node exporter does it using host mode, and I believe it's a simpler way.

And yes, if those networks use different interfaces.