graphs: send service graphs

This commit is contained in:
Girish Ramakrishnan
2022-10-13 20:32:36 +02:00
parent 6d8c3febac
commit 4015afc69c
8 changed files with 67 additions and 54 deletions

View File

@@ -58,6 +58,7 @@ exports = module.exports = {
updateBackup,
getLimits,
getGraphs,
load
};
@@ -68,6 +69,7 @@ const apps = require('../apps.js'),
BoxError = require('../boxerror.js'),
constants = require('../constants.js'),
debug = require('debug')('box:routes/apps'),
graphs = require('../graphs.js'),
HttpError = require('connect-lastmile').HttpError,
HttpSuccess = require('connect-lastmile').HttpSuccess,
safe = require('safetydance'),
@@ -959,3 +961,16 @@ async function getLimits(req, res, next) {
next(new HttpSuccess(200, { limits }));
}
async function getGraphs(req, res, next) {
assert.strictEqual(typeof req.app, 'object');
if (!req.query.fromMinutes || !parseInt(req.query.fromMinutes)) return next(new HttpError(400, 'fromMinutes must be a number'));
const fromMinutes = parseInt(req.query.fromMinutes);
const noNullPoints = !!req.query.noNullPoints;
const [error, result] = await safe(graphs.getContainerStats(req.app.id, fromMinutes, noNullPoints));
if (error) return next(new HttpError(500, error));
next(new HttpSuccess(200, result));
}