Allow path to net/dev to not be under HOST_PROC
Is your feature request related to a problem? Please describe. Running in a kubernetes space, to access the host's /proc/net requires presenting /proc/net as an alternative, such as /tmp/net. What I can't do (for example), is mount /proc as /tmp/proc and then /proc/net under /tmp/proc/net - not allowed as /proc can't be mounted under /proc.
Describe the solution you'd like I'd like there to be a separate environment variable for /proc/net so that /proc/net/dev can be accessed from within a Kubernetes context.
Describe alternatives you've considered I've tried running a daemonSet in Kubernetes with various mount options but wherever I mount /proc, the OS clobbers what I can see in /proc/net/dev. The only solution appears to be to mount /proc/net somewhere else but I then need to be able to specify a path to that alternate bit of /proc.
Additional context I'm attempting to run telegraf as a daemonSet in kubernetes to report on system statistics. It can do so for disk, memory, cpu, but not network.
Something like this?
diff --git a/internal/common/common.go b/internal/common/common.go
index 5e25e50..f5644ec 100644
--- a/internal/common/common.go
+++ b/internal/common/common.go
@@ -423,6 +423,10 @@ func HostProcMountInfoWithContext(ctx context.Context, combineWith ...string) st
return GetEnvWithContext(ctx, "HOST_PROC_MOUNTINFO", "", combineWith...)
}
+func HostProcNetInfoWithContext(ctx context.Context, combineWith ...string) string {
+ return GetEnvWithContext(ctx, "HOST_PROC_NETINFO", "/proc", combineWith...)
+}
+
func HostSysWithContext(ctx context.Context, combineWith ...string) string {
return GetEnvWithContext(ctx, "HOST_SYS", "/sys", combineWith...)
}
diff --git a/net/net_linux.go b/net/net_linux.go
index 20ca547..c788869 100644
--- a/net/net_linux.go
+++ b/net/net_linux.go
@@ -49,7 +49,7 @@ func IOCounters(pernic bool) ([]IOCountersStat, error) {
}
func IOCountersWithContext(ctx context.Context, pernic bool) ([]IOCountersStat, error) {
- filename := common.HostProcWithContext(ctx, "net/dev")
+ filename := common.HostProcNetInfoWithContext(ctx, "net/dev")
return IOCountersByFileWithContext(ctx, pernic, filename)
}