From 12420db4b9e166c099b1ed8c981f56b06fad796a Mon Sep 17 00:00:00 2001 From: Cameron Sparr Date: Wed, 23 Sep 2015 14:20:15 -0700 Subject: [PATCH] docker plugin: Add docker labels as tags in Closes #90 --- plugins/system/docker.go | 3 +++ plugins/system/ps.go | 16 +++++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/plugins/system/docker.go b/plugins/system/docker.go index 463c1f317..94f8ad059 100644 --- a/plugins/system/docker.go +++ b/plugins/system/docker.go @@ -30,6 +30,9 @@ func (s *DockerStats) Gather(acc plugins.Accumulator) error { "name": cont.Name, "command": cont.Command, } + for k, v := range cont.Labels { + tags[k] = v + } cts := cont.CPU diff --git a/plugins/system/ps.go b/plugins/system/ps.go index b489ed908..e715fbd58 100644 --- a/plugins/system/ps.go +++ b/plugins/system/ps.go @@ -19,6 +19,7 @@ type DockerContainerStat struct { Id string Name string Command string + Labels map[string]string CPU *cpu.CPUTimesStat Mem *docker.CgroupMemStat } @@ -118,7 +119,7 @@ func (s *systemPS) DockerStat() ([]*DockerContainerStat, error) { opts := dc.ListContainersOptions{} - list, err := s.dockerClient.ListContainers(opts) + containers, err := s.dockerClient.ListContainers(opts) if err != nil { if _, ok := err.(*gonet.OpError); ok { return nil, nil @@ -129,23 +130,24 @@ func (s *systemPS) DockerStat() ([]*DockerContainerStat, error) { var stats []*DockerContainerStat - for _, cont := range list { - ctu, err := docker.CgroupCPUDocker(cont.ID) + for _, container := range containers { + ctu, err := docker.CgroupCPUDocker(container.ID) if err != nil { return nil, err } - mem, err := docker.CgroupMemDocker(cont.ID) + mem, err := docker.CgroupMemDocker(container.ID) if err != nil { return nil, err } - name := strings.Join(cont.Names, " ") + name := strings.Join(container.Names, " ") stats = append(stats, &DockerContainerStat{ - Id: cont.ID, + Id: container.ID, Name: name, - Command: cont.Command, + Command: container.Command, + Labels: container.Labels, CPU: ctu, Mem: mem, })