From a13b64d3e8b5fe5bcff7b0bdbe239a9e78d2da7d Mon Sep 17 00:00:00 2001 From: Floran Brutel Date: Sun, 4 Jun 2017 12:39:02 +0200 Subject: [PATCH] Use event system to alert on disconnection --- .../js/components/glances/controller.js | 3 +- .../js/components/plugin-system/controller.js | 5 + glances/outputs/static/public/js/main.min.js | 284 +++++++++--------- .../outputs/static/public/js/templates.min.js | 10 +- 4 files changed, 155 insertions(+), 147 deletions(-) diff --git a/glances/outputs/static/js/components/glances/controller.js b/glances/outputs/static/js/components/glances/controller.js index f8006093..02405ea1 100644 --- a/glances/outputs/static/js/components/glances/controller.js +++ b/glances/outputs/static/js/components/glances/controller.js @@ -10,7 +10,6 @@ function GlancesController($scope, $timeout, GlancesStats, REFRESH_TIME, Hotkeys data.isLinux = data.stats['system']['os_name'] === 'Linux'; data.isMac = data.stats['system']['os_name'] === 'Darwin'; data.isWindows = data.stats['system']['os_name'] === 'Windows'; - vm.is_disconnected = false; $scope.$broadcast('data_refreshed', data); vm.dataLoaded = true; @@ -19,7 +18,7 @@ function GlancesController($scope, $timeout, GlancesStats, REFRESH_TIME, Hotkeys }; var refreshDataError = function() { - vm.is_disconnected = true; + $scope.$broadcast('is_disconnected'); nextLoad(); }; diff --git a/glances/outputs/static/js/components/plugin-system/controller.js b/glances/outputs/static/js/components/plugin-system/controller.js index 10148c6a..f8e52b35 100644 --- a/glances/outputs/static/js/components/plugin-system/controller.js +++ b/glances/outputs/static/js/components/plugin-system/controller.js @@ -19,5 +19,10 @@ function GlancesPluginSystemController($scope) { vm.os.name = stats['os_name']; vm.os.version = stats['os_version']; vm.humanReadableName = stats['hr_name']; + vm.isDisconnected = false; + }); + + $scope.$on('is_disconnected', function() { + vm.isDisconnected = true; }); } diff --git a/glances/outputs/static/public/js/main.min.js b/glances/outputs/static/public/js/main.min.js index 4a895401..e749be28 100644 --- a/glances/outputs/static/public/js/main.min.js +++ b/glances/outputs/static/public/js/main.min.js @@ -325,7 +325,6 @@ function GlancesController($scope, $timeout, GlancesStats, REFRESH_TIME, Hotkeys data.isLinux = data.stats['system']['os_name'] === 'Linux'; data.isMac = data.stats['system']['os_name'] === 'Darwin'; data.isWindows = data.stats['system']['os_name'] === 'Windows'; - vm.is_disconnected = false; $scope.$broadcast('data_refreshed', data); vm.dataLoaded = true; @@ -334,7 +333,7 @@ function GlancesController($scope, $timeout, GlancesStats, REFRESH_TIME, Hotkeys }; var refreshDataError = function() { - vm.is_disconnected = true; + $scope.$broadcast('is_disconnected'); nextLoad(); }; @@ -459,6 +458,32 @@ function GlancesPluginAlertController($scope, favicoService) { 'use strict'; +glancesApp.component('glancesPluginCloud', { + controller: GlancesPluginCloudController, + controllerAs: 'vm', + templateUrl: 'components/plugin-cloud/view.html' +}); + +'use strict'; + +function GlancesPluginCloudController($scope) { + var vm = this; + + vm.provider = null; + vm.instance = null; + + $scope.$on('data_refreshed', function(event, data) { + var stats = data.stats['cloud']; + + if (stats['ami-id'] !== undefined) { + vm.provider = 'AWS EC2'; + vm.instance = stats['instance-type'] + ' instance ' + stats['instance-id'] + ' (' + stats['region'] + ')'; + } + }); +} + +'use strict'; + glancesApp.component('glancesPluginCpu', { controller: GlancesPluginCpuController, controllerAs: 'vm', @@ -525,32 +550,6 @@ function GlancesPluginCpuController($scope) { 'use strict'; -glancesApp.component('glancesPluginCloud', { - controller: GlancesPluginCloudController, - controllerAs: 'vm', - templateUrl: 'components/plugin-cloud/view.html' -}); - -'use strict'; - -function GlancesPluginCloudController($scope) { - var vm = this; - - vm.provider = null; - vm.instance = null; - - $scope.$on('data_refreshed', function(event, data) { - var stats = data.stats['cloud']; - - if (stats['ami-id'] !== undefined) { - vm.provider = 'AWS EC2'; - vm.instance = stats['instance-type'] + ' instance ' + stats['instance-id'] + ' (' + stats['region'] + ')'; - } - }); -} - -'use strict'; - glancesApp.component('glancesPluginDiskio', { controller: GlancesPluginDiskioController, controllerAs: 'vm', @@ -649,39 +648,6 @@ function GlancesPluginFsController($scope, $filter) { 'use strict'; -glancesApp.component('glancesPluginIp', { - controller: GlancesPluginIpController, - controllerAs: 'vm', - bindings: { - arguments: '<' - }, - templateUrl: 'components/plugin-ip/view.html' -}); - -'use strict'; - -function GlancesPluginIpController($scope) { - var vm = this; - - vm.address = null; - vm.gateway = null; - vm.mask = null; - vm.maskCidr = null; - vm.publicAddress = null; - - $scope.$on('data_refreshed', function(event, data) { - var ipStats = data.stats['ip']; - - vm.address = ipStats.address; - vm.gateway = ipStats.gateway; - vm.mask = ipStats.mask; - vm.maskCidr = ipStats.mask_cidr; - vm.publicAddress = ipStats.public_address - }); -} - -'use strict'; - glancesApp.component('glancesPluginLoad', { controller: GlancesPluginLoadController, controllerAs: 'vm', @@ -758,6 +724,39 @@ function GlancesPluginMemController($scope) { 'use strict'; +glancesApp.component('glancesPluginIp', { + controller: GlancesPluginIpController, + controllerAs: 'vm', + bindings: { + arguments: '<' + }, + templateUrl: 'components/plugin-ip/view.html' +}); + +'use strict'; + +function GlancesPluginIpController($scope) { + var vm = this; + + vm.address = null; + vm.gateway = null; + vm.mask = null; + vm.maskCidr = null; + vm.publicAddress = null; + + $scope.$on('data_refreshed', function(event, data) { + var ipStats = data.stats['ip']; + + vm.address = ipStats.address; + vm.gateway = ipStats.gateway; + vm.mask = ipStats.mask; + vm.maskCidr = ipStats.mask_cidr; + vm.publicAddress = ipStats.public_address + }); +} + +'use strict'; + glancesApp.component('glancesPluginMemMore', { controller: GlancesPluginMemMoreController, controllerAs: 'vm', @@ -786,44 +785,6 @@ function GlancesPluginMemMoreController($scope) { 'use strict'; -glancesApp.component('glancesPluginMemswap', { - controller: GlancesPluginMemswapController, - controllerAs: 'vm', - templateUrl: 'components/plugin-memswap/view.html' -}); - -'use strict'; - -function GlancesPluginMemswapController($scope) { - var vm = this; - var _view = {}; - - vm.percent = null; - vm.total = null; - vm.used = null; - vm.free = null; - - $scope.$on('data_refreshed', function(event, data) { - var stats = data.stats['memswap']; - _view = data.view['memswap']; - - vm.percent = stats['percent']; - vm.total = stats['total']; - vm.used = stats['used']; - vm.free = stats['free']; - }); - - this.getDecoration = function (value) { - if (_view[value] === undefined) { - return; - } - - return _view[value].decoration.toLowerCase(); - }; -} - -'use strict'; - glancesApp.component('glancesPluginNetwork', { controller: GlancesPluginNetworkController, controllerAs: 'vm', @@ -1097,41 +1058,6 @@ function GlancesPluginProcesslistController($scope, GlancesPluginHelper, $filter 'use strict'; -glancesApp.component('glancesPluginSystem', { - controller: GlancesPluginSystemController, - controllerAs: 'vm', - bindings: { - isDisconnected: '<' - }, - templateUrl: 'components/plugin-system/view.html' -}); - -'use strict'; - -function GlancesPluginSystemController($scope) { - var vm = this; - - vm.hostname = null; - vm.platform = null; - vm.humanReadableName = null; - vm.os = { - 'name': null, - 'version': null - }; - - $scope.$on('data_refreshed', function(event, data) { - var stats = data.stats['system']; - - vm.hostname = stats['hostname']; - vm.platform = stats['platform']; - vm.os.name = stats['os_name']; - vm.os.version = stats['os_version']; - vm.humanReadableName = stats['hr_name']; - }); -} - -'use strict'; - glancesApp.component('glancesPluginQuicklook', { controller: GlancesPluginQuicklookController, controllerAs: 'vm', @@ -1186,20 +1112,41 @@ function GlancesPluginQuicklookController($scope) { 'use strict'; -glancesApp.component('glancesPluginUptime', { - controller: GlancesPluginUptimeController, +glancesApp.component('glancesPluginSystem', { + controller: GlancesPluginSystemController, controllerAs: 'vm', - templateUrl: 'components/plugin-uptime/view.html' + bindings: { + isDisconnected: '<' + }, + templateUrl: 'components/plugin-system/view.html' }); 'use strict'; -function GlancesPluginUptimeController($scope) { +function GlancesPluginSystemController($scope) { var vm = this; - vm.value = null; + + vm.hostname = null; + vm.platform = null; + vm.humanReadableName = null; + vm.os = { + 'name': null, + 'version': null + }; $scope.$on('data_refreshed', function(event, data) { - vm.value = data.stats['uptime']; + var stats = data.stats['system']; + + vm.hostname = stats['hostname']; + vm.platform = stats['platform']; + vm.os.name = stats['os_name']; + vm.os.version = stats['os_version']; + vm.humanReadableName = stats['hr_name']; + vm.isDisconnected = false; + }); + + $scope.$on('is_disconnected', function() { + vm.isDisconnected = true; }); } @@ -1250,3 +1197,60 @@ function GlancesPluginWifiController($scope, $filter) { return _view[hotpost.ssid][field].decoration.toLowerCase(); }; } + +'use strict'; + +glancesApp.component('glancesPluginUptime', { + controller: GlancesPluginUptimeController, + controllerAs: 'vm', + templateUrl: 'components/plugin-uptime/view.html' +}); + +'use strict'; + +function GlancesPluginUptimeController($scope) { + var vm = this; + vm.value = null; + + $scope.$on('data_refreshed', function(event, data) { + vm.value = data.stats['uptime']; + }); +} + +'use strict'; + +glancesApp.component('glancesPluginMemswap', { + controller: GlancesPluginMemswapController, + controllerAs: 'vm', + templateUrl: 'components/plugin-memswap/view.html' +}); + +'use strict'; + +function GlancesPluginMemswapController($scope) { + var vm = this; + var _view = {}; + + vm.percent = null; + vm.total = null; + vm.used = null; + vm.free = null; + + $scope.$on('data_refreshed', function(event, data) { + var stats = data.stats['memswap']; + _view = data.view['memswap']; + + vm.percent = stats['percent']; + vm.total = stats['total']; + vm.used = stats['used']; + vm.free = stats['free']; + }); + + this.getDecoration = function (value) { + if (_view[value] === undefined) { + return; + } + + return _view[value].decoration.toLowerCase(); + }; +} diff --git a/glances/outputs/static/public/js/templates.min.js b/glances/outputs/static/public/js/templates.min.js index 0146ea7b..11022c5b 100644 --- a/glances/outputs/static/public/js/templates.min.js +++ b/glances/outputs/static/public/js/templates.min.js @@ -1,22 +1,22 @@ angular.module('glancesApp').run(['$templateCache', function($templateCache) {$templateCache.put('components/glances/view.html','
\n
\n \n
Loading...
\n
\n\n \n\n
\n
\n
\n
\n
\n \n
\n
\n \n
\n
\n \n
\n
\n
\n
\n
\n \n
\n
\n
\n
\n
\n\n
\n \n
\n \n
\n
\n \n
\n \n
\n \n
\n \n
\n \n
\n
\n \n
\n
\n
\n \n
\n \n \n \n
\n
\n
\n
\n\n'); $templateCache.put('components/help/view.html','
\n
\n
{{vm.help.version}} {{vm.help.psutil_version}}
\n
\n
 
\n
\n
{{vm.help.configuration_file}}
\n
\n
 
\n
\n
{{vm.help.sort_auto}}
\n
{{vm.help.sort_network}}
\n
\n
\n
{{vm.help.sort_cpu}}
\n
{{vm.help.show_hide_alert}}
\n
\n
\n
{{vm.help.sort_mem}}
\n
{{vm.help.percpu}}
\n
\n
\n
{{vm.help.sort_user}}
\n
{{vm.help.show_hide_ip}}
\n
\n
\n
{{vm.help.sort_proc}}
\n
{{vm.help.enable_disable_docker}}
\n
\n
\n
{{vm.help.sort_io}}
\n
{{vm.help.view_network_io_combination}}
\n
\n
\n
{{vm.help.sort_cpu_times}}
\n
{{vm.help.view_cumulative_network}}
\n
\n
\n
{{vm.help.show_hide_diskio}}
\n
{{vm.help.show_hide_filesytem_freespace}}
\n
\n
\n
{{vm.help.show_hide_filesystem}}
\n
{{vm.help.show_hide_vm.help}}
\n
\n
\n
{{vm.help.show_hide_network}}
\n
{{vm.help.diskio_iops}}
\n
\n
\n
{{vm.help.show_hide_sensors}}
\n
{{vm.help.show_hide_top_menu}}
\n
\n
\n
{{vm.help.show_hide_left_sidebar}}
\n
{{vm.help.show_hide_amp}}
\n
\n
\n
{{vm.help.enable_disable_process_stats}}
\n
{{vm.help.show_hide_irq}}
\n
\n
\n
{{vm.help.enable_disable_gpu}}
\n
{{vm.help.enable_disable_mean_gpu}}
\n
\n
\n
{{vm.help.enable_disable_quick_look}}
\n
\n
\n
\n
{{vm.help.enable_disable_short_processname}}
\n
\n
\n
\n
{{vm.help.enable_disable_ports}}
\n
\n
\n\n
\n'); $templateCache.put('components/plugin-alert/view.html','
\n No warning or critical alert detected\n Warning or critical alerts (lasts {{vm.count()}} entries)\n
\n
\n
\n
\n
\n {{alert.begin | date : \'yyyy-MM-dd H:mm:ss\'}} ({{ alert.ongoing ? \'ongoing\' : alert.duration }}) - {{alert.level}} on {{alert.name}} ({{alert.max}})\n
\n
\n
\n
\n'); -$templateCache.put('components/plugin-cpu/view.html','
\n
\n
\n
\n
\n
CPU
\n
{{ vm.total }}%
\n
\n
\n
user:
\n
\n {{ vm.user }}%\n
\n
\n
\n
system:
\n
\n {{ vm.system }}%\n
\n
\n
\n
idle:
\n
{{ vm.idle }}%
\n
\n
\n
\n \n \n
\n
\n'); $templateCache.put('components/plugin-cloud/view.html','
\n {{ vm.provider }} {{ vm.instance }}\n
\n'); +$templateCache.put('components/plugin-cpu/view.html','
\n
\n
\n
\n
\n
CPU
\n
{{ vm.total }}%
\n
\n
\n
user:
\n
\n {{ vm.user }}%\n
\n
\n
\n
system:
\n
\n {{ vm.system }}%\n
\n
\n
\n
idle:
\n
{{ vm.idle }}%
\n
\n
\n
\n \n \n
\n
\n'); $templateCache.put('components/plugin-diskio/view.html','
\n
DISK I/O
\n
R/s
\n
W/s
\n\n
IOR/s
\n
IOW/s
\n
\n
\n
{{(disk.alias ? disk.alias : disk.name) | min_size}}
\n
{{disk.bitrate.txps }}
\n
{{disk.bitrate.rxps }}
\n\n
{{disk.count.txps }}
\n
{{disk.count.rxps }}
\n
\n'); $templateCache.put('components/plugin-fs/view.html','
\n
FILE SYS
\n
\n Used\n Free\n
\n
Total
\n
\n
\n
{{ fs.shortMountPoint }} ({{ fs.name }})
\n
\n {{ fs.used | bytes }}\n {{ fs.free | bytes }}\n
\n
{{ fs.size | bytes }}
\n
\n'); -$templateCache.put('components/plugin-ip/view.html','
\n  - IP {{ vm.address }}/{{ vm.maskCidr }} Pub {{ vm.publicAddress }}\n
\n'); $templateCache.put('components/plugin-load/view.html','
\n
\n
\n
LOAD
\n
{{ vm.cpucore }}-core
\n
\n
\n
1 min:
\n
\n {{ vm.min1 | number : 2}}\n
\n
\n
\n
5 min:
\n
\n {{ vm.min5 | number : 2}}\n
\n
\n
\n
15 min:
\n
\n {{ vm.min15 | number : 2}}\n
\n
\n
\n
\n'); $templateCache.put('components/plugin-mem/view.html','
\n
\n
\n
MEM
\n
{{ vm.percent }}%
\n
\n
\n
total:
\n
{{ vm.total | bytes }}
\n
\n
\n
used:
\n
\n {{ vm.used | bytes:2 }}\n
\n
\n
\n
free:
\n
{{ vm.free | bytes }}
\n
\n
\n
\n'); +$templateCache.put('components/plugin-ip/view.html','
\n  - IP {{ vm.address }}/{{ vm.maskCidr }} Pub {{ vm.publicAddress }}\n
\n'); $templateCache.put('components/plugin-mem-more/view.html','
\n
\n
\n
active:
\n
{{ vm.active | bytes }}
\n
\n
\n
inactive:
\n
{{ vm.inactive | bytes }}
\n
\n
\n
buffers:
\n
{{ vm.buffers | bytes }}
\n
\n
\n
cached:
\n
{{ vm.cached | bytes }}
\n
\n
\n
\n'); -$templateCache.put('components/plugin-memswap/view.html','
\n
\n
\n
SWAP
\n
{{ vm.percent }}%
\n
\n
\n
total:
\n
{{ vm.total | bytes }}
\n
\n
\n
used:
\n
\n {{ vm.used | bytes }}\n
\n
\n
\n
free:
\n
{{ vm.free | bytes }}
\n
\n
\n
\n'); $templateCache.put('components/plugin-network/view.html','
\n
NETWORK
\n
Rx/s
\n
Tx/s
\n\n
\n
Rx+Tx/s
\n\n
Rx
\n
Tx
\n\n
\n
Rx+Tx
\n
\n
\n
{{ network.interfaceName | min_size }}
\n
{{ vm.arguments.byte ? (network.rx / network.time_since_update | bytes) : (network.rx / network.time_since_update | bits) }}
\n
{{ vm.arguments.byte ? (network.tx / network.time_since_update | bytes) : (network.tx / network.time_since_update | bits) }}
\n\n
\n
{{ vm.arguments.byte ? (network.cx / network.time_since_update | bytes) : (network.cx / network.time_since_update | bits) }}
\n\n
{{ vm.arguments.byte ? (network.cumulativeRx | bytes) : (network.cumulativeRx | bits) }}
\n
{{ vm.arguments.byte ? (network.cumulativeTx | bytes) : (network.cumulativeTx | bits) }}
\n\n
\n
{{ vm.arguments.byte ? (network.cumulativeCx | bytes) : (network.cumulativeCx | bits) }}
\n
\n'); $templateCache.put('components/plugin-percpu/view.html','
\n
\n
\n
PER CPU
\n
{{ percpu.total }}%
\n
\n
\n
user:
\n
\n {{ percpu.user }}%\n
\n
\n
\n
system:
\n
\n {{ percpu.system }}%\n
\n
\n
\n
idle:
\n
{{ percpu.idle }}%
\n
\n
\n
iowait:
\n
\n {{ percpu.iowait }}%\n
\n
\n
\n
steal:
\n
\n {{ percpu.steal }}%\n
\n
\n
\n
\n'); $templateCache.put('components/plugin-ports/view.html','
\n
{{(port.description ? port.description : port.host + \' \' + port.port) | min_size: 20}}
\n
\n
\n Scanning\n Timeout\n Open\n {{port.status * 1000.0 | number:0}}ms\n
\n
'); $templateCache.put('components/plugin-process/view.html','
\n \n \n \n
\n
PROCESSES DISABLED (press \'z\' to display)
\n'); $templateCache.put('components/plugin-processcount/view.html','
\n TASKS\n {{ vm.total }} ({{ vm.thread }} thr),\n {{ vm.running }} run,\n {{ vm.sleeping }} slp,\n {{ vm.stopped }} oth\n sorted {{ vm.sorter.auto ? \'automatically\' : \'\' }} by {{ vm.sorter.getColumnLabel(vm.sorter.column) }}, flat view\n
'); $templateCache.put('components/plugin-processlist/view.html','
\n
\n
\n
CPU%
\n
MEM%
\n \n \n
PID
\n
USER
\n
NI
\n
S
\n \n \n \n
Command
\n
\n
\n
{{process.cpu_percent | number:1}}
\n
{{process.memory_percent | number:1}}
\n \n \n
{{process.pid}}
\n
{{process.username}}
\n
{{process.nice | exclamation}}
\n
{{process.status}}
\n \n \n \n
{{process.name}}
\n
{{process.cmdline}}
\n
\n
\n
\n'); -$templateCache.put('components/plugin-system/view.html','
\n Disconnected from\n {{ vm.hostname }}\n \n \n
\n'); $templateCache.put('components/plugin-quicklook/view.html','
\n
\n {{ vm.cpu_name }}\n
\n
\n
\n
CPU
\n
\n
\n
\n  \n
\n
\n
\n
\n {{ vm.cpu }}%\n
\n
\n
\n
CPU{{ percpu.number }}
\n
\n
\n
\n  \n
\n
\n
\n
\n {{ percpu.total }}%\n
\n
\n
\n
MEM
\n
\n
\n
\n  \n
\n
\n
\n
\n {{ vm.mem }}%\n
\n
\n
\n
SWAP
\n
\n
\n
\n  \n
\n
\n
\n
\n {{ vm.swap }}%\n
\n
\n
\n
\n'); +$templateCache.put('components/plugin-system/view.html','
\n Disconnected from\n {{ vm.hostname }}\n \n \n
\n'); +$templateCache.put('components/plugin-wifi/view.html','
\n
\n
WIFI
\n
\n
dBm
\n
\n
\n
{{ hotspot.ssid|limitTo:20 }} {{ hotspot.encryption_type }}
\n
\n
{{ hotspot.signal }}
\n
\n
\n'); $templateCache.put('components/plugin-uptime/view.html','
\n Uptime: {{ vm.value }}\n
\n'); -$templateCache.put('components/plugin-wifi/view.html','
\n
\n
WIFI
\n
\n
dBm
\n
\n
\n
{{ hotspot.ssid|limitTo:20 }} {{ hotspot.encryption_type }}
\n
\n
{{ hotspot.signal }}
\n
\n
\n');}]); \ No newline at end of file +$templateCache.put('components/plugin-memswap/view.html','
\n
\n
\n
SWAP
\n
{{ vm.percent }}%
\n
\n
\n
total:
\n
{{ vm.total | bytes }}
\n
\n
\n
used:
\n
\n {{ vm.used | bytes }}\n
\n
\n
\n
free:
\n
{{ vm.free | bytes }}
\n
\n
\n
\n');}]); \ No newline at end of file