-
+
diff --git a/glances/outputs/static/js/directives.js b/glances/outputs/static/js/directives.js
index d0f48d351ac4a7ce81a66ad9245cf9de3811c8c0..b45ccab1b08cf06e8f67c24864f9502987e78c89 100644
--- a/glances/outputs/static/js/directives.js
+++ b/glances/outputs/static/js/directives.js
@@ -34,45 +34,4 @@ glancesApp.directive("sortableTh", function() {
});
}
};
-});
-
-glancesApp.directive("glMonitorList", function() {
- return {
- restrict: 'AE',
- scope: {
- processes: '='
- },
- templateUrl: 'plugins/monitor.html',
- controller: function() {
-
- }
- }
-})
-
-glancesApp.directive("glMonitorProcess", function() {
- return {
- restrict: 'AE',
- require: "^glMonitorList",
- templateUrl: 'components/monitor_process.html',
- scope: {
- process: '='
- },
- link: function(scope, element, attrs) {
-
- count = scope.process.count;
- countMin = scope.process.countmin;
- countMax = scope.process.countmax;
-
- if (count > 0) {
- if ((countMin == null || count >= countMin) && (countMax == null || count <= countMax)) {
- scope.descriptionClass = 'ok';
- } else {
- scope.descriptionClass = 'careful';
- }
- } else {
- scope.descriptionClass = countMin == null ? 'ok' : 'critical';
- }
-
- }
- }
-});
+});
\ No newline at end of file
diff --git a/glances/outputs/static/js/filters.js b/glances/outputs/static/js/filters.js
index cab65529626cc26435dbed85d39678372c414812..63e5b85002c5622e6db5a7b02e9b071560eeec2a 100644
--- a/glances/outputs/static/js/filters.js
+++ b/glances/outputs/static/js/filters.js
@@ -20,7 +20,7 @@ glancesApp.filter('bytes', function() {
return function (bytes, low_precision) {
low_precision = low_precision || false;
if (isNaN(parseFloat(bytes)) || !isFinite(bytes) || bytes == 0){
- return '0';
+ return bytes;
}
var symbols = ['K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y'];
@@ -84,3 +84,27 @@ glancesApp.filter('leftPad', function($filter) {
return _.padLeft(value, length, chars);
}
});
+
+glancesApp.filter('timemillis', function() {
+ return function (array) {
+ var sum = 0.0;
+ for (var i = 0; i < array.length; i++) {
+ sum += array[i] * 1000.0;
+ }
+ return sum;
+ }
+});
+
+glancesApp.filter('timedelta', function($filter) {
+ return function (value) {
+ var sum = $filter('timemillis')(value);
+ var d = new Date(sum);
+
+ return {
+ hours: d.getUTCHours(), // TODO : multiple days ( * (d.getDay() * 24)))
+ minutes: d.getUTCMinutes(),
+ seconds: d.getUTCSeconds(),
+ milliseconds: parseInt("" + d.getUTCMilliseconds() / 10)
+ };
+ }
+});
diff --git a/glances/outputs/static/js/services/core/glances_stats.js b/glances/outputs/static/js/services/core/glances_stats.js
new file mode 100644
index 0000000000000000000000000000000000000000..6784a29b55879ab0ae31169d9281948b8f7daa9b
--- /dev/null
+++ b/glances/outputs/static/js/services/core/glances_stats.js
@@ -0,0 +1,84 @@
+glancesApp.service('GlancesStats', function($http, $injector, $q, GlancesPlugin) {
+ var _stats = [], _views = [], _limits = [];
+
+ var _plugins = {
+ 'alert': 'GlancesPluginAlert',
+ 'cpu': 'GlancesPluginCpu',
+ 'diskio': 'GlancesPluginDiskio',
+ 'docker': 'GlancesPluginDocker',
+ 'ip': 'GlancesPluginIp',
+ 'fs': 'GlancesPluginFs',
+ 'load': 'GlancesPluginLoad',
+ 'mem': 'GlancesPluginMem',
+ 'memswap': 'GlancesPluginMemSwap',
+ 'monitor': 'GlancesPluginMonitor',
+ 'network': 'GlancesPluginNetwork',
+ 'percpu': 'GlancesPluginPerCpu',
+ 'processcount': 'GlancesPluginProcessCount',
+ 'processlist': 'GlancesPluginProcessList',
+ 'sensors': 'GlancesPluginSensors',
+ 'system': 'GlancesPluginSystem',
+ 'uptime': 'GlancesPluginUptime'
+ };
+
+ this.getData = function() {
+ return $q.all([
+ this.getAllStats(),
+ this.getAllViews()
+ ]).then(function(results) {
+ return {
+ 'stats': results[0],
+ 'view': results[1]
+ };
+ });
+ };
+
+ this.getAllStats = function() {
+ return $http.get('/api/2/all').then(function (response) {
+ _stats = response.data;
+
+ return response.data;
+ });
+ };
+
+ this.getAllLimits = function() {
+ return $http.get('/api/2/all/limits').then(function (response) {
+ _limits = response.data;
+
+ return response.data;
+ });
+ };
+
+ this.getAllViews = function() {
+ return $http.get('/api/2/all/views').then(function (response) {
+ _views = response.data;
+
+ return response.data;
+ });
+ };
+
+ this.getHelp = function() {
+ return $http.get('/api/2/help').then(function (response) {
+ return response.data;
+ });
+ };
+
+ this.getPlugin = function(name) {
+ var plugin = _plugins[name];
+
+ if (plugin === undefined) {
+ throw "Plugin '" + name + "' not found";
+ }
+
+ plugin = $injector.get(plugin);
+ plugin.setData(_stats, _views);
+
+ return plugin;
+ };
+
+ // load limits to init GlancePlugin helper
+ this.getAllLimits().then(function(limits) {
+ GlancesPlugin.setLimits(limits);
+ });
+
+});
diff --git a/glances/outputs/static/js/services/plugins/glances_alert.js b/glances/outputs/static/js/services/plugins/glances_alert.js
new file mode 100644
index 0000000000000000000000000000000000000000..0b1466df8a3c7a89c4620f8a4b4961000d11d846
--- /dev/null
+++ b/glances/outputs/static/js/services/plugins/glances_alert.js
@@ -0,0 +1,45 @@
+glancesApp.service('GlancesPluginAlert', function () {
+ var _pluginName = "alert";
+ var _alerts = [];
+
+ this.setData = function (data, views) {
+ _alerts = [];
+
+ for (var i = 0; i < data[_pluginName].length; i++) {
+ var alertData = data[_pluginName][i];
+ var alert = {};
+
+ alert.name = alertData[3];
+ alert.level = alertData[2];
+ alert.begin = alertData[0] * 1000;
+ alert.end = alertData[1] * 1000;
+ alert.ongoing = alertData[1] == -1;
+ alert.min = alertData[6];
+ alert.mean = alertData[5];
+ alert.max = alertData[4];
+
+ if (!alert.ongoing) {
+ var duration = alert.end - alert.begin;
+ var seconds = parseInt((duration / 1000) % 60)
+ , minutes = parseInt((duration / (1000 * 60)) % 60)
+ , hours = parseInt((duration / (1000 * 60 * 60)) % 24);
+
+ alert.duration = _.padLeft(hours, 2, '0') + ":" + _.padLeft(minutes, 2, '0') + ":" + _.padLeft(seconds, 2, '0');
+ }
+
+ _alerts.push(alert);
+ }
+ };
+
+ this.hasAlerts = function () {
+ return _alerts.length > 0;
+ };
+
+ this.getAlerts = function () {
+ return _alerts;
+ };
+
+ this.count = function () {
+ return _alerts.length;
+ };
+});
diff --git a/glances/outputs/static/js/services/plugins/glances_cpu.js b/glances/outputs/static/js/services/plugins/glances_cpu.js
new file mode 100644
index 0000000000000000000000000000000000000000..5835b20913cac47e5ffbce26590192b536bb666b
--- /dev/null
+++ b/glances/outputs/static/js/services/plugins/glances_cpu.js
@@ -0,0 +1,35 @@
+glancesApp.service('GlancesPluginCpu', function() {
+ var _pluginName = "cpu";
+ var _view = {};
+
+ this.total = null;
+ this.user = null;
+ this.system = null;
+ this.idle = null;
+ this.nice = null;
+ this.irq = null;
+ this.iowait = null;
+ this.steal = null;
+
+ this.setData = function(data, views) {
+ data = data[_pluginName];
+ _view = views[_pluginName];
+
+ this.total = data.total;
+ this.user = data.user;
+ this.system = data.system;
+ this.idle = data.idle;
+ this.nice = data.nice;
+ this.irq = data.irq;
+ this.iowait = data.iowait;
+ this.steal = data.steal;
+ }
+
+ this.getDecoration = function(value) {
+ if(_view[value] == undefined) {
+ return;
+ }
+
+ return _view[value].decoration.toLowerCase();
+ }
+});
diff --git a/glances/outputs/static/js/services/plugins/glances_diskio.js b/glances/outputs/static/js/services/plugins/glances_diskio.js
new file mode 100644
index 0000000000000000000000000000000000000000..2ba1a396dfafac5693c4d3afd2dae086c3c6d008
--- /dev/null
+++ b/glances/outputs/static/js/services/plugins/glances_diskio.js
@@ -0,0 +1,21 @@
+glancesApp.service('GlancesPluginDiskio', function() {
+ var _pluginName = "diskio";
+ this.disks = [];
+
+ this.setData = function(data, views) {
+ data = data[_pluginName];
+ this.disks = [];
+
+ for (var i = 0; i < data.length; i++) {
+ var diskioData = data[i];
+
+ var diskio = {
+ 'name': diskioData['disk_name'],
+ 'readBytes': diskioData['read_bytes'],
+ 'writeBytes': diskioData['write_bytes']
+ };
+
+ this.disks.push(diskio);
+ }
+ };
+});
diff --git a/glances/outputs/static/js/services/plugins/glances_docker.js b/glances/outputs/static/js/services/plugins/glances_docker.js
new file mode 100644
index 0000000000000000000000000000000000000000..0f1f6ef7a604f8a9b0b04f7ebcec2b114981cf0a
--- /dev/null
+++ b/glances/outputs/static/js/services/plugins/glances_docker.js
@@ -0,0 +1,33 @@
+glancesApp.service('GlancesPluginDocker', function(GlancesPlugin) {
+
+ var _pluginName = "docker";
+ this.containers = [];
+ this.version = null;
+
+ this.setData = function(data, views) {
+ data = data[_pluginName];
+ this.containers = [];
+
+ if(_.isEmpty(data)) {
+ return;
+ }
+
+ for (var i = 0; i < data['containers'].length; i++) {
+ var containerData = data['containers'][i];
+
+ var container = {
+ 'id': containerData.Id,
+ 'name': containerData.Names[0],
+ 'status': containerData.Status,
+ 'cpu': containerData.cpu.total,
+ 'memory': containerData.memory.total != undefined ? containerData.memory.total : '?',
+ 'command': containerData.Command,
+ 'image': containerData.Image
+ };
+
+ this.containers.push(container);
+ }
+
+ this.version = data['version']['Version'];
+ };
+});
diff --git a/glances/outputs/static/js/services/plugins/glances_fs.js b/glances/outputs/static/js/services/plugins/glances_fs.js
new file mode 100644
index 0000000000000000000000000000000000000000..60fca8649d89b441884abcfc1bfd829fc59c87a0
--- /dev/null
+++ b/glances/outputs/static/js/services/plugins/glances_fs.js
@@ -0,0 +1,33 @@
+glancesApp.service('GlancesPluginFs', function() {
+ var _pluginName = "fs";
+ var _view = {};
+ this.fileSystems = [];
+
+ this.setData = function(data, views) {
+ _view = views[_pluginName];
+ data = data[_pluginName];
+ this.fileSystems = [];
+
+ for (var i = 0; i < data.length; i++) {
+ var fsData = data[i];
+
+ var fs = {
+ 'name': fsData['device_name'],
+ 'mountPoint': fsData['mnt_point'],
+ 'percent': fsData['percent'],
+ 'size': fsData['size'],
+ 'free': fsData['free']
+ };
+
+ this.fileSystems.push(fs);
+ }
+ };
+
+ this.getDecoration = function(mountPoint, field) {
+ if(_view[mountPoint][field] == undefined) {
+ return;
+ }
+
+ return _view[mountPoint][field].decoration.toLowerCase();
+ };
+});
diff --git a/glances/outputs/static/js/services/plugins/glances_ip.js b/glances/outputs/static/js/services/plugins/glances_ip.js
new file mode 100644
index 0000000000000000000000000000000000000000..f45d08d5c84ea837fe417e3f97040025cee60260
--- /dev/null
+++ b/glances/outputs/static/js/services/plugins/glances_ip.js
@@ -0,0 +1,17 @@
+glancesApp.service('GlancesPluginIp', function() {
+ var _pluginName = "ip";
+
+ this.address = null;
+ this.gateway = null;
+ this.mask = null;
+ this.maskCidr = null;
+
+ this.setData = function(data, views) {
+ data = data[_pluginName];
+
+ this.address = data['address'];
+ this.gateway = data['gateway'];
+ this.mask = data['mask'];
+ this.maskCidr = data['mask_cidr'];
+ };
+});
diff --git a/glances/outputs/static/js/services/plugins/glances_load.js b/glances/outputs/static/js/services/plugins/glances_load.js
new file mode 100644
index 0000000000000000000000000000000000000000..7a9993f1acadbdc5a6e343ada3c2638260fff288
--- /dev/null
+++ b/glances/outputs/static/js/services/plugins/glances_load.js
@@ -0,0 +1,27 @@
+glancesApp.service('GlancesPluginLoad', function() {
+ var _pluginName = "load";
+ var _view = {};
+
+ this.cpucore = null;
+ this.min1 = null;
+ this.min5 = null;
+ this.min15 = null;
+
+ this.setData = function(data, views) {
+ _view = views[_pluginName];
+ data = data[_pluginName];
+
+ this.cpucore = data['cpucore'];
+ this.min1 = data['min1'];
+ this.min5 = data['min5'];
+ this.min15 = data['min15'];
+ };
+
+ this.getDecoration = function(value) {
+ if(_view[value] == undefined) {
+ return;
+ }
+
+ return _view[value].decoration.toLowerCase();
+ };
+});
diff --git a/glances/outputs/static/js/services/plugins/glances_mem.js b/glances/outputs/static/js/services/plugins/glances_mem.js
new file mode 100644
index 0000000000000000000000000000000000000000..93b0d599350a8705b0bce92acaaaca45370cb0a4
--- /dev/null
+++ b/glances/outputs/static/js/services/plugins/glances_mem.js
@@ -0,0 +1,36 @@
+glancesApp.service('GlancesPluginMem', function() {
+ var _pluginName = "mem";
+ var _view = {};
+
+ this.percent = null;
+ this.total = null;
+ this.used = null;
+ this.free = null;
+ this.version = null;
+ this.active = null;
+ this.inactive = null;
+ this.buffers = null;
+ this.cached = null;
+
+ this.setData = function(data, views) {
+ _view = views[_pluginName];
+ data = data[_pluginName];
+
+ this.percent = data['percent'];
+ this.total = data['total'];
+ this.used = data['used'];
+ this.free = data['free'];
+ this.active = data['active'];
+ this.inactive = data['inactive'];
+ this.buffers = data['buffers'];
+ this.cached = data['cached'];
+ };
+
+ this.getDecoration = function(value) {
+ if(_view[value] == undefined) {
+ return;
+ }
+
+ return _view[value].decoration.toLowerCase();
+ };
+});
diff --git a/glances/outputs/static/js/services/plugins/glances_memswap.js b/glances/outputs/static/js/services/plugins/glances_memswap.js
new file mode 100644
index 0000000000000000000000000000000000000000..45896e5fb2fbdb826217a50274c11650ede636dd
--- /dev/null
+++ b/glances/outputs/static/js/services/plugins/glances_memswap.js
@@ -0,0 +1,27 @@
+glancesApp.service('GlancesPluginMemSwap', function() {
+ var _pluginName = "mem";
+ var _view = {};
+
+ this.percent = null;
+ this.total = null;
+ this.used = null;
+ this.free = null;
+
+ this.setData = function(data, views) {
+ _view = views[_pluginName];
+ data = data[_pluginName];
+
+ this.percent = data['percent'];
+ this.total = data['total'];
+ this.used = data['used'];
+ this.free = data['free'];
+ };
+
+ this.getDecoration = function(value) {
+ if(_view[value] == undefined) {
+ return;
+ }
+
+ return _view[value].decoration.toLowerCase();
+ };
+});
diff --git a/glances/outputs/static/js/services/plugins/glances_monitor.js b/glances/outputs/static/js/services/plugins/glances_monitor.js
new file mode 100644
index 0000000000000000000000000000000000000000..131f7bffacabd5b5fe57ef8ce9eb0fd421f8dcdc
--- /dev/null
+++ b/glances/outputs/static/js/services/plugins/glances_monitor.js
@@ -0,0 +1,27 @@
+glancesApp.service('GlancesPluginMonitor', function() {
+ var _pluginName = "monitor";
+ this.processes = [];
+
+ this.setData = function(data, views) {
+ this.processes = data[_pluginName];
+ };
+
+ this.getDesciptionDecoration = function(process) {
+ var count = process.count;
+ var countMin = process.countmin;
+ var countMax = process.countmax;
+ var decoration = "ok";
+
+ if (count > 0) {
+ if ((countMin == null || count >= countMin) && (countMax == null || count <= countMax)) {
+ decoration = 'ok';
+ } else {
+ decoration = 'careful';
+ }
+ } else {
+ decoration = countMin == null ? 'ok' : 'critical';
+ }
+
+ return decoration;
+ }
+});
diff --git a/glances/outputs/static/js/services/plugins/glances_network.js b/glances/outputs/static/js/services/plugins/glances_network.js
new file mode 100644
index 0000000000000000000000000000000000000000..1068bb6eede65ad5ea08242a488820686b76e9ee
--- /dev/null
+++ b/glances/outputs/static/js/services/plugins/glances_network.js
@@ -0,0 +1,20 @@
+glancesApp.service('GlancesPluginNetwork', function() {
+ var _pluginName = "network";
+ this.networks = [];
+
+ this.setData = function(data, views) {
+ this.networks = [];
+
+ for (var i = 0; i < data[_pluginName].length; i++) {
+ var networkData = data[_pluginName][i];
+
+ var network = {
+ 'interfaceName': networkData['interface_name'],
+ 'rx': networkData['rx'],
+ 'tx': networkData['tx']
+ };
+
+ this.networks.push(network);
+ }
+ };
+});
diff --git a/glances/outputs/static/js/services/plugins/glances_percpu.js b/glances/outputs/static/js/services/plugins/glances_percpu.js
new file mode 100644
index 0000000000000000000000000000000000000000..5f1361fdbf522e176dc199e71bd10e3429cb34ef
--- /dev/null
+++ b/glances/outputs/static/js/services/plugins/glances_percpu.js
@@ -0,0 +1,28 @@
+glancesApp.service('GlancesPluginPerCpu', function($filter, GlancesPlugin) {
+ var _pluginName = "percpu";
+ this.cpus = [];
+
+ this.setData = function(data, views) {
+ data = data[_pluginName];
+ this.cpus = [];
+
+ for (var i = 0; i < data.length; i++) {
+ var cpuData = data[i];
+
+ this.cpus.push({
+ 'total': cpuData.total,
+ 'user': cpuData.user,
+ 'system': cpuData.system,
+ 'idle': cpuData.idle
+ });
+ }
+ };
+
+ this.getUserAlert = function(cpu) {
+ return GlancesPlugin.getAlert(_pluginName, 'percpu_user_', cpu.user)
+ };
+
+ this.getSystemAlert = function(cpu) {
+ return GlancesPlugin.getAlert(_pluginName, 'percpu_system_', cpu.system);
+ };
+});
diff --git a/glances/outputs/static/js/services/plugins/glances_plugin.js b/glances/outputs/static/js/services/plugins/glances_plugin.js
new file mode 100644
index 0000000000000000000000000000000000000000..a2fbc91c3a794d494f5a2b2feb65da51a9dd5841
--- /dev/null
+++ b/glances/outputs/static/js/services/plugins/glances_plugin.js
@@ -0,0 +1,42 @@
+glancesApp.service('GlancesPlugin', function () {
+
+ var plugin = {
+ 'limits': {},
+ 'limitSuffix': ['critical', 'careful', 'warning']
+ };
+
+ plugin.setLimits = function(limits){
+ this.limits = limits;
+ };
+
+ plugin.getAlert = function (pluginName, limitNamePrefix, current, maximum, log) {
+ current = current || 0;
+ maximum = maximum || 100;
+ log = log || false;
+
+ var log_str = log ? '_log' : '';
+ var value = (current * 100) / maximum;
+
+ if (this.limits[pluginName] != undefined) {
+ for (var i = 0; i < this.limitSuffix.length; i++) {
+ var limitName = limitNamePrefix + this.limitSuffix[i];
+ var limit = this.limits[pluginName][limitName];
+
+ if (value >= limit) {
+ var pos = limitName.lastIndexOf("_");
+ var className = limitName.substring(pos + 1);
+
+ return className + log_str;
+ }
+ }
+ }
+
+ return "ok" + log_str;
+ };
+
+ plugin.getAlertLog = function (pluginName, limitNamePrefix, current, maximum) {
+ return this.getAlert(pluginName, limitNamePrefix, current, maximum, true);
+ };
+
+ return plugin;
+});
diff --git a/glances/outputs/static/js/services/plugins/glances_processcount.js b/glances/outputs/static/js/services/plugins/glances_processcount.js
new file mode 100644
index 0000000000000000000000000000000000000000..3f5bb78c75d6bf4a6c57123ca418a1bbe3fbbc4c
--- /dev/null
+++ b/glances/outputs/static/js/services/plugins/glances_processcount.js
@@ -0,0 +1,19 @@
+glancesApp.service('GlancesPluginProcessCount', function() {
+ var _pluginName = "processcount";
+
+ this.total = null;
+ this.running = null;
+ this.sleeping = null;
+ this.stopped = null;
+ this.thread = null;
+
+ this.setData = function(data, views) {
+ data = data[_pluginName];
+
+ this.total = data['total'];
+ this.running = data['running'];
+ this.sleeping = data['sleeping'];
+ this.stopped = data['stopped'];
+ this.thread = data['thread'];
+ };
+});
diff --git a/glances/outputs/static/js/services/plugins/glances_processlist.js b/glances/outputs/static/js/services/plugins/glances_processlist.js
new file mode 100644
index 0000000000000000000000000000000000000000..7a51081209326168f883df73559033102af38ac2
--- /dev/null
+++ b/glances/outputs/static/js/services/plugins/glances_processlist.js
@@ -0,0 +1,46 @@
+glancesApp.service('GlancesPluginProcessList', function($filter, GlancesPlugin) {
+ var _pluginName = "processlist";
+ this.processes = [];
+
+ this.setData = function(data, views) {
+ this.processes = [];
+
+ for (var i = 0; i < data[_pluginName].length; i++) {
+ var process = data[_pluginName][i];
+
+ process.memvirt = process.memory_info[1];
+ process.memres = process.memory_info[0];
+ process.timeplus = $filter('timedelta')(process.cpu_times);
+ process.timemillis = $filter('timemillis')(process.cpu_times);
+
+ process.ioRead = '?';
+ process.ioWrite = '?';
+
+ if (process.io_counters) {
+ process.ioRead = (process.io_counters[0] - process.io_counters[2]) / process.time_since_update;
+
+ if (process.ioRead != 0) {
+ process.ioRead = $filter('bytes')(process.ioRead);
+ }
+
+ process.ioWrite = (process.io_counters[1] - process.io_counters[3]) / process.time_since_update;
+
+ if (process.ioWrite != 0) {
+ process.ioWrite = $filter('bytes')(process.ioWrite);
+ }
+ }
+
+ process.isNice = process.nice !== undefined && ((data['system'].os_name === 'Windows' && nice != 32) || (!data['system'].os_name === 'Windows' && process.nice != 0));
+
+ this.processes.push(process);
+ }
+ };
+
+ this.getCpuPercentAlert = function(process) {
+ return GlancesPlugin.getAlert(_pluginName, 'processlist_cpu_', process.cpu_percent);
+ };
+
+ this.getMemoryPercentAlert = function(process) {
+ return GlancesPlugin.getAlert(_pluginName, 'processlist_mem_', process.cpu_percent);
+ };
+});
diff --git a/glances/outputs/static/js/services/plugins/glances_sensors.js b/glances/outputs/static/js/services/plugins/glances_sensors.js
new file mode 100644
index 0000000000000000000000000000000000000000..bd05eddb960c21ca8b6eed758e7aad6fdd61d626
--- /dev/null
+++ b/glances/outputs/static/js/services/plugins/glances_sensors.js
@@ -0,0 +1,19 @@
+glancesApp.service('GlancesPluginSensors', function(GlancesPlugin) {
+
+ var _pluginName = "sensors";
+ this.sensors = [];
+
+ this.setData = function(data, views) {
+ _.remove(data[_pluginName], function(sensor) {
+ return sensor.type == "battery" && _.isArray(sensor.value) && _.isEmpty(sensor.value);
+ });
+
+ this.sensors = data[_pluginName];
+ };
+
+ this.getAlert = function(sensor) {
+ var current = sensor.type == 'battery' ? 100 - sensor.value : sensor.value;
+
+ return GlancesPlugin.getAlert(_pluginName, 'sensors_' + sensor.type + '_', current);
+ };
+});
diff --git a/glances/outputs/static/js/services/plugins/glances_system.js b/glances/outputs/static/js/services/plugins/glances_system.js
new file mode 100644
index 0000000000000000000000000000000000000000..ecf4f0f8224c6e53e03c55a2a101700295376e6d
--- /dev/null
+++ b/glances/outputs/static/js/services/plugins/glances_system.js
@@ -0,0 +1,37 @@
+glancesApp.service('GlancesPluginSystem', function() {
+ var _pluginName = "system";
+
+ this.hostname = null;
+ this.platform = null;
+ this.humanReadableName = null;
+ this.os = {
+ 'name': null,
+ 'version': null
+ };
+
+ this.setData = function(data, views) {
+ data = data[_pluginName];
+
+ this.hostname = data['hostname'];
+ this.platform = data['platform'];
+ this.os.name = data['os_name'];
+ this.os.version = data['os_version'];
+ this.humanReadableName = data['hr_name'];
+ };
+
+ this.isBsd = function() {
+ return this.os.name === 'FreeBSD';
+ };
+
+ this.isLinux = function() {
+ return this.os.name === 'Linux';
+ };
+
+ this.isMac = function() {
+ return this.os.name === 'Darwin';
+ };
+
+ this.isWindows = function() {
+ return this.os.name === 'Windows';
+ };
+});
diff --git a/glances/outputs/static/js/services/plugins/glances_uptime.js b/glances/outputs/static/js/services/plugins/glances_uptime.js
new file mode 100644
index 0000000000000000000000000000000000000000..4a008bdedb1ed2b0b07e5d157d1783891b44783a
--- /dev/null
+++ b/glances/outputs/static/js/services/plugins/glances_uptime.js
@@ -0,0 +1,7 @@
+glancesApp.service('GlancesPluginUptime', function() {
+ this.uptime = null;
+
+ this.setData = function(data, views) {
+ this.uptime = data['uptime'];
+ };
+});
diff --git a/glances/outputs/static/js/stats_controller.js b/glances/outputs/static/js/stats_controller.js
index 7690377b6a6df26fe7364c49d11fa3a08a442169..b0a57b781d4ef17426d98b31acff1c4e444324b1 100644
--- a/glances/outputs/static/js/stats_controller.js
+++ b/glances/outputs/static/js/stats_controller.js
@@ -1,15 +1,12 @@
-glancesApp.controller('statsController', function($scope, $http, $interval, $q, $routeParams, $filter) {
-
- $scope.limitSuffix = ['critical', 'careful', 'warning'];
+glancesApp.controller('statsController', function ($scope, $interval, $routeParams, GlancesStats) {
$scope.refreshTime = 3;
- $scope.pluginLimits = [];
$scope.sorter = {
column: "cpu_percent",
auto: true,
- isReverseColumn: function(column) {
+ isReverseColumn: function (column) {
return !(column == 'username' || column == 'name');
},
- getColumnLabel: function(column) {
+ getColumnLabel: function (column) {
if (_.isEqual(column, ['io_read', 'io_write'])) {
return 'io_counters';
} else {
@@ -19,225 +16,112 @@ glancesApp.controller('statsController', function($scope, $http, $interval, $q,
};
$scope.help_screen = false;
$scope.show = {
- 'diskio' : true,
- 'network' : true,
- 'fs' : true,
- 'sensors' : true,
- 'sidebar' : true,
- 'alert' : true,
+ 'diskio': true,
+ 'network': true,
+ 'fs': true,
+ 'sensors': true,
+ 'sidebar': true,
+ 'alert': true,
'short_process_name': true,
'per_cpu': false,
- 'warning_alerts':true,
- 'warning_critical_alerts':true,
- 'process_stats':true,
- 'top_extended_stats':true,
- 'docker_stats':true,
- 'network_io_combination':false,
- 'network_io_cumulative':false,
- 'filesystem_freespace':false,
- 'network_by_bytes':true
+ 'warning_alerts': true,
+ 'warning_critical_alerts': true,
+ 'process_stats': true,
+ 'top_extended_stats': true,
+ 'docker_stats': true,
+ 'network_io_combination': false,
+ 'network_io_cumulative': false,
+ 'filesystem_freespace': false,
+ 'network_by_bytes': true
};
- $scope.init_refresh_time = function() {
+ $scope.init_refresh_time = function () {
if ($routeParams != undefined && $routeParams.refresh_time != undefined) {
- var new_refresh_time = parseInt($routeParams.refresh_time)
+ var new_refresh_time = parseInt($routeParams.refresh_time);
if (new_refresh_time >= 1) {
$scope.refreshTime = new_refresh_time
}
}
- }
-
- $scope.init_limits = function() {
- $http.get('/api/2/all/limits').success(function(response, status, headers, config) {
- $scope.pluginLimits = response
- }).error(function(response, status, headers, config) {
- console.log('error : ' + response+ status + headers + config);
- });
- }
-
- $scope.init_help = function() {
- $http.get('/api/2/help').success(function(response, status, headers, config) {
- $scope.help = response
- });
- }
+ };
- $scope.show_hide = function(bloc) {
- if(bloc == 'help') {
+ $scope.show_hide = function (bloc) {
+ if (bloc == 'help') {
$scope.help_screen = !$scope.help_screen
} else {
$scope.show[bloc] = !$scope.show[bloc]
}
- }
-
- var canceler = undefined;
-
- /**
- * Refresh all the data of the view
- */
- $scope.refreshData = function() {
- canceler = $q.defer();
- $http.get('/api/2/all', {timeout: canceler.promise}).success(function(response, status, headers, config) {
-
- function timemillis(array) {
- var sum = 0.0
- for (var i = 0; i < array.length; i++) {
- sum += array[i] * 1000.0;
- }
- return sum;
- }
- function timedelta(input) {
- var sum = timemillis(input);
- var d = new Date(sum);
-
- return {
- hours: d.getUTCHours(), // TODO : multiple days ( * (d.getDay() * 24)))
- minutes: d.getUTCMinutes(),
- seconds: d.getUTCSeconds(),
- milliseconds: parseInt("" + d.getUTCMilliseconds() / 10)
- };
- };
-
- function durationBetweenTwoDates(startDate, endDate) {
- var duration = endDate - startDate;
- var seconds = parseInt((duration/1000)%60)
- , minutes = parseInt((duration/(1000*60))%60)
- , hours = parseInt((duration/(1000*60*60))%24);
-
- return _.padLeft(hours,2,'0') + ":" + _.padLeft(minutes,2,'0') + ":" + _.padLeft(seconds,2,'0');
- }
-
- for (var i = 0; i < response['processlist'].length; i++) {
- var process = response['processlist'][i]
- process.memvirt = process.memory_info[1]
- process.memres = process.memory_info[0]
- process.timeplus = timedelta(process.cpu_times)
- process.timemillis = timemillis(process.cpu_times)
-
- process.io_read = '?';
- process.io_write = '?';
-
- if (process.io_counters) {
- process.io_read = (process.io_counters[0] - process.io_counters[2]) / process.time_since_update;
-
- if (process.io_read != 0) {
- process.io_read = $filter('bytes')(process.io_read);
- }
-
- process.io_write = (process.io_counters[1] - process.io_counters[3]) / process.time_since_update;
-
- if (process.io_write != 0) {
- process.io_write = $filter('bytes')(process.io_write);
- }
- }
- }
- for (var i = 0; i < response['alert'].length; i++) {
- var alert = response['alert'][i];
- alert.begin = alert[0] * 1000;
- alert.end = alert[1] * 1000;
- alert.ongoing = alert[1] == -1;
-
- if (!alert.ongoing) {
- alert.duration = durationBetweenTwoDates(alert.begin, alert.end);
- }
- }
-
- _.remove(response['sensors'], function(sensor) {
- return sensor.type == "battery" && _.isArray(sensor.value) && _.isEmpty(sensor.value);
- });
+ };
- $scope.is_bsd = response['system'].os_name === 'FreeBSD';
- $scope.is_linux = response['system'].os_name === 'Linux';
- $scope.is_mac = response['system'].os_name === 'Darwin';
- $scope.is_windows = response['system'].os_name === 'Windows';
+ $scope.dataLoaded = false;
+ $scope.refreshData = function () {
+ GlancesStats.getData().then(function (data) {
+
+ $scope.statsAlert = GlancesStats.getPlugin('alert');
+ $scope.statsCpu = GlancesStats.getPlugin('cpu');
+ $scope.statsDiskio = GlancesStats.getPlugin('diskio');
+ $scope.statsDocker = GlancesStats.getPlugin('docker');
+ $scope.statsFs = GlancesStats.getPlugin('fs');
+ $scope.statsIp = GlancesStats.getPlugin('ip');
+ $scope.statsLoad = GlancesStats.getPlugin('load');
+ $scope.statsMem = GlancesStats.getPlugin('mem');
+ $scope.statsMemSwap = GlancesStats.getPlugin('memswap');
+ $scope.statsMonitor = GlancesStats.getPlugin('monitor');
+ $scope.statsNetwork = GlancesStats.getPlugin('network');
+ $scope.statsPerCpu = GlancesStats.getPlugin('percpu');
+ $scope.statsProcessCount = GlancesStats.getPlugin('processcount');
+ $scope.statsProcessList = GlancesStats.getPlugin('processlist');
+ $scope.statsSensors = GlancesStats.getPlugin('sensors');
+ $scope.statsSystem = GlancesStats.getPlugin('system');
+ $scope.statsUptime = GlancesStats.getPlugin('uptime');
$scope.is_disconnected = false;
-
- $scope.result = response;
- canceler.resolve()
- }).error(function(d, status, headers, config) {
+ $scope.dataLoaded = true;
+ }, function() {
$scope.is_disconnected = true;
-
- canceler.resolve()
});
- }
-
- $scope.isNice = function(nice) {
- if(nice !== undefined && (($scope.is_windows && nice != 32) || (!$scope.is_windows && nice != 0))) {
- return true;
- }
-
- return false;
- }
-
- $scope.getAlert = function(pluginName, limitNamePrefix, current, maximum, log) {
- current = current || 0;
- maximum = maximum || 100;
- log = log || false;
- log_str = log ? '_log' : '';
-
- var value = (current * 100) / maximum;
-
- if ($scope.pluginLimits != undefined && $scope.pluginLimits[pluginName] != undefined) {
- for (var i = 0; i < $scope.limitSuffix.length; i++) {
- var limitName = limitNamePrefix + $scope.limitSuffix[i]
- var limit = $scope.pluginLimits[pluginName][limitName]
-
- if (value >= limit) {
- var pos = limitName.lastIndexOf("_")
- var className = limitName.substring(pos + 1)
-
- return className + log_str;
- }
- }
- }
-
- return "ok" + log_str;
- }
-
- $scope.getAlertLog = function(pluginName, limitNamePrefix, current, maximum) {
- return $scope.getAlert(pluginName, limitNamePrefix, current, maximum, true);
- }
+ };
$scope.init_refresh_time();
- $scope.init_limits();
- $scope.init_help();
+ GlancesStats.getHelp().then(function (help) {
+ $scope.help = help;
+ });
var stop;
$scope.configure_refresh = function () {
if (!angular.isDefined(stop)) {
- //$scope.refreshData();
- stop = $interval(function() {
+ stop = $interval(function () {
$scope.refreshData();
}, $scope.refreshTime * 1000); // in milliseconds
}
- }
+ };
$scope.$watch(
- function() { return $scope.refreshTime; },
- function(newValue, oldValue) {
- $scope.stop_refresh();
- $scope.configure_refresh();
- }
+ function () {
+ return $scope.refreshTime;
+ },
+ function (newValue, oldValue) {
+ $scope.stop_refresh();
+ $scope.configure_refresh();
+ }
);
- $scope.stop_refresh = function() {
+ $scope.stop_refresh = function () {
if (angular.isDefined(stop)) {
$interval.cancel(stop);
stop = undefined;
}
};
- $scope.$on('$destroy', function() {
- // Make sure that the interval is destroyed too
+ $scope.$on('$destroy', function () {
$scope.stop_refresh();
});
- $scope.onKeyDown = function($event) {
+ $scope.onKeyDown = function ($event) {
if ($event.keyCode == keycodes.a) { // a Sort processes automatically
$scope.sorter.column = "cpu_percent";
$scope.sorter.auto = true;
} else if ($event.keyCode == keycodes.c) {//c Sort processes by CPU%
- $scope.sorter.column = "cpu_percent";
+ $scope.sorter.column = "cpu_percent";
$scope.sorter.auto = false;
} else if ($event.keyCode == keycodes.m) {//m Sort processes by MEM%
$scope.sorter.column = "memory_percent";
@@ -297,5 +181,5 @@ glancesApp.controller('statsController', function($scope, $http, $interval, $q,
} else if ($event.keyCode == keycodes.q) {//q Quit (Esc and Ctrl-C also work)
// not available
}
- }
+ };
});