graphs: add app response in system graphs

This commit is contained in:
Girish Ramakrishnan
2022-10-12 22:08:10 +02:00
parent 4fe0402735
commit b5da4143c9
2 changed files with 11 additions and 5 deletions
+10 -4
View File
@@ -2,10 +2,11 @@
exports = module.exports = {
getSystem,
getByApp
getApp
};
const assert = require('assert'),
const apps = require('./apps.js'),
assert = require('assert'),
BoxError = require('./boxerror.js'),
docker = require('./docker.js'),
safe = require('safetydance'),
@@ -24,7 +25,7 @@ async function getGraphiteUrl() {
return `http://${ip}:8000/graphite-web/render`;
}
async function getByApp(app, fromMinutes, noNullPoints) {
async function getApp(app, fromMinutes, noNullPoints) {
assert.strictEqual(typeof app, 'object');
assert.strictEqual(typeof fromMinutes, 'number');
assert.strictEqual(typeof noNullPoints, 'boolean');
@@ -91,5 +92,10 @@ async function getSystem(fromMinutes, noNullPoints) {
if (memCpuError) throw new BoxError(BoxError.NETWORK_ERROR, memCpuError.message);
if (memCpuResponse.status !== 200) throw new BoxError(BoxError.EXTERNAL_ERROR, `Unknown error: ${memCpuResponse.status} ${memCpuResponse.text}`);
return { cpu: memCpuResponse.body[0], memory: memCpuResponse.body[1] };
const appResponses = {};
for (const app of await apps.list()) {
appResponses[app.id] = await getApp(app, fromMinutes, noNullPoints);
}
return { cpu: memCpuResponse.body[0], memory: memCpuResponse.body[1], apps: appResponses };
}
+1 -1
View File
@@ -29,7 +29,7 @@ async function getAppGraphs(req, res, next) {
const fromMinutes = parseInt(req.query.fromMinutes);
const noNullPoints = !!req.query.noNullPoints;
const [error, result] = await safe(graphs.getByApp(req.app, fromMinutes, noNullPoints));
const [error, result] = await safe(graphs.getApp(req.app, fromMinutes, noNullPoints));
if (error) return next(new HttpError(500, error));
next(new HttpSuccess(200, result));