diff options
Diffstat (limited to 'src/go/collectors/go.d.plugin/pkg/dockerhost/dockerhost.go')
-rw-r--r-- | src/go/collectors/go.d.plugin/pkg/dockerhost/dockerhost.go | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/go/collectors/go.d.plugin/pkg/dockerhost/dockerhost.go b/src/go/collectors/go.d.plugin/pkg/dockerhost/dockerhost.go new file mode 100644 index 000000000..eb26b18fa --- /dev/null +++ b/src/go/collectors/go.d.plugin/pkg/dockerhost/dockerhost.go @@ -0,0 +1,23 @@ +// SPDX-License-Identifier: GPL-3.0-or-later + +package dockerhost + +import ( + "fmt" + "os" + "strings" +) + +func FromEnv() string { + addr := os.Getenv("DOCKER_HOST") + if addr == "" { + return "" + } + if strings.HasPrefix(addr, "tcp://") || strings.HasPrefix(addr, "unix://") { + return addr + } + if strings.HasPrefix(addr, "/") { + return fmt.Sprintf("unix://%s", addr) + } + return fmt.Sprintf("tcp://%s", addr) +} |