Пример #1
0
func getTasks(vm models.VirtualMachine) {
	folder := fmt.Sprint("/proc/", vm.Ppid(), "/task/")
	files, _ := ioutil.ReadDir(folder)
	for _, f := range files {
		taskId := f.Name()
		fmt.Printf("%s ", taskId)
	}
}
Пример #2
0
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
	}
}