Merge pull request #36 from jwilder/jw-panic
Fix panics with docker stats
This commit is contained in:
commit
3907a842a7
|
@ -71,7 +71,10 @@ func CgroupCPU(containerid string, base string) (*cpu.CPUTimesStat, error) {
|
|||
}
|
||||
path := path.Join(base, containerid, "cpuacct.stat")
|
||||
|
||||
lines, _ := common.ReadLines(path)
|
||||
lines, err := common.ReadLines(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// empty containerid means all cgroup
|
||||
if len(containerid) == 0 {
|
||||
containerid = "all"
|
||||
|
@ -109,7 +112,10 @@ func CgroupMem(containerid string, base string) (*CgroupMemStat, error) {
|
|||
if len(containerid) == 0 {
|
||||
containerid = "all"
|
||||
}
|
||||
lines, _ := common.ReadLines(path)
|
||||
lines, err := common.ReadLines(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ret := &CgroupMemStat{ContainerID: containerid}
|
||||
for _, line := range lines {
|
||||
fields := strings.Split(line, " ")
|
||||
|
|
|
@ -31,6 +31,13 @@ func TestCgroupCPU(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestCgroupCPUInvalidId(t *testing.T) {
|
||||
_, err := CgroupCPUDocker("bad id")
|
||||
if err == nil {
|
||||
t.Error("Expected path does not exist error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCgroupMem(t *testing.T) {
|
||||
v, _ := GetDockerIDList()
|
||||
for _, id := range v {
|
||||
|
@ -44,3 +51,10 @@ func TestCgroupMem(t *testing.T) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestCgroupMemInvalidId(t *testing.T) {
|
||||
_, err := CgroupMemDocker("bad id")
|
||||
if err == nil {
|
||||
t.Error("Expected path does not exist error")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue