Thresholds are exposed in configuration.

This commit is contained in:
wescoeur 2016-03-09 16:59:36 +01:00
parent eaad41fe55
commit 021cea0b34

View File

@ -74,11 +74,30 @@ export const configurationSchema = {
type: 'array', type: 'array',
$type: 'Pool', $type: 'Pool',
description: 'list of pools where to apply the policy' description: 'list of pools where to apply the policy'
},
thresholds: {
type: 'object',
title: 'Critical thresholds',
properties: {
cpu: {
type: 'integer',
title: 'CPU (%)',
description: 'default: 90%'
},
memoryFree: {
type: 'integer',
title: 'RAM, Free memory (MB)',
description: 'default: 64MB'
}
}
} }
}, },
required: [ 'name', 'mode', 'pools' ] required: [ 'name', 'mode', 'pools' ]
}, },
minItems: 1 minItems: 1
} }
}, },
@ -208,7 +227,7 @@ class Plan {
critical: thresholds.cpu || DEFAULT_CRITICAL_THRESHOLD_CPU critical: thresholds.cpu || DEFAULT_CRITICAL_THRESHOLD_CPU
}, },
memoryFree: { memoryFree: {
critical: thresholds.memoryFree || DEFAULT_CRITICAL_THRESHOLD_MEMORY_FREE * 1024 * 1024 critical: (thresholds.memoryFree || DEFAULT_CRITICAL_THRESHOLD_MEMORY_FREE) * 1024
} }
} }
@ -358,15 +377,17 @@ class PerformancePlan extends Plan {
} }
async execute () { async execute () {
const data = await this._findHostsToOptimize()
if (!hosts) {
return
}
const { const {
averages, averages,
hosts, hosts,
toOptimize toOptimize
} = await this._findHostsToOptimize() } = data
if (toOptimize.length === 0) {
return
}
const exceededHost = searchObject(toOptimize, (a, b) => { const exceededHost = searchObject(toOptimize, (a, b) => {
a = averages[a.id] a = averages[a.id]
@ -385,7 +406,7 @@ class PerformancePlan extends Plan {
async _optimize ({ exceededHost, hosts, hostsAverages }) { async _optimize ({ exceededHost, hosts, hostsAverages }) {
const vms = await this._getVms(exceededHost.id) const vms = await this._getVms(exceededHost.id)
const vmsAverages = this._getVmsAverages const vmsAverages = await this._getVmsAverages(vms)
// Compute real CPU usage. Virtuals cpus to reals cpus. // Compute real CPU usage. Virtuals cpus to reals cpus.
setRealCpuAverageOfVms(vms, vmsAverages) setRealCpuAverageOfVms(vms, vmsAverages)
@ -451,17 +472,19 @@ class DensityPlan extends Plan {
async execute () { async execute () {
const [ const [
{ data,
averages,
hosts,
toOptimize
},
pools pools
] = await Promise.all(mapToArray( ] = await Promise.all(mapToArray(
this._findHostsToOptimize(), this._findHostsToOptimize(),
this._getPlanPools() this._getPlanPools()
)) ))
const {
averages,
hosts,
toOptimize
} = data
// Optimize master. // Optimize master.
console.log(hosts) console.log(hosts)
@ -509,7 +532,8 @@ class LoadBalancerPlugin {
mode: !plan.mode mode: !plan.mode
? PERFORMANCE_MODE ? PERFORMANCE_MODE
: DENSITY_MODE, : DENSITY_MODE,
poolIds: plan.pools poolIds: plan.pools,
thresholds: plan.thresholds
}) })
} }
} }
@ -527,7 +551,7 @@ class LoadBalancerPlugin {
this._job.cron.stop() this._job.cron.stop()
} }
_addPlan ({ name, mode, poolIds }) { _addPlan ({ name, mode, poolIds, thresholds }) {
poolIds = uniq(poolIds) poolIds = uniq(poolIds)
// Check already used pools. // Check already used pools.
@ -537,8 +561,8 @@ class LoadBalancerPlugin {
this._poolIds = this._poolIds.concat(poolIds) this._poolIds = this._poolIds.concat(poolIds)
this._plans.push(mode === PERFORMANCE_MODE this._plans.push(mode === PERFORMANCE_MODE
? new PerformancePlan(this.xo, name, poolIds) ? new PerformancePlan(this.xo, name, poolIds, { thresholds })
: new DensityPlan(this.xo, name, poolIds) : new DensityPlan(this.xo, name, poolIds, { thresholds })
) )
} }