예제 #1
0
파일: collector.go 프로젝트: cha87de/kvmtop
func (collector CpuCollector) Collect(vm models.VirtualMachine) (string, error) {
	// new current CPU counters
	newSchedStat, err := lookupStats(vm)
	if err != nil {
		return "", err
	}

	// get old CPU counters
	if oldSchedStat, exists := cpustats[vm.Ppid()]; exists {
		// set new stats as old stats for next run
		cpustats[vm.Ppid()] = newSchedStat
		// calculate diff between new and old counters
		cpu_utilisation := newSchedStat.calculateDiff(oldSchedStat)
		vCores := len(vm.VCpuTasks())
		result := fmt.Sprintf("%d\t%.0f%%\t%.0f%%\t%.0f%%\t%.0f%%",
			vCores,
			(cpu_utilisation.Avg.Inside * 100),
			(cpu_utilisation.Avg.Outside * 100),
			(cpu_utilisation.Avg.Steal * 100),
			(cpu_utilisation.Avg_other * 100))
		return result, nil
	} else {
		// no measurement yet
		// set new stats as old stats for next run
		cpustats[vm.Ppid()] = newSchedStat
		return "-", nil
	}
}
예제 #2
0
파일: helper.go 프로젝트: cha87de/kvmtop
func lookupStats(vm models.VirtualMachine) (VmCpuSchedStat, error) {
	cpuSchedStats := []CpuSchedStat{}
	for _, taskId := range vm.VCpuTasks() {
		cpuSchedStat, err := getCpuSchedStat(taskId)
		if err != nil {
			return VmCpuSchedStat{}, err
		}
		cpuSchedStats = append(cpuSchedStats, cpuSchedStat)
	}
	other := CpuSchedStat{}
	// TODO fill other
	//getTasks(vm)
	return VmCpuSchedStat{cpuSchedStats, other}, nil
}