get n values max
This commit is contained in:
parent
e40411ef91
commit
9120db2dc6
@ -47,7 +47,7 @@ function computeMin (values) {
|
|||||||
return min
|
return min
|
||||||
}
|
}
|
||||||
function computeCpuMax (cpus) {
|
function computeCpuMax (cpus) {
|
||||||
return computeMax(cpus.map(computeMax))
|
return sortArray(cpus.map(computeMax))
|
||||||
}
|
}
|
||||||
function computeCpuMin (cpus) {
|
function computeCpuMin (cpus) {
|
||||||
return computeMin(cpus.map(computeMin))
|
return computeMin(cpus.map(computeMin))
|
||||||
@ -55,6 +55,22 @@ function computeCpuMin (cpus) {
|
|||||||
function computeCpuMean (cpus) {
|
function computeCpuMean (cpus) {
|
||||||
return computeMean(cpus.map(computeMean))
|
return computeMean(cpus.map(computeMean))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function compareNumbersDesc (a, b) {
|
||||||
|
if (a > b) {
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
if (a < b) {
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
function sortArray (values) {
|
||||||
|
let n = 3
|
||||||
|
let sort = values.sort(compareNumbersDesc)
|
||||||
|
return sort.slice(0, n)
|
||||||
|
}
|
||||||
|
|
||||||
// ===================================================================
|
// ===================================================================
|
||||||
|
|
||||||
class UsageReportPlugin {
|
class UsageReportPlugin {
|
||||||
@ -67,10 +83,60 @@ class UsageReportPlugin {
|
|||||||
this.mailsReceivers = emails
|
this.mailsReceivers = emails
|
||||||
}
|
}
|
||||||
load () {
|
load () {
|
||||||
|
const this_ = this
|
||||||
|
// TOP Max Cpu
|
||||||
|
this._unsets.push(this._xo.api.addMethod('generateCpu', async ({ machine, granularity }) => {
|
||||||
|
const machineStats = await this_._xo.getXapiHostStats(this_._xo.getObject(machine), granularity)
|
||||||
|
let maxCpu = computeCpuMax(machineStats.stats.cpus)
|
||||||
|
return {
|
||||||
|
'max': maxCpu
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
// TOP Max Load
|
||||||
|
// xo-cli generate machine=4a2dccec-83ff-4212-9e16-44fbc0527961 granularity=days
|
||||||
|
this._unsets.push(this._xo.api.addMethod('generateLoad', async ({ machine, granularity }) => {
|
||||||
|
const machineStats = await this_._xo.getXapiHostStats(this_._xo.getObject(machine), granularity)
|
||||||
|
let maxLoad = sortArray(machineStats.stats.load)
|
||||||
|
return {
|
||||||
|
'max': maxLoad
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
// TOP Max Memory
|
||||||
|
this._unsets.push(this._xo.api.addMethod('generateMemory', async ({ machine, granularity }) => {
|
||||||
|
const machineStats = await this_._xo.getXapiHostStats(this_._xo.getObject(machine), granularity)
|
||||||
|
let maxMemory = sortArray(machineStats.stats.memory)
|
||||||
|
return {
|
||||||
|
'max': maxMemory
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
// TOP Max MemoryUsed
|
||||||
|
this._unsets.push(this._xo.api.addMethod('generateMemoryUsed', async ({ machine, granularity }) => {
|
||||||
|
const machineStats = await this_._xo.getXapiHostStats(this_._xo.getObject(machine), granularity)
|
||||||
|
let maxMemoryUsed = sortArray(machineStats.stats.memoryUsed)
|
||||||
|
return {
|
||||||
|
'max': maxMemoryUsed
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
// =============================================================================
|
||||||
|
// STATS min, max, mean
|
||||||
|
|
||||||
|
// Cpus
|
||||||
|
this._unsets.push(this._xo.api.addMethod('generateCpuReport', async ({ machine, granularity }) => {
|
||||||
|
const machineStats = await this_._xo.getXapiHostStats(this_._xo.getObject(machine), granularity)
|
||||||
|
let maxCpu = computeCpuMax(machineStats.stats.cpus)
|
||||||
|
let minCpu = computeCpuMin(machineStats.stats.cpus)
|
||||||
|
let meanCpu = computeCpuMean(machineStats.stats.cpus)
|
||||||
|
|
||||||
|
return {
|
||||||
|
'max': maxCpu,
|
||||||
|
'min': minCpu,
|
||||||
|
'mean': meanCpu
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
// Load
|
||||||
// xo-cli generateLoadReport machine=4a2dccec-83ff-4212-9e16-44fbc0527961 granularity=days
|
// xo-cli generateLoadReport machine=4a2dccec-83ff-4212-9e16-44fbc0527961 granularity=days
|
||||||
this._unsets.push(this._xo.api.addMethod('generateLoadReport', async ({ machine, granularity }) => {
|
this._unsets.push(this._xo.api.addMethod('generateLoadReport', async ({ machine, granularity }) => {
|
||||||
const machineStats = await this._xo.getXapiHostStats(machine, granularity)
|
const machineStats = await this_._xo.getXapiHostStats(this_._xo.getObject(machine), granularity)
|
||||||
|
|
||||||
let maxLoad = computeMax(machineStats.stats.load)
|
let maxLoad = computeMax(machineStats.stats.load)
|
||||||
let minLoad = computeMin(machineStats.stats.load)
|
let minLoad = computeMin(machineStats.stats.load)
|
||||||
let meanLoad = computeMean(machineStats.stats.load)
|
let meanLoad = computeMean(machineStats.stats.load)
|
||||||
@ -81,43 +147,39 @@ class UsageReportPlugin {
|
|||||||
'mean': meanLoad
|
'mean': meanLoad
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
|
// Memory
|
||||||
// memory
|
this._unsets.push(this._xo.api.addMethod('generateMemoryReport', async ({ machine, granularity }) => {
|
||||||
this._unsets.push(this._xo.api.addMethod('generateMemoryReport', ({ machine, granularity }) => {
|
const machineStats = await this_._xo.getXapiHostStats(this_._xo.getObject(machine), granularity)
|
||||||
// TODO
|
|
||||||
|
|
||||||
const machineStats = stats[`${machine}_${granularity}`]
|
|
||||||
let maxMemory = computeMax(machineStats.stats.memory)
|
let maxMemory = computeMax(machineStats.stats.memory)
|
||||||
let minMemory = computeMin(machineStats.stats.memory)
|
let minMemory = computeMin(machineStats.stats.memory)
|
||||||
let meanMemory = computeMean(machineStats.stats.memory)
|
let meanMemory = computeMean(machineStats.stats.memory)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'max': maxMemory,
|
'max': maxMemory,
|
||||||
'min': minMemory,
|
'min': minMemory,
|
||||||
'mean': meanMemory
|
'mean': meanMemory
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
// memoryUsed
|
// MemoryUsed
|
||||||
this._unsets.push(this._xo.api.addMethod('generateMemoryUsedReport', ({ machine, granularity }) => {
|
this._unsets.push(this._xo.api.addMethod('generateMemoryUsedReport', async ({ machine, granularity }) => {
|
||||||
// TODO
|
const machineStats = await this_._xo.getXapiHostStats(this_._xo.getObject(machine), granularity)
|
||||||
|
|
||||||
const machineStats = stats[`${machine}_${granularity}`]
|
|
||||||
let maxMemoryUsed = computeMax(machineStats.stats.memoryUsed)
|
let maxMemoryUsed = computeMax(machineStats.stats.memoryUsed)
|
||||||
let minMemoryUsed = computeMin(machineStats.stats.memoryUsed)
|
let minMemoryUsed = computeMin(machineStats.stats.memoryUsed)
|
||||||
let meanMemoryUsed = computeMean(machineStats.stats.memoryUsed)
|
let meanMemoryUsed = computeMean(machineStats.stats.memoryUsed)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'max': maxMemoryUsed,
|
'max': maxMemoryUsed,
|
||||||
'min': minMemoryUsed,
|
'min': minMemoryUsed,
|
||||||
'mean': meanMemoryUsed
|
'mean': meanMemoryUsed
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
// memoryFree
|
// MemoryFree
|
||||||
this._unsets.push(this._xo.api.addMethod('generateMemoryFreeReport', ({ machine, granularity }) => {
|
this._unsets.push(this._xo.api.addMethod('generateMemoryFreeReport', async ({ machine, granularity }) => {
|
||||||
// TODO
|
const machineStats = await this_._xo.getXapiHostStats(this_._xo.getObject(machine), granularity)
|
||||||
|
|
||||||
const machineStats = stats[`${machine}_${granularity}`]
|
|
||||||
let maxMemoryFree = computeMax(machineStats.stats.memoryFree)
|
let maxMemoryFree = computeMax(machineStats.stats.memoryFree)
|
||||||
let minMemoryFree = computeMin(machineStats.stats.memoryFree)
|
let minMemoryFree = computeMin(machineStats.stats.memoryFree)
|
||||||
let meanMemoryFree = computeMean(machineStats.stats.memoryFree)
|
let meanMemoryFree = computeMean(machineStats.stats.memoryFree)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'max': maxMemoryFree,
|
'max': maxMemoryFree,
|
||||||
'min': minMemoryFree,
|
'min': minMemoryFree,
|
||||||
@ -134,6 +196,7 @@ class UsageReportPlugin {
|
|||||||
this._unsets.length = 0
|
this._unsets.length = 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if (this._xo.sendEmail) {
|
/* if (this._xo.sendEmail) {
|
||||||
await this._xo.sendEmail({
|
await this._xo.sendEmail({
|
||||||
to: this._mailsReceivers,
|
to: this._mailsReceivers,
|
||||||
|
Loading…
Reference in New Issue
Block a user