From 07261e885f1eb4c78b9491849b343d86c970adfc Mon Sep 17 00:00:00 2001 From: Evan Phoenix Date: Mon, 6 Apr 2015 16:02:58 -0700 Subject: [PATCH] Fix docker stats --- plugins/system/ps/docker/docker.go | 32 ++++++++++++++++ plugins/system/ps/docker/docker_linux.go | 33 +---------------- plugins/system/ps/docker/docker_notlinux.go | 41 +++++++++++++++++++++ 3 files changed, 74 insertions(+), 32 deletions(-) create mode 100644 plugins/system/ps/docker/docker.go create mode 100644 plugins/system/ps/docker/docker_notlinux.go diff --git a/plugins/system/ps/docker/docker.go b/plugins/system/ps/docker/docker.go new file mode 100644 index 000000000..bc284f01b --- /dev/null +++ b/plugins/system/ps/docker/docker.go @@ -0,0 +1,32 @@ +package docker + +type CgroupMemStat struct { + ContainerID string `json:"container_id"` + Cache uint64 `json:"cache"` + RSS uint64 `json:"rss"` + RSSHuge uint64 `json:"rss_huge"` + MappedFile uint64 `json:"mapped_file"` + Pgpgin uint64 `json:"pgpgin"` + Pgpgout uint64 `json:"pgpgout"` + Pgfault uint64 `json:"pgfault"` + Pgmajfault uint64 `json:"pgmajfault"` + InactiveAnon uint64 `json:"inactive_anon"` + ActiveAnon uint64 `json:"active_anon"` + InactiveFile uint64 `json:"inactive_file"` + ActiveFile uint64 `json:"active_file"` + Unevictable uint64 `json:"unevictable"` + HierarchicalMemoryLimit uint64 `json:"hierarchical_memory_limit"` + TotalCache uint64 `json:"total_cache"` + TotalRSS uint64 `json:"total_rss"` + TotalRSSHuge uint64 `json:"total_rss_huge"` + TotalMappedFile uint64 `json:"total_mapped_file"` + TotalPgpgIn uint64 `json:"total_pgpgin"` + TotalPgpgOut uint64 `json:"total_pgpgout"` + TotalPgFault uint64 `json:"total_pgfault"` + TotalPgMajFault uint64 `json:"total_pgmajfault"` + TotalInactiveAnon uint64 `json:"total_inactive_anon"` + TotalActiveAnon uint64 `json:"total_active_anon"` + TotalInactiveFile uint64 `json:"total_inactive_file"` + TotalActiveFile uint64 `json:"total_active_file"` + TotalUnevictable uint64 `json:"total_unevictable"` +} diff --git a/plugins/system/ps/docker/docker_linux.go b/plugins/system/ps/docker/docker_linux.go index c8e19fc12..3dd1cdfcb 100644 --- a/plugins/system/ps/docker/docker_linux.go +++ b/plugins/system/ps/docker/docker_linux.go @@ -13,37 +13,6 @@ import ( cpu "github.com/shirou/gopsutil/cpu" ) -type CgroupMemStat struct { - ContainerID string `json:"container_id"` - Cache uint64 `json:"cache"` - RSS uint64 `json:"rss"` - RSSHuge uint64 `json:"rss_huge"` - MappedFile uint64 `json:"mapped_file"` - Pgpgin uint64 `json:"pgpgin"` - Pgpgout uint64 `json:"pgpgout"` - Pgfault uint64 `json:"pgfault"` - Pgmajfault uint64 `json:"pgmajfault"` - InactiveAnon uint64 `json:"inactive_anon"` - ActiveAnon uint64 `json:"active_anon"` - InctiveFile uint64 `json:"inactive_file"` - ActiveFile uint64 `json:"active_file"` - Unevictable uint64 `json:"unevictable"` - HierarchicalMemoryLimit uint64 `json:"hierarchical_memory_limit"` - TotalCache uint64 `json:"total_cache"` - TotalRSS uint64 `json:"total_rss"` - TotalRSSHuge uint64 `json:"total_rss_huge"` - TotalMappedFile uint64 `json:"total_mapped_file"` - TotalPgpgIn uint64 `json:"total_pgpgin"` - TotalPgpgOut uint64 `json:"total_pgpgout"` - TotalPgFault uint64 `json:"total_pgfault"` - TotalPgMajFault uint64 `json:"total_pgmajfault"` - TotalInactiveAnon uint64 `json:"total_inactive_anon"` - TotalActiveAnon uint64 `json:"total_active_anon"` - TotalInactiveFile uint64 `json:"total_inactive_file"` - TotalActiveFile uint64 `json:"total_active_file"` - TotalUnevictable uint64 `json:"total_unevictable"` -} - // GetDockerIDList returnes a list of DockerID. // This requires certain permission. func GetDockerIDList() ([]string, error) { @@ -145,7 +114,7 @@ func CgroupMem(containerid string, base string) (*CgroupMemStat, error) { case "active_anon": ret.ActiveAnon = v case "inactive_file": - ret.InctiveFile = v + ret.InactiveFile = v case "active_file": ret.ActiveFile = v case "unevictable": diff --git a/plugins/system/ps/docker/docker_notlinux.go b/plugins/system/ps/docker/docker_notlinux.go new file mode 100644 index 000000000..fa19d886f --- /dev/null +++ b/plugins/system/ps/docker/docker_notlinux.go @@ -0,0 +1,41 @@ +// +build !linux + +package docker + +import ( + "encoding/json" + + "github.com/influxdb/tivan/plugins/system/ps/common" + "github.com/influxdb/tivan/plugins/system/ps/cpu" +) + +// GetDockerIDList returnes a list of DockerID. +// This requires certain permission. +func GetDockerIDList() ([]string, error) { + return nil, common.NotImplementedError +} + +// CgroupCPU returnes specified cgroup id CPU status. +// containerid is same as docker id if you use docker. +// If you use container via systemd.slice, you could use +// containerid = docker-.scope and base=/sys/fs/cgroup/cpuacct/system.slice/ +func CgroupCPU(containerid string, base string) (*cpu.CPUTimesStat, error) { + return nil, common.NotImplementedError +} + +func CgroupCPUDocker(containerid string) (*cpu.CPUTimesStat, error) { + return CgroupCPU(containerid, "/sys/fs/cgroup/cpuacct/docker") +} + +func CgroupMem(containerid string, base string) (*CgroupMemStat, error) { + return nil, common.NotImplementedError +} + +func CgroupMemDocker(containerid string) (*CgroupMemStat, error) { + return CgroupMem(containerid, "/sys/fs/cgroup/memory/docker") +} + +func (m CgroupMemStat) String() string { + s, _ := json.Marshal(m) + return string(s) +}