telegraf/plugins/inputs/system/docker.go

90 lines
2.5 KiB
Go
Raw Normal View History

2015-08-27 19:28:49 +00:00
// +build linux
2015-05-18 23:01:42 +00:00
package system
import (
"fmt"
"github.com/influxdb/telegraf/plugins/inputs"
2015-05-18 23:01:42 +00:00
)
type DockerStats struct {
ps PS
}
func (_ *DockerStats) Description() string {
return "Read metrics about docker containers"
}
func (_ *DockerStats) SampleConfig() string { return "" }
2016-01-07 20:39:43 +00:00
func (s *DockerStats) Gather(acc inputs.Accumulator) error {
2015-05-18 23:01:42 +00:00
containers, err := s.ps.DockerStat()
if err != nil {
return fmt.Errorf("error getting docker info: %s", err)
}
for _, cont := range containers {
tags := map[string]string{
"id": cont.Id,
"name": cont.Name,
"command": cont.Command,
}
for k, v := range cont.Labels {
tags[k] = v
}
2015-05-18 23:01:42 +00:00
cts := cont.CPU
2015-12-11 20:07:32 +00:00
fields := map[string]interface{}{
"user": cts.User,
"system": cts.System,
"idle": cts.Idle,
"nice": cts.Nice,
"iowait": cts.Iowait,
"irq": cts.Irq,
"softirq": cts.Softirq,
"steal": cts.Steal,
"guest": cts.Guest,
"guest_nice": cts.GuestNice,
2015-05-18 23:01:42 +00:00
2015-12-11 20:07:32 +00:00
"cache": cont.Mem.Cache,
"rss": cont.Mem.RSS,
"rss_huge": cont.Mem.RSSHuge,
"mapped_file": cont.Mem.MappedFile,
"swap_in": cont.Mem.Pgpgin,
"swap_out": cont.Mem.Pgpgout,
"page_fault": cont.Mem.Pgfault,
"page_major_fault": cont.Mem.Pgmajfault,
"inactive_anon": cont.Mem.InactiveAnon,
"active_anon": cont.Mem.ActiveAnon,
"inactive_file": cont.Mem.InactiveFile,
"active_file": cont.Mem.ActiveFile,
"unevictable": cont.Mem.Unevictable,
"memory_limit": cont.Mem.HierarchicalMemoryLimit,
"total_cache": cont.Mem.TotalCache,
"total_rss": cont.Mem.TotalRSS,
"total_rss_huge": cont.Mem.TotalRSSHuge,
"total_mapped_file": cont.Mem.TotalMappedFile,
"total_swap_in": cont.Mem.TotalPgpgIn,
"total_swap_out": cont.Mem.TotalPgpgOut,
"total_page_fault": cont.Mem.TotalPgFault,
"total_page_major_fault": cont.Mem.TotalPgMajFault,
"total_inactive_anon": cont.Mem.TotalInactiveAnon,
"total_active_anon": cont.Mem.TotalActiveAnon,
"total_inactive_file": cont.Mem.TotalInactiveFile,
"total_active_file": cont.Mem.TotalActiveFile,
"total_unevictable": cont.Mem.TotalUnevictable,
}
acc.AddFields("docker", fields, tags)
2015-05-18 23:01:42 +00:00
}
return nil
}
func init() {
2016-01-07 20:39:43 +00:00
inputs.Add("docker", func() inputs.Input {
2015-05-18 23:01:42 +00:00
return &DockerStats{ps: &systemPS{}}
})
}