Use explicit app graphs api

This commit is contained in:
Johannes Zellner
2022-09-14 13:03:24 +02:00
parent be72bfdb9f
commit 380b41a1b4
2 changed files with 13 additions and 8 deletions
+9
View File
@@ -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 = [];
+4 -8
View File
@@ -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);
});
}
};