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, "name": cont.Name,
"command": cont.Command, "command": cont.Command,
} }
for k, v := range cont.Labels {
tags[k] = v
}
cts := cont.CPU cts := cont.CPU

View File

@ -19,6 +19,7 @@ type DockerContainerStat struct {
Id string Id string
Name string Name string
Command string Command string
Labels map[string]string
CPU *cpu.CPUTimesStat CPU *cpu.CPUTimesStat
Mem *docker.CgroupMemStat Mem *docker.CgroupMemStat
} }
@ -118,7 +119,7 @@ func (s *systemPS) DockerStat() ([]*DockerContainerStat, error) {
opts := dc.ListContainersOptions{} opts := dc.ListContainersOptions{}
list, err := s.dockerClient.ListContainers(opts) containers, err := s.dockerClient.ListContainers(opts)
if err != nil { if err != nil {
if _, ok := err.(*gonet.OpError); ok { if _, ok := err.(*gonet.OpError); ok {
return nil, nil return nil, nil
@ -129,23 +130,24 @@ func (s *systemPS) DockerStat() ([]*DockerContainerStat, error) {
var stats []*DockerContainerStat var stats []*DockerContainerStat
for _, cont := range list { for _, container := range containers {
ctu, err := docker.CgroupCPUDocker(cont.ID) ctu, err := docker.CgroupCPUDocker(container.ID)
if err != nil { if err != nil {
return nil, err return nil, err
} }
mem, err := docker.CgroupMemDocker(cont.ID) mem, err := docker.CgroupMemDocker(container.ID)
if err != nil { if err != nil {
return nil, err return nil, err
} }
name := strings.Join(cont.Names, " ") name := strings.Join(container.Names, " ")
stats = append(stats, &DockerContainerStat{ stats = append(stats, &DockerContainerStat{
Id: cont.ID, Id: container.ID,
Name: name, Name: name,
Command: cont.Command, Command: container.Command,
Labels: container.Labels,
CPU: ctu, CPU: ctu,
Mem: mem, Mem: mem,
}) })