diff --git a/src/app.ts b/src/app.ts index bcc51f7..54d4639 100644 --- a/src/app.ts +++ b/src/app.ts @@ -467,6 +467,14 @@ app.get('/groups/:name/instance-audit', async (req, res, next) => { } }); +app.get('/groups/:name/group-metrics', async (req, res, next) => { + try { + await h.getGroupMetrics(req, res); + } catch (err) { + next(err); + } +}); + app.get('/groups/:name/group-audit', async (req, res, next) => { try { await h.getGroupAudit(req, res); diff --git a/src/handlers.ts b/src/handlers.ts index c38f70b..fde082f 100644 --- a/src/handlers.ts +++ b/src/handlers.ts @@ -417,6 +417,32 @@ class Handlers { res.send({ audit }); } + async getGroupMetrics(req: Request, res: Response): Promise { + const groupName = req.params.name; + const ctx = req.context; + const group = await this.instanceGroupManager.getInstanceGroup(groupName); + + if (!group) { + res.sendStatus(404); + return; + } + + const maxPeriodCount = Math.max( + group.scalingOptions.scaleUpPeriodsCount, + group.scalingOptions.scaleDownPeriodsCount, + ); + + const metrics = await this.instanceTracker.getMetricInventoryPerPeriod( + ctx, + groupName, + maxPeriodCount, + group.scalingOptions.scalePeriod, + ); + + res.status(200); + res.send({ metrics }); + } + async resetInstanceGroups(req: Request, res: Response): Promise { req.context.logger.info('Resetting instance groups'); const ctx = req.context;