getPoolVmStats to get all the VMs stats from a specific pool

This commit is contained in:
Pierre 2016-02-05 15:01:55 +01:00
parent 9ba2a6628d
commit d21f5f427c

View File

@ -23,29 +23,29 @@ export const configurationSchema = {
// =================================================================== // ===================================================================
function computeMean (values) { function computeMean (values) {
let sum = 0 let sum = 0
let tot = 0
for (let i = 0; i < values.length; i++) { forEach(values, (val) => {
sum += values[i] || 0 sum += val || 0
} tot += val ? 1 : 0
})
return sum / values.length return sum / tot
} }
function computeMax (values) { function computeMax (values) {
let max = -Infinity let max = -Infinity
for (let i = 0; i < values.length; i++) { forEach(values, (val) => {
if (values[i] > max) { if (val && val > max) {
max = values[i] max = val
} }
} })
return max return max
} }
function computeMin (values) { function computeMin (values) {
let min = +Infinity let min = +Infinity
for (let i = 0; i < values.length; i++) { forEach(values, (val) => {
if (values[i] < min) { if (val && val < min) {
min = values[i] min = val
} }
} })
return min return min
} }
function computeCpuMax (cpus) { function computeCpuMax (cpus) {
@ -135,6 +135,29 @@ class UsageReportPlugin {
return hostMean return hostMean
})) }))
const _getPoolVmsStats = async (machine, granularity) => {
const host = await this_._xo.getObject(machine)
const objects = await this_._xo.getObjects()
const vmsOnPool = []
forEach(objects, (obj) => {
if (obj.type === 'VM' && obj.$poolId === host.$poolId) {
vmsOnPool.push(obj)
}
})
const poolVmStats = []
for (const vm of vmsOnPool) {
if (vm.power_state === 'Running') {
const vmStats = await this_._xo.getXapiVmStats(vm, granularity)
poolVmStats.push(vmStats)
}
}
return poolVmStats
}
this._unsets.push(this._xo.api.addMethod('generateGlobalVmReport', async ({ machine, granularity }) => {
return _getPoolVmsStats(machine, granularity)
}))
// Cpus // Cpus
this._unsets.push(this._xo.api.addMethod('generateCpuReport', async ({ machine, granularity }) => { this._unsets.push(this._xo.api.addMethod('generateCpuReport', async ({ machine, granularity }) => {
const machineStats = await this_._xo.getXapiHostStats(this_._xo.getObject(machine), granularity) const machineStats = await this_._xo.getXapiHostStats(this_._xo.getObject(machine), granularity)