diff --git a/src/graphs.js b/src/graphs.js index 78f197763..9191da200 100644 --- a/src/graphs.js +++ b/src/graphs.js @@ -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 }; } diff --git a/src/routes/graphs.js b/src/routes/graphs.js index c77ff243a..3706f1dc5 100644 --- a/src/routes/graphs.js +++ b/src/routes/graphs.js @@ -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));