Use system graphs API

This commit is contained in:
Girish Ramakrishnan
2022-09-15 12:12:32 +02:00
parent 0d573e0213
commit e938aae257
2 changed files with 30 additions and 26 deletions
+16 -25
View File
@@ -82,7 +82,7 @@ angular.module('Application').controller('SystemController', ['$scope', '$locati
diskName = diskName.replace(/\/|\./g, '_');
// use collectd instead of df data so the timeframe matches with the du data
Client.graphs([
Client.getSystemGraphs([
'absolute(collectd.localhost.df-' + diskName + '.df_complex-free)',
'absolute(collectd.localhost.df-' + diskName + '.df_complex-reserved)', // reserved for root (default: 5%) tune2fs -l/m
'absolute(collectd.localhost.df-' + diskName + '.df_complex-used)'
@@ -163,7 +163,7 @@ angular.module('Application').controller('SystemController', ['$scope', '$locati
},
show: function () {
var apps = Client.getInstalledApps();
var appsById = Client.getInstalledAppsByAppId();
// both in minutes
var timePeriod = $scope.graphs.period * 60;
@@ -191,20 +191,19 @@ angular.module('Application').controller('SystemController', ['$scope', '$locati
data: datapoints
}];
if (Array.isArray(appsData)) {
appsData.forEach(function (data, index) {
if (!data.datapoints.some(function (p) { return p[0] > 1024*1024*1024; })) return;
Object.keys(appsData).forEach(function (appId) {
var data = appsData[appId].memory;
if (!data.datapoints.some(function (p) { return p[0] > 1024*1024*1024; })) return;
datasets.push({
label: apps[index].fqdn,
fill: false,
borderColor: getRandomColor(),
borderWidth: 1,
radius: 0,
data: data.datapoints.map(function (d) { return parseInt((d[0] / valueDivider).toFixed(2)); })
});
datasets.push({
label: appsById[appId].fqdn,
fill: false,
borderColor: getRandomColor(),
borderWidth: 1,
radius: 0,
data: data.datapoints.map(function (d) { return parseInt((d[0] / valueDivider).toFixed(2)); })
});
}
});
var chartData = {
labels: labels,
@@ -242,19 +241,11 @@ angular.module('Application').controller('SystemController', ['$scope', '$locati
$scope.graphs[chartPropertyName] = new Chart(ctx, { type: 'line', data: chartData, options: options });
}
var cpuQuery = 'summarize(sum(collectd.localhost.aggregation-cpu-average.cpu-system, collectd.localhost.aggregation-cpu-average.cpu-user), "' + timeBucketSize + 'min", "avg")';
var systemMemoryQuery = 'summarize(sum(collectd.localhost.memory.memory-used, collectd.localhost.swap.swap-used), "' + timeBucketSize + 'min", "avg")';
var appQueries = [];
apps.forEach(function (app) {
appQueries.push('summarize(collectd.localhost.table-' + app.id + '-memory.gauge-rss, "' + timeBucketSize + 'min", "avg")');
});
Client.graphs([ cpuQuery, systemMemoryQuery ].concat(appQueries), '-' + timePeriod + 'min', {}, function (error, result) {
Client.getSystemGraphs(timePeriod, function (error, result) {
if (error) return console.error(error);
fillGraph('#graphsCPUChart', result[0], null, 'CPU Usage', 'cpuChart', 100, 1);
fillGraph('#graphsSystemMemoryChart', result[1], result.slice(2), 'Memory', 'memoryChart', Number.parseInt(($scope.memory.memory + $scope.memory.swap) / 1024 / 1024), 1024 * 1024);
fillGraph('#graphsCPUChart', result.cpu, [], 'CPU Usage', 'cpuChart', 100, 1);
fillGraph('#graphsSystemMemoryChart', result.memory, result.apps, 'Memory', 'memoryChart', Number.parseInt(($scope.memory.memory + $scope.memory.swap) / 1024 / 1024), 1024 * 1024);
});
}
};