diff --git a/src/js/client.js b/src/js/client.js index ffe10a3af..8fb9cb667 100644 --- a/src/js/client.js +++ b/src/js/client.js @@ -1797,6 +1797,15 @@ angular.module('Application').service('Client', ['$http', '$interval', '$timeout }); }; + Client.prototype.getAppGraphs = function (appId, fromMinutes, callback) { + get('/api/v1/apps/' + appId + '/graphs', { params: { fromMinutes: fromMinutes } }, function (error, data, status) { + if (error) return callback(error); + if (status !== 200) return callback(new ClientError(status, data)); + + callback(null, data); + }); + }; + Client.prototype.graphs = function (targets, from, options, callback) { // if we have a lot of apps, targets can be very large. node will just disconnect since it exceeds header size var size = 10, chunks = []; diff --git a/src/views/app.js b/src/views/app.js index ce3bc1489..a633ed74e 100644 --- a/src/views/app.js +++ b/src/views/app.js @@ -799,9 +799,8 @@ angular.module('Application').controller('AppController', ['$scope', '$location' }, show: function () { - // both in minutes + // in minutes var timePeriod = $scope.graphs.period * 60; - var timeBucketSize = $scope.graphs.period > 24 ? (6*60) : 5; function fillGraph(canvasId, data, label, chartPropertyName, max) { if (!data) return; // no data available yet @@ -871,16 +870,13 @@ angular.module('Application').controller('AppController', ['$scope', '$location' $scope.graphs[chartPropertyName] = new Chart(ctx, { type: 'line', data: graphData, options: options }); } - var memoryQuery = 'summarize(sum(collectd.localhost.table-' + appId + '-memory.gauge-rss, collectd.localhost.table-' + appId + '-memory.gauge-swap), "' + timeBucketSize + 'min", "avg")'; - var diskQuery = 'summarize(collectd.localhost.du-' + appId + '.capacity-usage, "' + timeBucketSize + 'min", "avg")'; - - Client.graphs([ memoryQuery, diskQuery ], '-' + timePeriod + 'min', { appId: appId }, function (error, result) { + Client.getAppGraphs(appId, timePeriod, function (error, result) { if (error) return console.error(error); var currentMemoryLimit = $scope.app.memoryLimit || $scope.app.manifest.memoryLimit || (256 * 1024 * 1024); - fillGraph('#graphsMemoryChart', result[0], 'Memory', 'memoryChart', currentMemoryLimit / 1024 / 1024); - fillGraph('#graphsDiskChart', result[1], 'Disk', 'diskChart', 1024 / 1024); + fillGraph('#graphsMemoryChart', result.memory, 'Memory', 'memoryChart', currentMemoryLimit / 1024 / 1024); + fillGraph('#graphsDiskChart', result.disk, 'Disk', 'diskChart', 1024 / 1024); }); } };