Skip to content

Commit

Permalink
docker plugin: Add docker labels as tags in
Browse files Browse the repository at this point in the history
Closes #90
  • Loading branch information
sparrc committed Sep 23, 2015
1 parent aad6a7e commit 12420db
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
3 changes: 3 additions & 0 deletions plugins/system/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 9 additions & 7 deletions plugins/system/ps.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type DockerContainerStat struct {
Id string
Name string
Command string
Labels map[string]string
CPU *cpu.CPUTimesStat
Mem *docker.CgroupMemStat
}
Expand Down Expand Up @@ -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
Expand All @@ -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,
})
Expand Down

0 comments on commit 12420db

Please sign in to comment.