diff --git a/MANIFEST.in b/MANIFEST.in index 37000d2a2c755e9f930205d964d702ffcb3e264e..1a6076a17772f6c87279c0ac54692d5bc200e74c 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -4,12 +4,13 @@ include NEWS include README.rst include conf/glances.conf include glances/outputs/static/html/*.html -include glances/outputs/static/html/components/*.html include glances/outputs/static/html/plugins/*.html include glances/outputs/static/*.ico include glances/outputs/static/css/*.css include glances/outputs/static/js/*.js include glances/outputs/static/js/*.js.map +include glances/outputs/static/js/services/core/*.js +include glances/outputs/static/js/services/plugins/*.js include glances/outputs/static/js/vendors/*.js include glances/outputs/static/js/vendors/*.js.map include glances/outputs/static/images/*.png diff --git a/glances/outputs/static/html/components/monitor_process.html b/glances/outputs/static/html/components/monitor_process.html deleted file mode 100644 index ec88304090cdd553bde2da2c27328688c4cb0b88..0000000000000000000000000000000000000000 --- a/glances/outputs/static/html/components/monitor_process.html +++ /dev/null @@ -1,4 +0,0 @@ -
{{ process.description }}
-
{{ process.count > 1 ? process.count : '' }}
-
{{ process.count > 0 ? 'RUNNING' : 'NOT RUNNING' }}
-
{{ process.result }}
diff --git a/glances/outputs/static/html/index.html b/glances/outputs/static/html/index.html index f9b20a704f3a286e99045ba2cdb6c66390a3e21c..03ffc66bc0458e680e07aa34e6ef0750e1a1e611 100644 --- a/glances/outputs/static/html/index.html +++ b/glances/outputs/static/html/index.html @@ -18,6 +18,25 @@ + + + + + + + + + + + + + + + + + + + diff --git a/glances/outputs/static/html/plugins/alert.html b/glances/outputs/static/html/plugins/alert.html index ea13e876c84c3a0dc35940ff58f64f93a1ff7def..061892a4c0cb1dd2ef3017482dbc079ac2cb3073 100644 --- a/glances/outputs/static/html/plugins/alert.html +++ b/glances/outputs/static/html/plugins/alert.html @@ -1,7 +1,7 @@
-
+
-{{alert.begin | date : 'yyyy-MM-dd H:mm:ss'}} ({{ alert.ongoing ? 'ongoing' : alert.duration }}) - {{alert[2]}} on {{alert[3]}} ({{alert[4]}}) +{{alert.begin | date : 'yyyy-MM-dd H:mm:ss'}} ({{ alert.ongoing ? 'ongoing' : alert.duration }}) - {{alert.level}} on {{alert.name}} ({{alert.max}})
diff --git a/glances/outputs/static/html/plugins/alerts.html b/glances/outputs/static/html/plugins/alerts.html index a03db0fc149a4253a906b981c5fffbb5458bfccc..1c0a1b429dafa0973535e65d88b880f599e67193 100644 --- a/glances/outputs/static/html/plugins/alerts.html +++ b/glances/outputs/static/html/plugins/alerts.html @@ -1,2 +1,2 @@ -No warning or critical alert detected -Warning or critical alerts (lasts {{result['alert'].length}} entries) +No warning or critical alert detected +Warning or critical alerts (lasts {{statsAlert.count()}} entries) diff --git a/glances/outputs/static/html/plugins/cpu.html b/glances/outputs/static/html/plugins/cpu.html index e574c8efc60071ac2ef2743923b52bb13d3ae9a9..332317bada8870143afa10f519784bc185744fe8 100644 --- a/glances/outputs/static/html/plugins/cpu.html +++ b/glances/outputs/static/html/plugins/cpu.html @@ -1,22 +1,22 @@
CPU
-
{{result["cpu"].total}}%
+
{{ statsCpu.total }}%
user:
-
- {{result["cpu"].user}}% +
+ {{ statsCpu.user }}%
system:
-
- {{result["cpu"].system}}% +
+ {{ statsCpu.system }}%
idle:
-
{{result["cpu"].idle}}%
+
{{ statsCpu.idle }}%
diff --git a/glances/outputs/static/html/plugins/cpu_more.html b/glances/outputs/static/html/plugins/cpu_more.html index 2c16332afba882da4873ebedaec3014c2174a22e..c4f7e6cff2f9cd058c98ee7dada3821ee253de84 100644 --- a/glances/outputs/static/html/plugins/cpu_more.html +++ b/glances/outputs/static/html/plugins/cpu_more.html @@ -2,25 +2,25 @@
nice:
- {{result["cpu"].nice}}% + {{ statsCpu.nice }}%
-
+
irq:
- {{result["cpu"].irq}}% + {{ statsCpu.irq }}%
-
+
iowait:
-
- {{result["cpu"].iowait}}% +
+ {{ statsCpu.iowait }}%
-
+
steal:
-
- {{result["cpu"].steal}}% +
+ {{ statsCpu.steal }}%
diff --git a/glances/outputs/static/html/plugins/diskio.html b/glances/outputs/static/html/plugins/diskio.html index 35426170493d50b9275c29d09e606d0dad0b93f5..2cd9de342a8224e5ad51e25c7bc583119980df2b 100644 --- a/glances/outputs/static/html/plugins/diskio.html +++ b/glances/outputs/static/html/plugins/diskio.html @@ -3,8 +3,8 @@
R/s
W/s
-
-
{{disk.disk_name | min_size}}
-
{{disk.read_bytes | bytes}}
-
{{disk.write_bytes | bytes}}
+
+
{{disk.name | min_size}}
+
{{disk.readBytes | bytes}}
+
{{disk.writeBytes | bytes}}
diff --git a/glances/outputs/static/html/plugins/docker.html b/glances/outputs/static/html/plugins/docker.html index d30fa2d0b901205b33680efda14e4bf2caea1cdf..23f38aeeb3a557b2f3e2b41245720c6d1ea27ff1 100644 --- a/glances/outputs/static/html/plugins/docker.html +++ b/glances/outputs/static/html/plugins/docker.html @@ -1,4 +1,4 @@ -CONTAINERS {{ result['docker']['containers'].length }} (served by Docker {{ result['docker']['version']['Version'] }}) +CONTAINERS {{ statsDocker.containers.length }} (served by Docker {{ statsDocker.version }})
@@ -9,12 +9,12 @@
MEM
Command
-
-
{{ container.Id | limitTo:12 }}
-
{{ container.Names[0] }}
-
{{ container.Status }}
-
{{ container.cpu.total | number:1 }}
-
{{ container.memory.usage | bytes }}
-
{{ container.Command }}
+
+
{{ container.id | limitTo:12 }}
+
{{ container.name }}
+
{{ container.status }}
+
{{ container.cpu | number:1 }}
+
{{ container.memory | bytes }}
+
{{ container.command }}
diff --git a/glances/outputs/static/html/plugins/fs.html b/glances/outputs/static/html/plugins/fs.html index cd26163cc7e27ffbeba6c5fd7d2124ca545edb66..5fdea584912b0a70016aee3159cce4ada98056db 100644 --- a/glances/outputs/static/html/plugins/fs.html +++ b/glances/outputs/static/html/plugins/fs.html @@ -3,10 +3,10 @@
Used
Total
-
-
{{fs.mnt_point}} ({{fs.device_name}})
-
- {{fs.size - fs.free | bytes}} +
+
{{ fs.mountPoint }} ({{ fs.name }})
+
+ {{ fs.size - fs.free | bytes }}
-
{{fs.size | bytes}}
+
{{ fs.size | bytes }}
diff --git a/glances/outputs/static/html/plugins/ip.html b/glances/outputs/static/html/plugins/ip.html index 161244d17c3a90a2d6a641110320233ff6832fb5..45566436290c42dcc56f96c39a5465eaa203d46e 100644 --- a/glances/outputs/static/html/plugins/ip.html +++ b/glances/outputs/static/html/plugins/ip.html @@ -1 +1 @@ - - IP {{result["ip"].address}}/{{result["ip"].mask_cidr}} + - IP {{ statsIp.address }}/{{ statsIp.maskCidr }} diff --git a/glances/outputs/static/html/plugins/load.html b/glances/outputs/static/html/plugins/load.html index 32677109e5e1214c565f1aed456e63e9d3f66e4a..1d90b6e36f65da88897b78fd1c7b58b8a5379bd3 100644 --- a/glances/outputs/static/html/plugins/load.html +++ b/glances/outputs/static/html/plugins/load.html @@ -1,24 +1,24 @@
LOAD
-
{{result["load"].cpucore}}-core
+
{{ statsLoad.cpucore }}-core
1 min:
- {{result["load"].min1 | number : 2}} + {{ statsLoad.min1 | number : 2}}
5 min:
-
- {{result["load"].min5 | number : 2}} +
+ {{ statsLoad.min5 | number : 2}}
15 min:
-
- {{result["load"].min15 | number : 2}} +
+ {{ statsLoad.min15 | number : 2}}
diff --git a/glances/outputs/static/html/plugins/mem.html b/glances/outputs/static/html/plugins/mem.html index c02ff4029020167096ffc0905a86363aafe60a2a..9f6f869dc2e5bba75a18eba7055217d71e463a33 100644 --- a/glances/outputs/static/html/plugins/mem.html +++ b/glances/outputs/static/html/plugins/mem.html @@ -1,20 +1,20 @@
MEM
-
{{result["mem"].percent}}%
+
{{ statsMem.percent }}%
total:
-
{{result["mem"].total | bytes}}
+
{{ statsMem.total | bytes }}
used:
-
- {{result["mem"].used | bytes:2}} +
+ {{ statsMem.used | bytes:2 }}
free:
-
{{result["mem"].free | bytes}}
+
{{ statsMem.free | bytes }}
diff --git a/glances/outputs/static/html/plugins/mem_more.html b/glances/outputs/static/html/plugins/mem_more.html index 913a17d5d144064da9ac1daf8e18594ce0322aa8..080060ae1feec6aec0ac268089daedb6f15459aa 100644 --- a/glances/outputs/static/html/plugins/mem_more.html +++ b/glances/outputs/static/html/plugins/mem_more.html @@ -1,18 +1,18 @@
active:
-
{{result["mem"].active | bytes}}
+
{{ statsMem.active | bytes }}
inactive:
-
{{result["mem"].inactive | bytes}}
+
{{ statsMem.inactive | bytes }}
-
+
buffers:
-
{{result["mem"].buffers | bytes}}
+
{{ statsMem.buffers | bytes }}
-
+
cached:
-
{{result["mem"].cached | bytes}}
+
{{ statsMem.cached | bytes }}
diff --git a/glances/outputs/static/html/plugins/memswap.html b/glances/outputs/static/html/plugins/memswap.html index af9c4025544fe6d23297df30b4790b4f99b82cea..3d566a518d280064508d559fef3551a1d9c75967 100644 --- a/glances/outputs/static/html/plugins/memswap.html +++ b/glances/outputs/static/html/plugins/memswap.html @@ -1,20 +1,20 @@
SWAP
-
{{result["memswap"].percent}}%
+
{{ statsMemSwap.percent }}%
total:
-
{{result["memswap"].total | bytes}}
+
{{ statsMemSwap.total | bytes }}
used:
-
- {{result["memswap"].used | bytes}} +
+ {{ statsMemSwap.used | bytes }}
free:
-
{{result["memswap"].free | bytes}}
+
{{ statsMemSwap.free | bytes }}
diff --git a/glances/outputs/static/html/plugins/monitor.html b/glances/outputs/static/html/plugins/monitor.html index 01ded84262476887ec5316685b57189997cf2a90..5ce2a43bacc6d94d3355ac720a76df5e1fc52185 100644 --- a/glances/outputs/static/html/plugins/monitor.html +++ b/glances/outputs/static/html/plugins/monitor.html @@ -1,3 +1,8 @@
- +
+
{{ process.description }}
+
{{ process.count > 1 ? process.count : '' }}
+
{{ process.count > 0 ? 'RUNNING' : 'NOT RUNNING' }}
+
{{ process.result }}
+
diff --git a/glances/outputs/static/html/plugins/network.html b/glances/outputs/static/html/plugins/network.html index 1f1a4016240ba899d868ad4742020571012021d1..409ec86b9b2439ff63dde8d0db22a45702887bd2 100644 --- a/glances/outputs/static/html/plugins/network.html +++ b/glances/outputs/static/html/plugins/network.html @@ -3,10 +3,10 @@
Rx/s
Tx/s
-
-
{{network.interface_name | min_size}}
-
{{network.rx | bytes}}
-
{{network.tx | bytes}}
-
{{network.rx | bits}}
-
{{network.tx | bits}}
+
+
{{ network.interfaceName | min_size }}
+
{{ network.rx | bytes }}
+
{{ network.tx | bytes }}
+
{{ network.rx | bits }}
+
{{ network.tx | bits }}
diff --git a/glances/outputs/static/html/plugins/per_cpu.html b/glances/outputs/static/html/plugins/per_cpu.html index 68b0ae449615dbad890c680444ea03c9a4707c84..bc918c19d28f4789983f91035da88faaec619142 100644 --- a/glances/outputs/static/html/plugins/per_cpu.html +++ b/glances/outputs/static/html/plugins/per_cpu.html @@ -1,22 +1,22 @@
PER CPU
-
{{percpu.total}}%
+
{{ percpu.total }}%
user:
-
- {{percpu.user}}% +
+ {{ percpu.user }}%
system:
-
- {{percpu.system}}% +
+ {{ percpu.system }}%
idle:
-
{{percpu.idle}}%
+
{{ percpu.idle }}%
diff --git a/glances/outputs/static/html/plugins/processcount.html b/glances/outputs/static/html/plugins/processcount.html index a787edd3dbd8d0ffc373130b5cfdbb5e01bda75a..82e29ae6433b60029f8e4f237ac150885f2a9f1b 100644 --- a/glances/outputs/static/html/plugins/processcount.html +++ b/glances/outputs/static/html/plugins/processcount.html @@ -1,6 +1,6 @@ TASKS -{{result["processcount"].total}} ({{result["processcount"].thread}} thr), -{{result["processcount"].running}} run, -{{result["processcount"].sleeping}} slp, -{{result["processcount"].stopped}} oth +{{ statsProcessCount.total }} ({{ statsProcessCount.thread }} thr), +{{ statsProcessCount.running }} run, +{{ statsProcessCount.sleeping }} slp, +{{ statsProcessCount.stopped }} oth sorted {{ sorter.auto ? 'automatically' : '' }} by {{ sorter.getColumnLabel(sorter.column) }}, flat view diff --git a/glances/outputs/static/html/plugins/processlist.html b/glances/outputs/static/html/plugins/processlist.html index d738721b25f1671d29887852beb38254c90e8470..3f594fe6c828ce344a3c7c899130ec47ac2ca159 100644 --- a/glances/outputs/static/html/plugins/processlist.html +++ b/glances/outputs/static/html/plugins/processlist.html @@ -13,21 +13,21 @@
Command
-
-
{{process.cpu_percent | number:1}}
-
{{process.memory_percent | number:1}}
+
+
{{process.cpu_percent | number:1}}
+
{{process.memory_percent | number:1}}
{{process.pid}}
{{process.username}}
-
{{process.nice | exclamation}}
+
{{process.nice | exclamation}}
{{process.status}}
- - -
{{process.name}}
-
{{process.cmdline}}
+ + +
{{process.name}}
+
{{process.cmdline}}
diff --git a/glances/outputs/static/html/plugins/sensors.html b/glances/outputs/static/html/plugins/sensors.html index 0ee09581725fe26480b88e6f8a9ae6cd0fa46731..5288f8798689e7832b60341f532e5e378bfd711e 100644 --- a/glances/outputs/static/html/plugins/sensors.html +++ b/glances/outputs/static/html/plugins/sensors.html @@ -1,13 +1,9 @@
SENSORS
-
+ +
{{ sensor.label }}
{{ sensor.unit }}
-
- {{ sensor.value }} -
-
- {{ sensor.value }} -
+
{{ sensor.value }}
diff --git a/glances/outputs/static/html/plugins/system.html b/glances/outputs/static/html/plugins/system.html index 257393f00cd0273fab9128b890932197d87615ae..5e700b914969239f439032ca5bc3bd9af1b73bde 100644 --- a/glances/outputs/static/html/plugins/system.html +++ b/glances/outputs/static/html/plugins/system.html @@ -1,4 +1,4 @@ Disconnected from -{{ result["system"].hostname }} - - +{{ statsSystem.hostname }} + + \ No newline at end of file diff --git a/glances/outputs/static/html/plugins/uptime.html b/glances/outputs/static/html/plugins/uptime.html index 10222fb4ca01e9f581c34cc7c01394c9892cd9a5..1fc9238cf336ae2ca1c4054bb6ada5d15ed76a0f 100644 --- a/glances/outputs/static/html/plugins/uptime.html +++ b/glances/outputs/static/html/plugins/uptime.html @@ -1 +1 @@ -Uptime: {{result["uptime"]}} +Uptime: {{ statsUptime.uptime }} diff --git a/glances/outputs/static/html/stats.html b/glances/outputs/static/html/stats.html index a1ff63009a80f15b5bab5529cdad4acba893886e..ce83aafa6fd9a0d504dac4868254bf8ded141ddb 100644 --- a/glances/outputs/static/html/stats.html +++ b/glances/outputs/static/html/stats.html @@ -1,18 +1,18 @@ -
+
Loading...
-
+
-
+
@@ -24,13 +24,13 @@
-
+
@@ -48,17 +48,17 @@
-
+
-
+
- +
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 } - } + }; });