Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow path to net/dev to not be under HOST_PROC #1625

Open
yellowpattern opened this issue Apr 17, 2024 · 0 comments
Open

Allow path to net/dev to not be under HOST_PROC #1625

yellowpattern opened this issue Apr 17, 2024 · 0 comments

Comments

@yellowpattern
Copy link

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)
 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant