diff --git a/cgroup/cgroup.go b/cgroup/cgroup.go index 8ec4d01..d3804d1 100644 --- a/cgroup/cgroup.go +++ b/cgroup/cgroup.go @@ -105,7 +105,10 @@ func NewFromProcessCgroupFile(filePath string) (*Cgroup, error) { cg.subsystems[cgType] = path.Join(baseCgroupPath, parts[2]) } } - if p := cg.subsystems["cpu"]; p != "" { + if p := cg.subsystems["name=systemd"]; p != "" { + cg.Id = p + cg.Version = V1 + } else if p = cg.subsystems["cpu"]; p != "" { cg.Id = p cg.Version = V1 } else { diff --git a/cgroup/cgroup_test.go b/cgroup/cgroup_test.go index da8c9fc..bff6f5f 100644 --- a/cgroup/cgroup_test.go +++ b/cgroup/cgroup_test.go @@ -55,6 +55,13 @@ func TestNewFromProcessCgroupFile(t *testing.T) { assert.Equal(t, "73051af271105c07e1f493b34856a77e665e3b0b4fc72f76c807dfbffeb881bd", cg.ContainerId) assert.Equal(t, ContainerTypeDocker, cg.ContainerType) + cg, err = NewFromProcessCgroupFile(path.Join("fixtures/proc/600/cgroup")) + assert.Nil(t, err) + assert.Equal(t, V1, cg.Version) + assert.Equal(t, "/system.slice/springboot.service", cg.Id) + assert.Equal(t, "/system.slice/springboot.service", cg.ContainerId) + assert.Equal(t, ContainerTypeSystemdService, cg.ContainerType) + baseCgroupPath = "/kubepods.slice/kubepods-besteffort.slice/kubepods-besteffort-podc83d0428_58af_41eb_8dba_b9e6eddffe7b.slice/docker-0e612005fd07e7f47e2cd07df99a2b4e909446814d71d0b5e4efc7159dd51252.scope" defer func() { baseCgroupPath = "" diff --git a/cgroup/fixtures/proc/600/cgroup b/cgroup/fixtures/proc/600/cgroup new file mode 100644 index 0000000..95e834f --- /dev/null +++ b/cgroup/fixtures/proc/600/cgroup @@ -0,0 +1,11 @@ +11:freezer:/ +10:blkio:/init.scope +9:hugetlb:/ +8:memory:/init.scope +7:pids:/init.scope +6:devices:/init.scope +5:rdma:/ +4:cpuset:/ +3:net_cls,net_prio:/ +2:cpu,cpuacct:/ +1:name=systemd:/system.slice/springboot.service