generateGlobalCpuReport: average CPU usage for each host

This commit is contained in:
Pierre 2016-02-05 10:59:56 +01:00
parent 9120db2dc6
commit 9ba2a6628d
2 changed files with 17 additions and 1 deletions

View File

@ -35,6 +35,7 @@
"babel-preset-stage-0": "^6.3.13",
"clarify": "^1.0.5",
"dependency-check": "^2.5.1",
"lodash.foreach": "^4.0.0",
"mocha": "^2.3.4",
"must": "^0.13.1",
"nyc": "^5.2.0",

View File

@ -1,3 +1,5 @@
import forEach from 'lodash.foreach'
export const configurationSchema = {
type: 'object',
@ -23,7 +25,7 @@ function computeMean (values) {
let sum = 0
for (let i = 0; i < values.length; i++) {
sum += values[i]
sum += values[i] || 0
}
return sum / values.length
@ -119,6 +121,19 @@ class UsageReportPlugin {
}))
// =============================================================================
// STATS min, max, mean
this._unsets.push(this._xo.api.addMethod('generateGlobalCpuReport', async ({ machines, granularity }) => {
machines = machines.split(',')
const hostMean = {}
for (let machine of machines) {
const machineStats = await this_._xo.getXapiHostStats(this_._xo.getObject(machine), granularity)
const cpusMean = []
forEach(machineStats.stats.cpus, (cpu) => {
cpusMean.push(computeMean(cpu))
})
hostMean[machine] = computeMean(cpusMean)
}
return hostMean
}))
// Cpus
this._unsets.push(this._xo.api.addMethod('generateCpuReport', async ({ machine, granularity }) => {