Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(xo-server-usage-report): change dataset size #6723

Merged
merged 8 commits into from
Apr 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

> Users must be able to say: “I had this issue, happy to know it's fixed”

- [Plugins/usage-report] Compute stats on configured period instead of the whole year (PR [#6723](https://github.com/vatesfr/xen-orchestra/pull/6723))
- [Backup] Fix `Invalid parameters` when deleting `speed limit` value (PR [#6768](https://github.com/vatesfr/xen-orchestra/pull/6768))

### Packages to release
Expand All @@ -31,5 +32,6 @@

- xo-web patch
- xo-server minor
- xo-server-usage-report patch

<!--packages-end-->
66 changes: 43 additions & 23 deletions packages/xo-server-usage-report/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,12 +266,31 @@ const METRICS_MEAN = {
iops: value => computeDoubleMean(values(value)),
load: computeMean,
net: value => computeDoubleMean(value) / kibPower,
ram: stats => computeMean(getMemoryUsedMetric(stats)) / gibPower,
ram: value => computeMean(value) / gibPower,
}

const DAYS_TO_KEEP = {
daily: 1,
weekly: 7,
monthly: 30,
}
function getLastDays(data, periodicity) {
const daysToKeep = DAYS_TO_KEEP[periodicity]
const expectedData = {}
for (const [key, value] of Object.entries(data)) {
if (Array.isArray(value)) {
// slice only applies to array
expectedData[key] = value.slice(-daysToKeep)
} else {
expectedData[key] = value
}
}
return expectedData
}

// ===================================================================

async function getVmsStats({ runningVms, xo }) {
async function getVmsStats({ runningVms, periodicity, xo }) {
return orderBy(
await Promise.all(
map(runningVms, async vm => {
Expand All @@ -285,21 +304,21 @@ async function getVmsStats({ runningVms, xo }) {
}
})

const iopsRead = METRICS_MEAN.iops(get(stats.iops, 'r'))
const iopsWrite = METRICS_MEAN.iops(get(stats.iops, 'w'))
const iopsRead = METRICS_MEAN.iops(getLastDays(get(stats.iops, 'r'), periodicity))
const iopsWrite = METRICS_MEAN.iops(getLastDays(get(stats.iops, 'w'), periodicity))
return {
uuid: vm.uuid,
name: vm.name_label,
addresses: Object.values(vm.addresses),
cpu: METRICS_MEAN.cpu(stats.cpus),
ram: METRICS_MEAN.ram(stats),
diskRead: METRICS_MEAN.disk(get(stats.xvds, 'r')),
diskWrite: METRICS_MEAN.disk(get(stats.xvds, 'w')),
cpu: METRICS_MEAN.cpu(getLastDays(stats.cpus, periodicity)),
ram: METRICS_MEAN.ram(getLastDays(getMemoryUsedMetric(stats), periodicity)),
diskRead: METRICS_MEAN.disk(getLastDays(get(stats.xvds, 'r'), periodicity)),
diskWrite: METRICS_MEAN.disk(getLastDays(get(stats.xvds, 'w'), periodicity)),
iopsRead,
iopsWrite,
iopsTotal: iopsRead + iopsWrite,
netReception: METRICS_MEAN.net(get(stats.vifs, 'rx')),
netTransmission: METRICS_MEAN.net(get(stats.vifs, 'tx')),
netReception: METRICS_MEAN.net(getLastDays(get(stats.vifs, 'rx'), periodicity)),
netTransmission: METRICS_MEAN.net(getLastDays(get(stats.vifs, 'tx'), periodicity)),
}
})
),
Expand All @@ -308,7 +327,7 @@ async function getVmsStats({ runningVms, xo }) {
)
}

async function getHostsStats({ runningHosts, xo }) {
async function getHostsStats({ runningHosts, periodicity, xo }) {
return orderBy(
await Promise.all(
map(runningHosts, async host => {
Expand All @@ -325,11 +344,11 @@ async function getHostsStats({ runningHosts, xo }) {
return {
uuid: host.uuid,
name: host.name_label,
cpu: METRICS_MEAN.cpu(stats.cpus),
ram: METRICS_MEAN.ram(stats),
load: METRICS_MEAN.load(stats.load),
netReception: METRICS_MEAN.net(get(stats.pifs, 'rx')),
netTransmission: METRICS_MEAN.net(get(stats.pifs, 'tx')),
cpu: METRICS_MEAN.cpu(getLastDays(stats.cpus, periodicity)),
ram: METRICS_MEAN.ram(getLastDays(getMemoryUsedMetric(stats), periodicity)),
load: METRICS_MEAN.load(getLastDays(stats.load, periodicity)),
netReception: METRICS_MEAN.net(getLastDays(get(stats.pifs, 'rx'), periodicity)),
netTransmission: METRICS_MEAN.net(getLastDays(get(stats.pifs, 'tx'), periodicity)),
}
})
),
Expand All @@ -338,7 +357,7 @@ async function getHostsStats({ runningHosts, xo }) {
)
}

async function getSrsStats({ xo, xoObjects }) {
async function getSrsStats({ periodicity, xo, xoObjects }) {
return orderBy(
await asyncMapSettled(
filter(xoObjects, obj => obj.type === 'SR' && obj.size > 0 && obj.$PBDs.length > 0),
Expand All @@ -362,8 +381,8 @@ async function getSrsStats({ xo, xoObjects }) {
}
})

const iopsRead = computeMean(get(stats.iops, 'r'))
const iopsWrite = computeMean(get(stats.iops, 'w'))
const iopsRead = computeMean(getLastDays(get(stats.iops, 'r'), periodicity))
const iopsWrite = computeMean(getLastDays(get(stats.iops, 'w'), periodicity))

return {
uuid: sr.uuid,
Expand Down Expand Up @@ -562,7 +581,7 @@ async function computeEvolution({ storedStatsPath, ...newStats }) {
}
}

async function dataBuilder({ currDate, xo, storedStatsPath, all }) {
async function dataBuilder({ currDate, periodicity, xo, storedStatsPath, all }) {
const xoObjects = values(xo.getObjects())
const runningVms = filter(xoObjects, { type: 'VM', power_state: 'Running' })
const haltedVms = filter(xoObjects, { type: 'VM', power_state: 'Halted' })
Expand All @@ -573,9 +592,9 @@ async function dataBuilder({ currDate, xo, storedStatsPath, all }) {
const haltedHosts = filter(xoObjects, { type: 'host', power_state: 'Halted' })
const [users, vmsStats, hostsStats, srsStats, hostsMissingPatches] = await Promise.all([
xo.getAllUsers(),
getVmsStats({ xo, runningVms }),
getHostsStats({ xo, runningHosts }),
getSrsStats({ xo, xoObjects }),
getVmsStats({ xo, runningVms, periodicity }),
getHostsStats({ xo, runningHosts, periodicity }),
getSrsStats({ xo, xoObjects, periodicity }),
getHostsMissingPatches({ xo, runningHosts }),
])

Expand Down Expand Up @@ -756,6 +775,7 @@ class UsageReportPlugin {
const currDate = new Date().toISOString().slice(0, 10)
const data = await dataBuilder({
currDate,
periodicity: this._conf.periodicity,
xo,
storedStatsPath: this._storedStatsPath,
all: this._conf.all,
Expand Down