Пример #1
0
func GetUsage(id_short string) (int64, error) {
	id, err := utils.GetFullContainerId(id_short)
	if err != nil {
		return -1, err
	}
	return int64((float64((cpuUsages[id] - previousCpuUsages[id])) / float64(1e9) / float64(runtime.NumCPU())) * 100), nil
}
Пример #2
0
func GetUsage(name string) (int64, error) {
	id, err := utils.GetFullContainerId(name)
	if err != nil {
		return 0, err
	}
	path := fmt.Sprintf("%s/%s/%s", LXC_MEM_DIR, id, LXC_MEM_USAGE_FILE)
	f, err := os.Open(path)
	if err != nil {
		log.Println("Error while opening : ", err)
		return 0, err
	}
	defer f.Close()

	buffer := make([]byte, 16)
	n, err := f.Read(buffer)
	if err != nil {
		log.Println("Error while reading ", path, " : ", err)
		return 0, err
	}

	buffer = buffer[:n-1]
	val, err := strconv.ParseInt(string(buffer), 10, strconv.IntSize)
	if err != nil {
		log.Println("Error while parsing ", string(buffer), " : ", err)
		return 0, err
	}

	return val, nil
}