Пример #1
0
func GetUsage(id string) (int64, error) {
	id, err := docker.ExpandId(id)
	if err != nil {
		log.Println("Error when expanding id:", err)
		return 0, err
	}

	path := config.CgroupPath("memory", 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, 64)
	if err != nil {
		log.Println("Error while parsing ", string(buffer), " : ", err)
		return 0, err
	}

	return val, nil
}
Пример #2
0
func GetUsage(id string) (*NetUsage, error) {
	id, err := docker.ExpandId(id)
	if err != nil {
		return nil, err
	}
	usage := NetUsage{}
	usage.NetworkStat = netUsages[id]
	usage.RxBps = int64(float64(netUsages[id].Received.Bytes-previousNetUsages[id].Received.Bytes) / float64(config.RefreshTime))
	usage.TxBps = int64(float64(netUsages[id].Transmit.Bytes-previousNetUsages[id].Transmit.Bytes) / float64(config.RefreshTime))
	return &usage, nil
}
Пример #3
0
func GetUsage(id string) (int64, error) {
	id, err := docker.ExpandId(id)
	if err != nil {
		log.Println("Error when expanding id:", err)
		return -1, err
	}
	if _, ok := previousCpuUsages[id]; !ok {
		return -1, nil
	}
	deltaCpuUsage := float64(cpuUsages[id] - previousCpuUsages[id])
	deltaSystemCpuUsage := float64(currentSystemUsage[id] - previousSystemUsage[id])

	return int64(deltaCpuUsage / deltaSystemCpuUsage * 100 * float64(runtime.NumCPU())), nil
}