docker plugin: Add docker labels as tags in

Closes #90
This commit is contained in:
Cameron Sparr 2015-09-23 14:20:15 -07:00
parent aad6a7e262
commit 12420db4b9
2 changed files with 12 additions and 7 deletions

View File

@ -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

View File

@ -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,
})