Example #1
0
func (collector StaticCollector) Collect(vm models.VirtualMachine) (string, error) {
	vmx := vms[vm.Name()]
	// nothing to do, just look up the osUuid and print it as a result
	vmOsUuid := vmx.StaticData.Values["UUID"]
	result := fmt.Sprintf("%s", vmOsUuid)
	return result, nil
}
Example #2
0
func readItems(vm models.VirtualMachine) (models.Statistic, error) {
	/*
		# virsh dominfo xy
		Id:             4
		Name:           instance-0000012c
		UUID:           5f065a85-9a0f-402c-8470-681155a10021
		OS Type:        hvm
		State:          running
		CPU(s):         2
		CPU time:       15240.3s
		Max memory:     4194304 KiB
		Used memory:    4194304 KiB
		Persistent:     yes
		Autostart:      disable
		Managed save:   no
		Security model: none
		Security DOI:   0
	*/
	staticData, err := util.VirshXDetails("dominfo", vm.Name(), "", 0, 1, nil)
	if err != nil {
		log.Printf("Error while readItems %a", err)
		return models.Statistic{}, err
	}
	return staticData, nil
}
Example #3
0
func readItemStats(vm models.VirtualMachine, vmif models.MeasurementItem) (models.Statistic, error) {
	/*
		Capacity:       21474836480
		Allocation:     483991552
		Physical:       483991552
	*/
	stat1, err1 := util.VirshXDetails("domblkinfo", vm.Name(), vmif.Name, 0, 1, nil)
	if err1 != nil {
		return models.Statistic{}, err1
	}

	/*
		hda rd_req 23316
		hda rd_bytes 461506990
		hda wr_req 0
		hda wr_bytes 0
		hda flush_operations 0
		hda rd_total_times 1514874067
		hda wr_total_times 0
		hda flush_total_times 0
	*/
	stat2, err2 := util.VirshXDetails("domblkstat", vm.Name(), vmif.Name, 1, 2, nil)
	if err2 != nil {
		return models.Statistic{}, err2
	}

	// copy stats from stat1 to stat2
	for k, v := range stat1.Values {
		stat2.Values[k] = v
	}

	return stat2, nil
}
Example #4
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)
	}
}
Example #5
0
func readItems(vm models.VirtualMachine) ([]models.MeasurementItem, error) {
	/*
		# virsh domblklist xy
		Target     Source
		------------------------------------------------
		vda        /var/lib/nova/instances/9e703375-7ca7-4135-9534-b7aaeb5a14e5/disk
	*/
	list, err := util.VirshXList("domblklist", vm.Name())
	if err != nil {
		return nil, err
	}
	return list, nil
}
Example #6
0
func readItems(vm models.VirtualMachine) ([]models.MeasurementItem, error) {
	/*
		# virsh domiflist xy
		Interface  Type       Source     Model       MAC
		-------------------------------------------------------
		tap07e88f58-5d bridge     qbr07e88f58-5d virtio      fa:16:3e:63:1c:a9
	*/
	list, err := util.VirshXList("domiflist", vm.Name())
	if err != nil {
		return nil, err
	}
	return list, nil
}
Example #7
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
	}
}
Example #8
0
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
}
Example #9
0
func readItemStats(vm models.VirtualMachine, vmif models.MeasurementItem) (models.Statistic, error) {
	/*
		# virsh domiflist xy
		Interface  Type       Source     Model       MAC
		-------------------------------------------------------
		tap07e88f58-5d bridge     qbr07e88f58-5d virtio      fa:16:3e:63:1c:a9
	*/
	stat, err := util.VirshXDetails("domifstat", vm.Name(), vmif.Name, 1, 2, statisticEvalFunction)
	if err != nil {
		return models.Statistic{}, err
	}
	return stat, nil

}
Example #10
0
func (collector NetworkCollector) Collect(vm models.VirtualMachine) (string, error) {
	vmx := vms[vm.Name()]

	// new current counters
	newStats, err := vmx.lookupStats()
	if err != nil {
		return "", err
	}

	// get old counters
	oldStats := vmx.Statistic
	if len(oldStats) < 1 {
		vmx.Statistic = newStats
		vms[vm.Name()] = vmx
		return "-", nil
	}

	// calculate diff between new and old counters
	var utilSum int64 = 0
	for itemName, newStat := range newStats {
		if oldStat, exists := oldStats[itemName]; exists {
			utilItem := newStat.DiffPerTime(oldStat)
			utilSum = utilSum + utilItem
		}
	}

	// set newStats as oldStats
	vmx.Statistic = newStats
	vms[vm.Name()] = vmx

	utilMB := (float64(utilSum) / 1024 / 1024)
	result := fmt.Sprintf("%.2fMB/s", utilMB)
	return result, nil

}
Example #11
0
func (collector StaticCollector) CollectDetails(vm models.VirtualMachine) {
	staticData, err := readItems(vm)
	if err != nil {
		log.Printf("Error while CollectDetails in StaticCollector %a", err)
		return
	}
	if vmx, exists := vms[vm.Name()]; exists {
		vmx.StaticData = staticData
		vms[vm.Name()] = vmx
	} else {
		vms[vm.Name()] = VirtualMachineExtended{vm, staticData}
	}

}
Example #12
0
func (collector DiskCollector) CollectDetails(vm models.VirtualMachine) {
	// lookup network interfaces for all virtual machines
	list, err := readItems(vm)
	if err != nil {
		return
	}
	if vmx, exists := vms[vm.Name()]; exists {
		vmx.Items = list
		vms[vm.Name()] = vmx
	} else {
		vms[vm.Name()] = VirtualMachineExtended{vm, list, nil}
	}

}
Example #13
0
func (collector DiskCollector) Collect(vm models.VirtualMachine) (string, error) {
	vmx := vms[vm.Name()]

	// new current counters
	newStats, err := vmx.lookupStats()
	if err != nil {
		return "", err
	}

	// get old counters
	oldStats := vmx.Statistic
	if len(oldStats) < 1 {
		vmx.Statistic = newStats
		vms[vm.Name()] = vmx
		return "-", nil
	}

	// sum up disk space (available and used)
	var spaceTotal int64 = 0
	var spaceUsed int64 = 0
	for _, newStat := range newStats {
		spaceTotal = spaceTotal + newStat.GetValueAsInt("Capacity")
		spaceUsed = spaceUsed + newStat.GetValueAsInt("Allocation")
	}
	// calculate read/write bandwidth
	var readBand int64 = 0
	var writeBand int64 = 0
	for itemName, newStat := range newStats {
		if oldStat, exists := oldStats[itemName]; exists {
			readBandItem := newStat.DiffPerTimeField(oldStat, "rd_bytes")
			readBand = readBand + readBandItem
			writeBandItem := newStat.DiffPerTimeField(oldStat, "wr_bytes")
			writeBand = writeBand + writeBandItem
		}
	}

	// set newStats as oldStats
	vmx.Statistic = newStats
	vms[vm.Name()] = vmx

	// format results
	spaceTotalMB := (float64(spaceTotal) / 1024 / 1024)
	spaceUsedMB := (float64(spaceUsed) / 1024 / 1024)
	readBandMB := (float64(readBand) / 1024 / 1024)
	writeBandMB := (float64(writeBand) / 1024 / 1024)
	result := fmt.Sprintf("%.0fMB\t%0.fMB\t%.2fMB/s\t%.2fMB/s", spaceUsedMB, spaceTotalMB, readBandMB, writeBandMB)

	return result, nil

}