Пример #1
0
func getMemoryStats(containerID string, stats *info.ContainerStats) error {
	path, err := fs.GetPath(containerID, driver, "memory", "")
	if err != nil {
		return err
	}
	// Get memory stat file
	statsFile, err := os.Open(filepath.Join(path, "memory.stat"))
	if err != nil {
		if os.IsNotExist(err) {
			return nil
		}
		return err
	}
	defer statsFile.Close()
	sc := bufio.NewScanner(statsFile)
	for sc.Scan() {
		t, v, err := getCgroupParamKeyValue(sc.Text())
		if err != nil {
			return fmt.Errorf("failed to parse memory.stat (%q) - %v", sc.Text(), err)
		}
		stats.Memory.Stats[t] = v
	}
	// Get memory usage
	usage, err := getCgroupParamUint(path, "memory.usage_in_bytes")
	if err != nil {
		return fmt.Errorf("failed to parse memory.usage_in_bytes - %v", err)
	}
	stats.Memory.Usage = usage

	return nil
}
Пример #2
0
func getCpusetSpec(containerID string, cinfo *info.ContainerInfo) error {
	path, err := fs.GetPath(containerID, driver, "cpuset", "")
	if err != nil {
		return err
	}
	// Get cpuset cpus
	cpus, err := getCgroupParamString(path, "cpuset.cpus")
	if err != nil {
		return fmt.Errorf("failed to parse cpuset.cpus - %v", err)
	}
	cinfo.Spec.Cpuset.Cpus = cpus

	return nil
}
Пример #3
0
func getMemorySpec(containerID string, cinfo *info.ContainerInfo) error {
	path, err := fs.GetPath(containerID, driver, "memory", "")
	if err != nil {
		return err
	}
	// Get memory limit
	limit, err := getCgroupParamUint(path, "memory.limit_in_bytes")
	if err != nil {
		return fmt.Errorf("failed to parse memory.limit_in_bytes - %v", err)
	}
	cinfo.Spec.Memory.Limit = limit
	// Get memory memsw limit
	swapLimit, err := getCgroupParamUint(path, "memory.memsw.limit_in_bytes")
	if err != nil {
		return fmt.Errorf("failed to parse memory.memsw.limit_in_bytes - %v", err)
	}
	cinfo.Spec.Memory.SwapLimit = swapLimit

	return nil
}