From 1fe5c65fd43c45180cdb0f9da91acce55606c21d Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Tue, 14 Jun 2016 11:36:59 +0100 Subject: [PATCH] Add kernel version, Docker version and awsvpc setting to checkpoint info --- common/docker/client.go | 9 +++++++++ prog/weaver/checkpoint.go | 26 +++++++++++++++++++++++++- prog/weaver/main.go | 9 +++++++-- 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/common/docker/client.go b/common/docker/client.go index 028bf05d..00100186 100644 --- a/common/docker/client.go +++ b/common/docker/client.go @@ -84,6 +84,15 @@ func (c *Client) Info() string { return fmt.Sprintf("Docker API on %s: %v", c.Endpoint(), env) } +func (c *Client) DockerVersion() string { + if env, err := c.Version(); err == nil { + if v, found := env.Map()["Version"]; found { + return v + } + } + return "unknown" +} + // AddObserver adds an observer for docker events func (c *Client) AddObserver(ob ContainerObserver) error { go func() { diff --git a/prog/weaver/checkpoint.go b/prog/weaver/checkpoint.go index 831babda..fac1b089 100644 --- a/prog/weaver/checkpoint.go +++ b/prog/weaver/checkpoint.go @@ -2,6 +2,7 @@ package main import ( "sync/atomic" + "syscall" "time" "github.com/weaveworks/go-checkpoint" @@ -14,7 +15,7 @@ const ( updateCheckPeriod = 6 * time.Hour ) -func checkForUpdates() { +func checkForUpdates(dockerVersion string, network string) { newVersion.Store("") handleResponse := func(r *checkpoint.CheckResponse, err error) { @@ -29,11 +30,34 @@ func checkForUpdates() { } } + var uts syscall.Utsname + syscall.Uname(&uts) + flags := map[string]string{ + "docker-version": dockerVersion, + "kernel-version": charsToString(uts.Release[:]), + } + if network != "" { + flags["network"] = network + } + // Start background version checking params := checkpoint.CheckParams{ Product: "weave-net", Version: version, SignatureFile: "", + Flags: flags, } checker = checkpoint.CheckInterval(¶ms, updateCheckPeriod, handleResponse) } + +func charsToString(ca []int8) string { + s := make([]byte, len(ca)) + i := 0 + for ; i < len(ca); i++ { + if ca[i] == 0 { + break + } + s[i] = uint8(ca[i]) + } + return string(s[:i]) +} diff --git a/prog/weaver/main.go b/prog/weaver/main.go index 74f9662c..59315d43 100644 --- a/prog/weaver/main.go +++ b/prog/weaver/main.go @@ -204,8 +204,6 @@ func main() { Log.Println("Command line options:", options()) - checkForUpdates() - if prof != "" { defer profile.Start(profile.CPUProfile, profile.ProfilePath(prof), profile.NoShutdownHook).Stop() } @@ -257,6 +255,13 @@ func main() { } dockerCli = dc } + + network := "" + if isAWSVPC { + network = "awsvpc" + } + checkForUpdates(dockerCli.DockerVersion(), network) + observeContainers := func(o docker.ContainerObserver) { if dockerCli != nil { if err := dockerCli.AddObserver(o); err != nil {