Rework system graphs
This commit is contained in:
@@ -42,35 +42,42 @@ angular.module('Application').controller('SystemController', ['$scope', '$locati
|
||||
update: function () {
|
||||
$scope.disks.busy = true;
|
||||
|
||||
Client.getSystemGraphs($scope.graphs.period * 60, function (error, result) {
|
||||
if (error) return $scope.disks.setError(error);
|
||||
|
||||
console.log(result);
|
||||
|
||||
$scope.disks.disks = result.disks; // [ { filesystem, type, size, used, available, capacity, mountpoint }]
|
||||
|
||||
// https://graphite.readthedocs.io/en/latest/render_api.html#paths-and-wildcards
|
||||
// on scaleway, for some reason docker devices are collected as part of collectd
|
||||
// until we figure why just hardcode popular disk devices - https://www.mjmwired.net/kernel/Documentation/devices.txt
|
||||
Client.disks(function (error, result) {
|
||||
if (error) return $scope.disks.setError(error);
|
||||
// Client.disks(function (error, result) {
|
||||
// if (error) return $scope.disks.setError(error);
|
||||
|
||||
// segregate locations into the correct disks based on 'filesystem'
|
||||
result.disks.forEach(function (disk, index) {
|
||||
disk.id = index;
|
||||
disk.contains = [];
|
||||
// // segregate locations into the correct disks based on 'filesystem'
|
||||
// result.disks.forEach(function (disk, index) {
|
||||
// disk.id = index;
|
||||
// disk.contains = [];
|
||||
|
||||
if (disk.filesystem === result.platformDataDisk) disk.contains.push({ type: 'standard', label: 'Platform data', id: 'platformdata', usage: 0 });
|
||||
if (disk.filesystem === result.boxDataDisk) disk.contains.push({ type: 'standard', label: 'Box data', id: 'boxdata', usage: 0 });
|
||||
if (disk.filesystem === result.dockerDataDisk) disk.contains.push({ type: 'standard', label: 'Docker images', id: 'docker', usage: 0 });
|
||||
if (disk.filesystem === result.mailDataDisk) disk.contains.push({ type: 'standard', label: 'Email data', id: 'maildata', usage: 0 });
|
||||
if (disk.filesystem === result.backupsDisk) disk.contains.push({ type: 'standard', label: 'Backup data', id: 'cloudron-backup', usage: 0 });
|
||||
// if (disk.filesystem === result.platformDataDisk) disk.contains.push({ type: 'standard', label: 'Platform data', id: 'platformdata', usage: 0 });
|
||||
// if (disk.filesystem === result.boxDataDisk) disk.contains.push({ type: 'standard', label: 'Box data', id: 'boxdata', usage: 0 });
|
||||
// if (disk.filesystem === result.dockerDataDisk) disk.contains.push({ type: 'standard', label: 'Docker images', id: 'docker', usage: 0 });
|
||||
// if (disk.filesystem === result.mailDataDisk) disk.contains.push({ type: 'standard', label: 'Email data', id: 'maildata', usage: 0 });
|
||||
// if (disk.filesystem === result.backupsDisk) disk.contains.push({ type: 'standard', label: 'Backup data', id: 'cloudron-backup', usage: 0 });
|
||||
|
||||
const apps = Object.keys(result.apps).filter(function (appId) { return result.apps[appId] === disk.filesystem; });
|
||||
apps.forEach(function (appId) {
|
||||
var app = Client.getCachedAppSync(appId);
|
||||
disk.contains.push({ type: 'app', app: app, label: app.label || app.fqdn, id: appId, usage: 0 });
|
||||
});
|
||||
// const apps = Object.keys(result.apps).filter(function (appId) { return result.apps[appId] === disk.filesystem; });
|
||||
// apps.forEach(function (appId) {
|
||||
// var app = Client.getCachedAppSync(appId);
|
||||
// disk.contains.push({ type: 'app', app: app, label: app.label || app.fqdn, id: appId, usage: 0 });
|
||||
// });
|
||||
|
||||
const volumes = Object.keys(result.volumes).filter(function (volumeId) { return result.volumes[volumeId] === disk.filesystem; });
|
||||
volumes.forEach(function (volumeId) {
|
||||
var volume = $scope.volumesById[volumeId];
|
||||
disk.contains.push({ type: 'volume', volume: volume, label: volume.name, id: volumeId, usage: 0 });
|
||||
});
|
||||
});
|
||||
// const volumes = Object.keys(result.volumes).filter(function (volumeId) { return result.volumes[volumeId] === disk.filesystem; });
|
||||
// volumes.forEach(function (volumeId) {
|
||||
// var volume = $scope.volumesById[volumeId];
|
||||
// disk.contains.push({ type: 'volume', volume: volume, label: volume.name, id: volumeId, usage: 0 });
|
||||
// });
|
||||
// });
|
||||
|
||||
$scope.disks.disks = result.disks; // [ { filesystem, type, size, used, available, capacity, mountpoint }]
|
||||
|
||||
@@ -78,70 +85,70 @@ angular.module('Application').controller('SystemController', ['$scope', '$locati
|
||||
async.eachSeries(result.disks, function (disk, iteratorCallback) {
|
||||
// /dev/sda1 -> sda1
|
||||
// /dev/mapper/foo.com -> mapper_foo_com (see #348)
|
||||
var diskName = disk.filesystem.slice(disk.filesystem.indexOf('/', 1) + 1);
|
||||
diskName = diskName.replace(/\/|\./g, '_');
|
||||
// var diskName = disk.filesystem.slice(disk.filesystem.indexOf('/', 1) + 1);
|
||||
// diskName = diskName.replace(/\/|\./g, '_');
|
||||
|
||||
// use collectd instead of df data so the timeframe matches with the du data
|
||||
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)'
|
||||
], '-1min', {}, function (error, data) {
|
||||
if (error) return iteratorCallback(error);
|
||||
// // use collectd instead of df data so the timeframe matches with the du data
|
||||
// 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)'
|
||||
// ], '-1min', {}, function (error, data) {
|
||||
// if (error) return iteratorCallback(error);
|
||||
|
||||
disk.size = data[2].datapoints[0][0] + data[1].datapoints[0][0] + data[0].datapoints[0][0];
|
||||
disk.free = data[0].datapoints[0][0];
|
||||
disk.occupied = data[2].datapoints[0][0];
|
||||
// disk.size = data[2].datapoints[0][0] + data[1].datapoints[0][0] + data[0].datapoints[0][0];
|
||||
// disk.free = data[0].datapoints[0][0];
|
||||
// disk.occupied = data[2].datapoints[0][0];
|
||||
|
||||
colorIndex = 0;
|
||||
disk.contains.forEach(function (content) {
|
||||
content.color = getNextColor();
|
||||
});
|
||||
|
||||
// get disk usage data
|
||||
var graphiteQueries = disk.contains.map(function (content) {
|
||||
return 'absolute(collectd.localhost.du-' + content.id + '.capacity-usage)';
|
||||
});
|
||||
|
||||
Client.graphs(graphiteQueries, '-1day', { noNullPoints: true }, function (error, data) {
|
||||
if (error) return iteratorCallback(error);
|
||||
|
||||
var usageOther = disk.occupied;
|
||||
|
||||
data.forEach(function (d) {
|
||||
var content = disk.contains.find(function (content) { return d.target.indexOf(content.id) !== -1; });
|
||||
if (!content) return; // didn't match any content
|
||||
|
||||
var tmp = d.datapoints[d.datapoints.length-1][0];
|
||||
content.usage = tmp;
|
||||
|
||||
// deduct from overal disk usage to track other
|
||||
usageOther -= tmp;
|
||||
});
|
||||
|
||||
disk.contains.sort(function (x, y) { return y.usage - x.usage; }); // sort by usage
|
||||
|
||||
if ($scope.disks.disks[0] === disk) { // the root mount point is the first disk. keep this 'contains' in the end
|
||||
disk.contains.push({
|
||||
type: 'standard',
|
||||
label: 'Everything else (Ubuntu, Swap, etc)',
|
||||
id: 'other',
|
||||
color: '#27CE65',
|
||||
usage: usageOther
|
||||
});
|
||||
} else {
|
||||
disk.contains.push({
|
||||
type: 'standard',
|
||||
label: 'Used',
|
||||
id: 'other',
|
||||
color: '#27CE65',
|
||||
usage: usageOther
|
||||
});
|
||||
}
|
||||
|
||||
iteratorCallback();
|
||||
});
|
||||
colorIndex = 0;
|
||||
disk.contains.forEach(function (content) {
|
||||
content.color = getNextColor();
|
||||
});
|
||||
|
||||
// // get disk usage data
|
||||
// var graphiteQueries = disk.contains.map(function (content) {
|
||||
// return 'absolute(collectd.localhost.du-' + content.id + '.capacity-usage)';
|
||||
// });
|
||||
|
||||
// Client.graphs(graphiteQueries, '-1day', { noNullPoints: true }, function (error, data) {
|
||||
// if (error) return iteratorCallback(error);
|
||||
|
||||
var usageOther = disk.occupied;
|
||||
|
||||
// data.forEach(function (d) {
|
||||
// var content = disk.contains.find(function (content) { return d.target.indexOf(content.id) !== -1; });
|
||||
// if (!content) return; // didn't match any content
|
||||
|
||||
// var tmp = d.datapoints[d.datapoints.length-1][0];
|
||||
// content.usage = tmp;
|
||||
|
||||
// // deduct from overal disk usage to track other
|
||||
// usageOther -= tmp;
|
||||
// });
|
||||
|
||||
disk.contains.sort(function (x, y) { return y.usage - x.usage; }); // sort by usage
|
||||
|
||||
if ($scope.disks.disks[0] === disk) { // the root mount point is the first disk. keep this 'contains' in the end
|
||||
disk.contains.push({
|
||||
type: 'standard',
|
||||
label: 'Everything else (Ubuntu, Swap, etc)',
|
||||
id: 'other',
|
||||
color: '#27CE65',
|
||||
usage: usageOther
|
||||
});
|
||||
} else {
|
||||
disk.contains.push({
|
||||
type: 'standard',
|
||||
label: 'Used',
|
||||
id: 'other',
|
||||
color: '#27CE65',
|
||||
usage: usageOther
|
||||
});
|
||||
}
|
||||
|
||||
iteratorCallback();
|
||||
// });
|
||||
// });
|
||||
}, function iteratorDone(error) {
|
||||
if (error) $scope.disks.setError(error);
|
||||
$scope.disks.busy = false;
|
||||
@@ -244,7 +251,7 @@ angular.module('Application').controller('SystemController', ['$scope', '$locati
|
||||
Client.getSystemGraphs(timePeriod, function (error, result) {
|
||||
if (error) return console.error(error);
|
||||
|
||||
fillGraph('#graphsCPUChart', result.cpu, [], 'CPU Usage', 'cpuChart', 100, 1);
|
||||
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);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user