(function() {
"use strict";
///////////////////////////////////////////////////////////
////////////////// Module Directives /////////////////// //
///////////////////////////////////////////////////////////
angular.module('linuxDash').directive('diskSpace', ['server', function(server) {
return {
restrict: 'E',
scope: {},
templateUrl: 'templates/modules/disk-space.html',
link: function(scope) {
scope.heading = "Disk Partitions";
scope.getData = function() {
server.get('disk_partitions', function(serverResponseData) {
scope.diskSpaceData = serverResponseData;
});
scope.lastGet = new Date().getTime();
};
scope.getData();
scope.getKB = function(stringSize) {
var lastChar = stringSize.slice(-1),
size = parseInt(stringSize);
switch (lastChar) {
case 'M':
return size * Math.pow(1024, 1);
case 'G':
return size * Math.pow(1024, 2);
case 'T':
return size * Math.pow(1024, 3);
case 'P':
return size * Math.pow(1024, 4);
case 'E':
return size * Math.pow(1024, 5);
case 'Z':
return size * Math.pow(1024, 6);
case 'Y':
return size * Math.pow(1024, 7);
default:
return size;
}
};
}
};
}]);
angular.module('linuxDash').directive('ramChart', ['server', function(server) {
return {
restrict: 'E',
scope: {},
templateUrl: 'templates/modules/ram-chart.html',
link: function(scope) {
// get max ram available on machine before we
// can start charting
server.get('current_ram', function(resp) {
scope.maxRam = resp.total;
scope.minRam = 0;
});
scope.ramToDisplay = function(serverResponseData) {
return serverResponseData.used;
};
var humanizeRam = function (ramInMB) {
var ram = {
value: parseInt(ramInMB, 10),
unit: 'MB',
};
// if ram > 1,000 MB, use GB
if (ram.value > 1000) {
ram = {
value: (ramInMB/1024).toFixed(2),
unit: 'GB',
};
}
return ram.value + ' ' + ram.unit;
};
scope.ramMetrics = [{
name: 'Used',
generate: function(serverResponseData) {
var ratio = serverResponseData.used / serverResponseData.total;
var percentage = parseInt(ratio * 100);
var usedRam = humanizeRam(serverResponseData.used);
return usedRam + ' (' + percentage.toString() + '%)';
}
},
{
name: 'Free',
generate: function(serverResponseData) {
var freeRam = humanizeRam(serverResponseData.free);
var totalRam = humanizeRam(serverResponseData.total);
return freeRam + ' of ' + totalRam;
}
}];
}
};
}]);
angular.module('linuxDash').directive('cpuAvgLoadChart', ['server', function(server) {
return {
restrict: 'E',
scope: {},
templateUrl: 'templates/modules/cpu-load.html',
link: function(scope) {
scope.units = '%';
}
};
}]);
angular.module('linuxDash').directive('cpuUtilizationChart', ['server', function(server) {
return {
restrict: 'E',
scope: {},
templateUrl: 'templates/modules/cpu-utilization-chart.html',
link: function(scope) {
scope.min = 0;
scope.max = 100;
scope.displayValue = function(serverResponseData) {
return serverResponseData;
};
scope.utilMetrics = [{
name: 'Usage',
generate: function(serverResponseData) {
return serverResponseData + ' %';
}
}];
}
};
}]);
angular.module('linuxDash').directive('uploadTransferRateChart', ['server', function(server) {
return {
restrict: 'E',
scope: {},
templateUrl: 'templates/modules/upload-transfer-rate.html',
link: function(scope) {
scope.delay = 2000;
scope.units = 'KB/s';
}
};
}]);
angular.module('linuxDash').directive('downloadTransferRateChart', ['server', function(server) {
return {
restrict: 'E',
scope: {},
templateUrl: 'templates/modules/download-transfer-rate.html',
link: function(scope) {
scope.delay = 2000;
scope.units = 'KB/s';
}
};
}]);
//////////////////////////////////////////////////////////
/////////////// Table Data Modules //////////////////// //
//////////////////////////////////////////////////////////
var simpleTableModules = [
{
name: 'machineInfo',
template: ''
},
{
name: 'ipAddresses',
template: ''
},
{
name: 'ramIntensiveProcesses',
template: ''
},
{
name: 'cpuIntensiveProcesses',
template: ''
},
{
name: 'networkConnections',
template: ''
},
{
name: 'serverAccounts',
template: ''
},
{
name: 'loggedInAccounts',
template: ''
},
{
name: 'recentLogins',
template: ''
},
{
name: 'arpCacheTable',
template: ''
},
{
name: 'commonApplications',
template: ''
},
{
name: 'pingSpeeds',
template: ''
},
{
name: 'bandwidth',
template: ''
},
{
name: 'swapUsage',
template: ''
},
{
name: 'internetSpeed',
template: ''
},
{
name: 'memcached',
template: ''
},
{
name: 'redis',
template: ''
},
{
name: 'memoryInfo',
template: ''
},
{
name: 'cpuInfo',
template: ''
},
{
name: 'ioStats',
template: ''
},
{
name: 'scheduledCrons',
template: ''
},
{
name: 'cronHistory',
template: ''
}
];
simpleTableModules.forEach(function(module, key) {
angular.module('linuxDash').directive(module.name, ['server', function(server) {
var moduleDirective = {
restrict: 'E',
scope: {}
};
if (module.templateUrl) {
moduleDirective['templateUrl'] = 'templates/modules/' + module.templateUrl
}
if (module.template) {
moduleDirective['template'] = module.template;
}
return moduleDirective;
}]);
});
}());