Implement a more generic method.
This commit is contained in:
parent
ccb508705b
commit
56f99b2129
@ -35,7 +35,6 @@ function computeCpuMean (cpus) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function computeMax (values) {
|
function computeMax (values) {
|
||||||
// TODO
|
|
||||||
let max = -Infinity
|
let max = -Infinity
|
||||||
for (let i = 0; i < values.length; i++) {
|
for (let i = 0; i < values.length; i++) {
|
||||||
if (values > max) {
|
if (values > max) {
|
||||||
@ -50,7 +49,6 @@ function computeCpuMax (cpus) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function computeMin (values) {
|
function computeMin (values) {
|
||||||
// TODO
|
|
||||||
let min = +Infinity
|
let min = +Infinity
|
||||||
for (let i = 0; i < values.length; i++) {
|
for (let i = 0; i < values.length; i++) {
|
||||||
if (values < min) {
|
if (values < min) {
|
||||||
@ -60,21 +58,8 @@ function computeMin (values) {
|
|||||||
return min
|
return min
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO
|
|
||||||
function computeCpuMin (cpus) {
|
function computeCpuMin (cpus) {
|
||||||
return computeMin(cpus.map(computeMin))
|
return computeMin(cpus.map(computeMin))
|
||||||
// TODO: rebase on top of computeMin()
|
|
||||||
// let min = +Infinity
|
|
||||||
// for (let i = 0; i < cpus.length; i++) {
|
|
||||||
// const valuesByDay = cpus[i]
|
|
||||||
// for (let j = 0; j < valuesByDay.length; j++) {
|
|
||||||
// const value = valuesByDay[j]
|
|
||||||
// if (value < min) {
|
|
||||||
// min = value
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// return min
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ===================================================================
|
// ===================================================================
|
||||||
@ -82,68 +67,50 @@ function computeCpuMin (cpus) {
|
|||||||
class UsageReportPlugin {
|
class UsageReportPlugin {
|
||||||
constructor (xo) {
|
constructor (xo) {
|
||||||
this._xo = xo
|
this._xo = xo
|
||||||
this._unset = null
|
this._unsets = []
|
||||||
}
|
}
|
||||||
|
|
||||||
configure ({emails}) {
|
configure ({emails}) {
|
||||||
this.mailsReceivers = emails
|
this.mailsReceivers = emails
|
||||||
}
|
}
|
||||||
load () {
|
load () {
|
||||||
let parsedHostDaysLab1 = require('/home/thannos/xo-server/lab1_days.json')
|
const stats = {}
|
||||||
let parsedHostHoursLab1 = require('/home/thannos/xo-server/lab1_hours.json')
|
|
||||||
let parsedHostDaysLab2 = require('/home/thannos/xo-server/lab2_days.json')
|
stats['lab1_days'] = require('/home/thannos/xo-server/lab1_days.json')
|
||||||
let parsedHostHoursLab2 = require('/home/thannos/xo-server/lab2_hours.json')
|
stats['lab1_hours'] = require('/home/thannos/xo-server/lab1_hours.json')
|
||||||
let parsedVmDaysNfs = require('/home/thannos/xo-server/nfs_days.json')
|
stats['lab2_days'] = require('/home/thannos/xo-server/lab2_days.json')
|
||||||
let parsedVmHoursNfs = require('/home/thannos/xo-server/nfs_hours.json')
|
stats['lab2_hours'] = require('/home/thannos/xo-server/lab2_hours.json')
|
||||||
let parsedVmHoursSalt = require('/home/thannos/xo-server/salt_hours.json')
|
stats['nfs_days'] = require('/home/thannos/xo-server/nfs_days.json')
|
||||||
let parsedVmDaysSalt = require('/home/thannos/xo-server/salt_days.json')
|
stats['nfs_hours'] = require('/home/thannos/xo-server/nfs_hours.json')
|
||||||
|
stats['salt_hours'] = require('/home/thannos/xo-server/salt_hours.json')
|
||||||
|
stats['salt_days'] = require('/home/thannos/xo-server/salt_days.json')
|
||||||
|
|
||||||
// ===================================================================
|
// ===================================================================
|
||||||
this._unset = this._xo.api.addMethod('generateUsageReport', () => {
|
|
||||||
return 'heracles'
|
|
||||||
})
|
|
||||||
this._unset = this._xo.api.addMethod('generateCpuMeanL1Days', () => {
|
|
||||||
return computeCpuMean(parsedHostDaysLab1.stats.cpus)
|
|
||||||
})
|
|
||||||
this._unset = this._xo.api.addMethod('generateCpuMaxL1Days', () => {
|
|
||||||
return computeCpuMax(parsedHostDaysLab1.stats.cpus)
|
|
||||||
})
|
|
||||||
this._unset = this._xo.api.addMethod('generateCpuMinL1Days', () => {
|
|
||||||
return computeCpuMin(parsedHostDaysLab1.stats.cpus)
|
|
||||||
})
|
|
||||||
|
|
||||||
this._unset = this._xo.api.addMethod('generateLoadMeanL1Days', () => {
|
// xo-cli generateCpuReport machine=lab1
|
||||||
|
this._unsets.push(this._xo.api.addMethod('generateCpuReport', ({ machine }) => {
|
||||||
|
// TODO: compute and returns CPU mean, min & max.
|
||||||
|
}))
|
||||||
|
|
||||||
|
this._unsets.push(this._xo.api.addMethod('generateLoadMeanL1Days', () => {
|
||||||
return computeMean(parsedHostDaysLab1.stats.load)
|
return computeMean(parsedHostDaysLab1.stats.load)
|
||||||
})
|
}))
|
||||||
|
|
||||||
this._unset = this._xo.api.addMethod('generateLoadMaxL1Days', () => {
|
this._unsets.push(this._xo.api.addMethod('generateLoadMaxL1Days', () => {
|
||||||
return computeMax(parsedHostDaysLab1.stats.load)
|
return computeMax(parsedHostDaysLab1.stats.load)
|
||||||
})
|
}))
|
||||||
|
|
||||||
this._unset = this._xo.api.addMethod('generateLoadMinL1Days', () => {
|
this._unsets.push(this._xo.api.addMethod('generateLoadMinL1Days', () => {
|
||||||
return computeMin(parsedHostDaysLab1.stats.load)
|
return computeMin(parsedHostDaysLab1.stats.load)
|
||||||
})
|
}))
|
||||||
|
|
||||||
this._unset = this._xo.api.addMethod('generateCpuMeanL2Days', () => {
|
|
||||||
return computeCpuMean(parsedHostDaysLab2.stats.cpus)
|
|
||||||
})
|
|
||||||
this._unset = this._xo.api.addMethod('generateCpuMaxL2Days', () => {
|
|
||||||
return computeCpuMax(parsedHostDaysLab2.stats.cpus)
|
|
||||||
})
|
|
||||||
this._unset = this._xo.api.addMethod('generateCpuMinL2Days', () => {
|
|
||||||
return computeCpuMin(parsedHostDaysLab2.stats.cpus)
|
|
||||||
})
|
|
||||||
|
|
||||||
this._unset = this._xo.api.addMethod('generateCpuMeanNfsDays', () => {
|
|
||||||
return computeCpuMean(parsedVmDaysNfs.stats.cpus)
|
|
||||||
})
|
|
||||||
this._unset = this._xo.api.addMethod('generateCpuMeanSaltDays', () => {
|
|
||||||
return computeCpuMean(parsedVmDaysSalt.stats.cpus)
|
|
||||||
})
|
|
||||||
// CONCATENATION
|
|
||||||
// totalMean = `${MeanenneCpuLab1}${MeanenneCpuLab2}`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unload () {
|
unload () {
|
||||||
this._unset()
|
for (let i = 0; i < this._unsets; ++i) {
|
||||||
|
this._unsets[i]()
|
||||||
|
}
|
||||||
|
|
||||||
|
this._unsets.length = 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* if (this._xo.sendEmail) {
|
/* if (this._xo.sendEmail) {
|
||||||
@ -165,7 +132,7 @@ fs.readdirSync(dir).forEach(function (file) {
|
|||||||
data[file.replace(/\.json$/, '')] = require(dir + file)
|
data[file.replace(/\.json$/, '')] = require(dir + file)
|
||||||
}) */
|
}) */
|
||||||
|
|
||||||
// ===================================================================
|
// ===================================================================
|
||||||
|
|
||||||
export default ({ xo }) => new UsageReportPlugin(xo)
|
export default ({ xo }) => new UsageReportPlugin(xo)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user