Add docker stats
This commit is contained in:
@@ -7,11 +7,18 @@ import (
|
||||
"github.com/influxdb/tivan/plugins/system/ps/common"
|
||||
"github.com/influxdb/tivan/plugins/system/ps/cpu"
|
||||
"github.com/influxdb/tivan/plugins/system/ps/disk"
|
||||
"github.com/influxdb/tivan/plugins/system/ps/docker"
|
||||
"github.com/influxdb/tivan/plugins/system/ps/load"
|
||||
"github.com/influxdb/tivan/plugins/system/ps/mem"
|
||||
"github.com/influxdb/tivan/plugins/system/ps/net"
|
||||
)
|
||||
|
||||
type DockerContainerStat struct {
|
||||
Name string
|
||||
CPU *cpu.CPUTimesStat
|
||||
Mem *docker.CgroupMemStat
|
||||
}
|
||||
|
||||
type PS interface {
|
||||
LoadAvg() (*load.LoadAvgStat, error)
|
||||
CPUTimes() ([]cpu.CPUTimesStat, error)
|
||||
@@ -20,6 +27,7 @@ type PS interface {
|
||||
DiskIO() (map[string]disk.DiskIOCountersStat, error)
|
||||
VMStat() (*mem.VirtualMemoryStat, error)
|
||||
SwapStat() (*mem.SwapMemoryStat, error)
|
||||
DockerStat() ([]*DockerContainerStat, error)
|
||||
}
|
||||
|
||||
type SystemStats struct {
|
||||
@@ -156,6 +164,59 @@ func (s *SystemStats) Gather(acc plugins.Accumulator) error {
|
||||
acc.Add("swap_in", swap.Sin, swaptags)
|
||||
acc.Add("swap_out", swap.Sout, swaptags)
|
||||
|
||||
containers, err := s.ps.DockerStat()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, cont := range containers {
|
||||
tags := map[string]string{
|
||||
"docker": cont.Name,
|
||||
}
|
||||
|
||||
cts := cont.CPU
|
||||
|
||||
acc.Add("user", cts.User, tags)
|
||||
acc.Add("system", cts.System, tags)
|
||||
acc.Add("idle", cts.Idle, tags)
|
||||
acc.Add("nice", cts.Nice, tags)
|
||||
acc.Add("iowait", cts.Iowait, tags)
|
||||
acc.Add("irq", cts.Irq, tags)
|
||||
acc.Add("softirq", cts.Softirq, tags)
|
||||
acc.Add("steal", cts.Steal, tags)
|
||||
acc.Add("guest", cts.Guest, tags)
|
||||
acc.Add("guestNice", cts.GuestNice, tags)
|
||||
acc.Add("stolen", cts.Stolen, tags)
|
||||
|
||||
acc.Add("cache", cont.Mem.Cache, tags)
|
||||
acc.Add("rss", cont.Mem.RSS, tags)
|
||||
acc.Add("rss_huge", cont.Mem.RSSHuge, tags)
|
||||
acc.Add("mapped_file", cont.Mem.MappedFile, tags)
|
||||
acc.Add("swap_in", cont.Mem.Pgpgin, tags)
|
||||
acc.Add("swap_out", cont.Mem.Pgpgout, tags)
|
||||
acc.Add("page_fault", cont.Mem.Pgfault, tags)
|
||||
acc.Add("page_major_fault", cont.Mem.Pgmajfault, tags)
|
||||
acc.Add("inactive_anon", cont.Mem.InactiveAnon, tags)
|
||||
acc.Add("active_anon", cont.Mem.ActiveAnon, tags)
|
||||
acc.Add("inactive_file", cont.Mem.InactiveFile, tags)
|
||||
acc.Add("active_file", cont.Mem.ActiveFile, tags)
|
||||
acc.Add("unevictable", cont.Mem.Unevictable, tags)
|
||||
acc.Add("memory_limit", cont.Mem.HierarchicalMemoryLimit, tags)
|
||||
acc.Add("total_cache", cont.Mem.TotalCache, tags)
|
||||
acc.Add("total_rss", cont.Mem.TotalRSS, tags)
|
||||
acc.Add("total_rss_huge", cont.Mem.TotalRSSHuge, tags)
|
||||
acc.Add("total_mapped_file", cont.Mem.TotalMappedFile, tags)
|
||||
acc.Add("total_swap_in", cont.Mem.TotalPgpgIn, tags)
|
||||
acc.Add("total_swap_out", cont.Mem.TotalPgpgOut, tags)
|
||||
acc.Add("total_page_fault", cont.Mem.TotalPgFault, tags)
|
||||
acc.Add("total_page_major_fault", cont.Mem.TotalPgMajFault, tags)
|
||||
acc.Add("total_inactive_anon", cont.Mem.TotalInactiveAnon, tags)
|
||||
acc.Add("total_active_anon", cont.Mem.TotalActiveAnon, tags)
|
||||
acc.Add("total_inactive_file", cont.Mem.TotalInactiveFile, tags)
|
||||
acc.Add("total_active_file", cont.Mem.TotalActiveFile, tags)
|
||||
acc.Add("total_unevictable", cont.Mem.TotalUnevictable, tags)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -210,6 +271,35 @@ func (s *systemPS) SwapStat() (*mem.SwapMemoryStat, error) {
|
||||
return mem.SwapMemory()
|
||||
}
|
||||
|
||||
func (s *systemPS) DockerStat() ([]*DockerContainerStat, error) {
|
||||
list, err := docker.GetDockerIDList()
|
||||
if err != nil {
|
||||
if err == common.NotImplementedError {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var stats []*DockerContainerStat
|
||||
|
||||
for _, cont := range list {
|
||||
ctu, err := docker.CgroupCPUDocker(cont)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
mem, err := docker.CgroupMemDocker(cont)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
stats = append(stats, &DockerContainerStat{cont, ctu, mem})
|
||||
}
|
||||
|
||||
return stats, nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
plugins.Add("system", func() plugins.Plugin {
|
||||
return &SystemStats{ps: &systemPS{}}
|
||||
|
||||
Reference in New Issue
Block a user