From e567a3b3589c3c3eee15cf87868015887185f365 Mon Sep 17 00:00:00 2001 From: Mathieu <70369997+MathieuRA@users.noreply.github.com> Date: Wed, 26 Feb 2025 12:01:03 +0100 Subject: [PATCH] feat(xo-server/rest-api): expose vms/hosts stats (#8378) `GET /rest/v0/vms/f26eb0a5-1d91-4682-ae58-96df405a3af6/stats` `GET /rest/v0/hosts/f26eb0a5-1d91-4682-ae58-96df405a3af6/stats` --- CHANGELOG.unreleased.md | 1 + packages/xo-server/src/xo-mixins/rest-api.mjs | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/CHANGELOG.unreleased.md b/CHANGELOG.unreleased.md index 86cef5977ff..191a0dd7766 100644 --- a/CHANGELOG.unreleased.md +++ b/CHANGELOG.unreleased.md @@ -17,6 +17,7 @@ - **XO 6:** - [i18n] Add Swedish, update Czech and Spanish translations (contributions made by [@xiscoj](https://github.com/xiscoj), [@p-bo](https://github.com/p-bo) and [Jonas](https://translate.vates.tech/user/Jonas/)) (PR [#8294](https://github.com/vatesfr/xen-orchestra/pull/8294)) - [i18n] Merge XO 6 translations files into one file in web-core ([PR #8380](https://github.com/vatesfr/xen-orchestra/pull/8380)) +- [REST API] VM/Host stats available at `/rest/v0///stats` (PR [#8378](https://github.com/vatesfr/xen-orchestra/pull/8378)) ### Bug fixes diff --git a/packages/xo-server/src/xo-mixins/rest-api.mjs b/packages/xo-server/src/xo-mixins/rest-api.mjs index 1ea8837be4c..476a8e4d764 100644 --- a/packages/xo-server/src/xo-mixins/rest-api.mjs +++ b/packages/xo-server/src/xo-mixins/rest-api.mjs @@ -1356,6 +1356,18 @@ export default class RestApi { }) ) + api.get( + '/:collection(vms|hosts)/:object/stats', + wrap(async (req, res) => { + const object = req.object + const method = object.type === 'VM' ? 'getXapiVmStats' : 'getXapiHostStats' + const granularity = req.query.granularity + + const result = await app[method](object.id, granularity) + return res.json(result) + }) + ) + api.get('/:collection/:object', (req, res, next) => { const { collection } = req if (swaggerEndpoints.includes(collection.id)) {