Added a new method cgroups.GetStats() which will return a cgroups.Stats object which will contain all the available cgroup Stats.

Remove old Stats interface in libcontainers cgroups package.
Changed Stats to use unit64 instead of int64 to prevent integer overflow issues.
Updated unit tests.

Docker-DCO-1.1-Signed-off-by: Vishnu Kannan <vishnuk@google.com> (github: vishh)
This commit is contained in:
Vishnu Kannan 2014-05-28 00:01:08 +00:00
parent c22a0a3297
commit c7135d73d3
16 changed files with 329 additions and 231 deletions

View file

@ -5,6 +5,8 @@ import (
"os"
"path/filepath"
"strconv"
"github.com/dotcloud/docker/pkg/libcontainer/cgroups"
)
type cpuGroup struct {
@ -39,16 +41,15 @@ func (s *cpuGroup) Remove(d *data) error {
return removePath(d.path("cpu"))
}
func (s *cpuGroup) Stats(d *data) (map[string]int64, error) {
paramData := make(map[string]int64)
func (s *cpuGroup) GetStats(d *data, stats *cgroups.Stats) error {
path, err := d.path("cpu")
if err != nil {
return nil, err
return err
}
f, err := os.Open(filepath.Join(path, "cpu.stat"))
if err != nil {
return nil, err
return err
}
defer f.Close()
@ -56,9 +57,18 @@ func (s *cpuGroup) Stats(d *data) (map[string]int64, error) {
for sc.Scan() {
t, v, err := getCgroupParamKeyValue(sc.Text())
if err != nil {
return nil, err
return err
}
switch t {
case "nr_periods":
stats.CpuStats.ThrottlingData.Periods = v
case "nr_throttled":
stats.CpuStats.ThrottlingData.ThrottledPeriods = v
case "throttled_time":
stats.CpuStats.ThrottlingData.ThrottledTime = v
}
paramData[t] = v
}
return paramData, nil
return nil
}