From dd5576b2b3f5667811f882d1f64a11e13164791a Mon Sep 17 00:00:00 2001 From: Alexander Morozov Date: Mon, 2 Mar 2015 14:36:09 -0800 Subject: [PATCH] Implement stats for systemd It looks weird but works and not crashes application. Signed-off-by: Alexander Morozov --- cgroups/systemd/apply_systemd.go | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/cgroups/systemd/apply_systemd.go b/cgroups/systemd/apply_systemd.go index 3c7cefff..fbaa13c7 100644 --- a/cgroups/systemd/apply_systemd.go +++ b/cgroups/systemd/apply_systemd.go @@ -29,6 +29,17 @@ type subsystem interface { GetStats(string, *cgroups.Stats) error } +var subsystems = map[string]subsystem{ + "devices": &fs.DevicesGroup{}, + "memory": &fs.MemoryGroup{}, + "cpu": &fs.CpuGroup{}, + "cpuset": &fs.CpusetGroup{}, + "cpuacct": &fs.CpuacctGroup{}, + "blkio": &fs.BlkioGroup{}, + "perf_event": &fs.PerfEventGroup{}, + "freezer": &fs.FreezerGroup{}, +} + var ( connLock sync.Mutex theConn *systemd.Conn @@ -298,7 +309,18 @@ func (m *Manager) GetPids() ([]int, error) { } func (m *Manager) GetStats() (*cgroups.Stats, error) { - panic("not implemented") + stats := cgroups.NewStats() + for name, path := range m.Paths { + sys, ok := subsystems[name] + if !ok || !cgroups.PathExists(path) { + continue + } + if err := sys.GetStats(path, stats); err != nil { + return nil, err + } + } + + return stats, nil } func getUnitName(c *configs.Cgroup) string {