Skip to content

Commit

Permalink
feat(xo-server/rest-api): expose vms/hosts stats (#8378)
Browse files Browse the repository at this point in the history
`GET /rest/v0/vms/f26eb0a5-1d91-4682-ae58-96df405a3af6/stats`
`GET /rest/v0/hosts/f26eb0a5-1d91-4682-ae58-96df405a3af6/stats`
  • Loading branch information
MathieuRA authored Feb 26, 2025
1 parent 468732c commit e567a3b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/<vms|hosts>/<id>/stats` (PR [#8378](https://github.com/vatesfr/xen-orchestra/pull/8378))

### Bug fixes

Expand Down
12 changes: 12 additions & 0 deletions packages/xo-server/src/xo-mixins/rest-api.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down

0 comments on commit e567a3b

Please sign in to comment.