提交 83728d14 编写于 作者: F Floran Brutel

Big refactoring of the Web UI

Move logic from controller and views to the new services GlancesStats and GlancesPlugins : GlanceStats load data from api and set data in plugins. Plugins are responsible for transforming data for the view.
GetAlert is now in GlancesPlugin
Use view data instead of getAlert when is possible
Remove directives for monitor plugin
上级 1722dbc3
......@@ -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
......
<div class="table-cell {{ descriptionClass }}">{{ process.description }}</div>
<div class="table-cell">{{ process.count > 1 ? process.count : '' }}</div>
<div class="table-cell">{{ process.count > 0 ? 'RUNNING' : 'NOT RUNNING' }}</div>
<div class="table-cell">{{ process.result }}</div>
......@@ -18,6 +18,25 @@
<script type="text/javascript" src="filters.js"></script>
<script type="text/javascript" src="variables.js"></script>
<script type="text/javascript" src="directives.js"></script>
<script type="text/javascript" src="services/core/glances_stats.js"></script>
<script type="text/javascript" src="services/plugins/glances_plugin.js"></script>
<script type="text/javascript" src="services/plugins/glances_alert.js"></script>
<script type="text/javascript" src="services/plugins/glances_cpu.js"></script>
<script type="text/javascript" src="services/plugins/glances_diskio.js"></script>
<script type="text/javascript" src="services/plugins/glances_docker.js"></script>
<script type="text/javascript" src="services/plugins/glances_fs.js"></script>
<script type="text/javascript" src="services/plugins/glances_ip.js"></script>
<script type="text/javascript" src="services/plugins/glances_load.js"></script>
<script type="text/javascript" src="services/plugins/glances_mem.js"></script>
<script type="text/javascript" src="services/plugins/glances_memswap.js"></script>
<script type="text/javascript" src="services/plugins/glances_monitor.js"></script>
<script type="text/javascript" src="services/plugins/glances_network.js"></script>
<script type="text/javascript" src="services/plugins/glances_percpu.js"></script>
<script type="text/javascript" src="services/plugins/glances_processcount.js"></script>
<script type="text/javascript" src="services/plugins/glances_processlist.js"></script>
<script type="text/javascript" src="services/plugins/glances_sensors.js"></script>
<script type="text/javascript" src="services/plugins/glances_system.js"></script>
<script type="text/javascript" src="services/plugins/glances_uptime.js"></script>
<script type="text/javascript" src="stats_controller.js"></script>
</head>
......
<div class="table">
<div class="table-row" ng-repeat="alert in result['alert']">
<div class="table-row" ng-repeat="alert in statsAlert.getAlerts()">
<div class="table-cell text-left">
{{alert.begin | date : 'yyyy-MM-dd H:mm:ss'}} ({{ alert.ongoing ? 'ongoing' : alert.duration }}) - {{alert[2]}} on <span class="{{ alert[2] | lowercase }}">{{alert[3]}}</span> ({{alert[4]}})
{{alert.begin | date : 'yyyy-MM-dd H:mm:ss'}} ({{ alert.ongoing ? 'ongoing' : alert.duration }}) - {{alert.level}} on <span class="{{ alert.level | lowercase }}">{{alert.name}}</span> ({{alert.max}})
</div>
</div>
</div>
<span class="title" ng-show="!result['alert'].length">No warning or critical alert detected</span>
<span class="title" ng-show="result['alert'].length">Warning or critical alerts (lasts {{result['alert'].length}} entries)</span>
<span class="title" ng-show="!statsAlert.hasAlerts()">No warning or critical alert detected</span>
<span class="title" ng-show="statsAlert.hasAlerts()">Warning or critical alerts (lasts {{statsAlert.count()}} entries)</span>
<div class="table">
<div class="table-row">
<div class="table-cell text-left title">CPU</div>
<div class="table-cell">{{result["cpu"].total}}%</div>
<div class="table-cell">{{ statsCpu.total }}%</div>
</div>
<div class="table-row">
<div class="table-cell text-left">user:</div>
<div class="table-cell" ng-class="getAlertLog('cpu', 'cpu_user_', result['cpu'].user)">
{{result["cpu"].user}}%
<div class="table-cell" ng-class="statsCpu.getDecoration('user')">
{{ statsCpu.user }}%
</div>
</div>
<div class="table-row">
<div class="table-cell text-left">system:</div>
<div class="table-cell" ng-class="getAlertLog('cpu', 'cpu_system_', result['cpu'].system)">
{{result["cpu"].system}}%
<div class="table-cell" ng-class="statsCpu.getDecoration('system')">
{{ statsCpu.system }}%
</div>
</div>
<div class="table-row">
<div class="table-cell text-left">idle:</div>
<div class="table-cell">{{result["cpu"].idle}}%</div>
<div class="table-cell">{{ statsCpu.idle }}%</div>
</div>
</div>
......@@ -2,25 +2,25 @@
<div class="table-row">
<div class="table-cell text-left">nice:</div>
<div class="table-cell">
{{result["cpu"].nice}}%
{{ statsCpu.nice }}%
</div>
</div>
<div class="table-row" ng-if="result['cpu'].irq != undefined">
<div class="table-row" ng-show="statsCpu.irq != undefined">
<div class="table-cell text-left">irq:</div>
<div class="table-cell">
{{result["cpu"].irq}}%
{{ statsCpu.irq }}%
</div>
</div>
<div class="table-row" ng-if="result['cpu'].iowait != undefined">
<div class="table-row" ng-show="statsCpu.iowait != undefined">
<div class="table-cell text-left">iowait:</div>
<div class="table-cell" ng-class="getAlertLog('cpu', 'cpu_iowait_', result['cpu'].iowait)">
{{result["cpu"].iowait}}%
<div class="table-cell" ng-class="statsCpu.getDecoration('iowait')">
{{ statsCpu.iowait }}%
</div>
</div>
<div class="table-row" ng-if="result['cpu'].steal != undefined">
<div class="table-row" ng-show="statsCpu.steal != undefined">
<div class="table-cell text-left">steal:</div>
<div class="table-cell" ng-class="getAlert('cpu', 'cpu_steal_', result['cpu'].steal)">
{{result["cpu"].steal}}%
<div class="table-cell" ng-class="statsCpu.getDecoration('steal')">
{{ statsCpu.steal }}%
</div>
</div>
</div>
......@@ -3,8 +3,8 @@
<div class="table-cell">R/s</div>
<div class="table-cell">W/s</div>
</div>
<div class="table-row" ng-repeat="disk in result['diskio'] | orderBy: 'disk_name'">
<div class="table-cell text-left">{{disk.disk_name | min_size}}</div>
<div class="table-cell">{{disk.read_bytes | bytes}}</div>
<div class="table-cell">{{disk.write_bytes | bytes}}</div>
<div class="table-row" ng-repeat="disk in statsDiskio.disks | orderBy: 'name'">
<div class="table-cell text-left">{{disk.name | min_size}}</div>
<div class="table-cell">{{disk.readBytes | bytes}}</div>
<div class="table-cell">{{disk.writeBytes | bytes}}</div>
</div>
<span class="title">CONTAINERS</span> {{ result['docker']['containers'].length }} (served by Docker {{ result['docker']['version']['Version'] }})
<span class="title">CONTAINERS</span> {{ statsDocker.containers.length }} (served by Docker {{ statsDocker.version }})
<div class="table">
<div class="table-row">
......@@ -9,12 +9,12 @@
<div class="table-cell">MEM</div>
<div class="table-cell text-left">Command</div>
</div>
<div class="table-row" ng-repeat="container in result['docker']['containers']">
<div class="table-cell">{{ container.Id | limitTo:12 }}</div>
<div class="table-cell text-left">{{ container.Names[0] }}</div>
<div class="table-cell" ng-class="container.Status == 'Paused' ? 'careful' : 'ok'">{{ container.Status }}</div>
<div class="table-cell">{{ container.cpu.total | number:1 }}</div>
<div class="table-cell">{{ container.memory.usage | bytes }}</div>
<div class="table-cell text-left">{{ container.Command }}</div>
<div class="table-row" ng-repeat="container in statsDocker.containers">
<div class="table-cell">{{ container.id | limitTo:12 }}</div>
<div class="table-cell text-left">{{ container.name }}</div>
<div class="table-cell" ng-class="container.status == 'Paused' ? 'careful' : 'ok'">{{ container.status }}</div>
<div class="table-cell">{{ container.cpu | number:1 }}</div>
<div class="table-cell">{{ container.memory | bytes }}</div>
<div class="table-cell text-left">{{ container.command }}</div>
</div>
</div>
......@@ -3,10 +3,10 @@
<div class="table-cell">Used</div>
<div class="table-cell">Total</div>
</div>
<div class="table-row" ng-repeat="fs in result['fs'] | orderBy: 'mnt_point'">
<div class="table-cell text-left">{{fs.mnt_point}} ({{fs.device_name}})</div>
<div class="table-cell" ng-class="getAlert('fs', 'fs_', fs.percent)">
{{fs.size - fs.free | bytes}}
<div class="table-row" ng-repeat="fs in statsFs.fileSystems | orderBy: 'mnt_point'">
<div class="table-cell text-left">{{ fs.mountPoint }} ({{ fs.name }})</div>
<div class="table-cell" ng-class="statsFs.getDecoration(fs.mountPoint, 'used')">
{{ fs.size - fs.free | bytes }}
</div>
<div class="table-cell">{{fs.size | bytes}}</div>
<div class="table-cell">{{ fs.size | bytes }}</div>
</div>
&nbsp;-&nbsp;<span class="title">IP</span> <span>{{result["ip"].address}}/{{result["ip"].mask_cidr}}</span>
&nbsp;-&nbsp;<span class="title">IP</span> <span>{{ statsIp.address }}/{{ statsIp.maskCidr }}</span>
<div class="table">
<div class="table-row">
<div class="table-cell text-left title">LOAD</div>
<div class="table-cell">{{result["load"].cpucore}}-core</div>
<div class="table-cell">{{ statsLoad.cpucore }}-core</div>
</div>
<div class="table-row">
<div class="table-cell text-left">1 min:</div>
<div class="table-cell">
{{result["load"].min1 | number : 2}}
{{ statsLoad.min1 | number : 2}}
</div>
</div>
<div class="table-row">
<div class="table-cell text-left">5 min:</div>
<div class="table-cell" ng-class="getAlert('load', 'load_', result['load'].min5, 100 * result['load'].cpucore)">
{{result["load"].min5 | number : 2}}
<div class="table-cell" ng-class="statsLoad.getDecoration('min5')">
{{ statsLoad.min5 | number : 2}}
</div>
</div>
<div class="table-row">
<div class="table-cell text-left">15 min:</div>
<div class="table-cell" ng-class="getAlertLog('load', 'load_', result['load'].min15, 100 * result['load'].cpucore)">
{{result["load"].min15 | number : 2}}
<div class="table-cell" ng-class="statsLoad.getDecoration('min15')">
{{ statsLoad.min15 | number : 2}}
</div>
</div>
</div>
<div class="table">
<div class="table-row">
<div class="table-cell text-left title">MEM</div>
<div class="table-cell">{{result["mem"].percent}}%</div>
<div class="table-cell">{{ statsMem.percent }}%</div>
</div>
<div class="table-row">
<div class="table-cell text-left">total:</div>
<div class="table-cell">{{result["mem"].total | bytes}}</div>
<div class="table-cell">{{ statsMem.total | bytes }}</div>
</div>
<div class="table-row">
<div class="table-cell text-left">used:</div>
<div class="table-cell" ng-class="getAlertLog('mem', 'mem_', result['mem'].percent)">
{{result["mem"].used | bytes:2}}
<div class="table-cell" ng-class="statsMem.getDecoration('used')">
{{ statsMem.used | bytes:2 }}
</div>
</div>
<div class="table-row">
<div class="table-cell text-left">free:</div>
<div class="table-cell">{{result["mem"].free | bytes}}</div>
<div class="table-cell">{{ statsMem.free | bytes }}</div>
</div>
</div>
<div class="table">
<div class="table-row">
<div class="table-cell text-left">active:</div>
<div class="table-cell">{{result["mem"].active | bytes}}</div>
<div class="table-cell">{{ statsMem.active | bytes }}</div>
</div>
<div class="table-row">
<div class="table-cell text-left">inactive:</div>
<div class="table-cell">{{result["mem"].inactive | bytes}}</div>
<div class="table-cell">{{ statsMem.inactive | bytes }}</div>
</div>
<div class="table-row" ng-if="result['mem'].buffers != undefined">
<div class="table-row" ng-show="statsMem.buffers != undefined">
<div class="table-cell text-left">buffers:</div>
<div class="table-cell">{{result["mem"].buffers | bytes}}</div>
<div class="table-cell">{{ statsMem.buffers | bytes }}</div>
</div>
<div class="table-row" ng-if="result['mem'].cached != undefined">
<div class="table-row" ng-show="statsMem.cached != undefined">
<div class="table-cell text-left">cached:</div>
<div class="table-cell">{{result["mem"].cached | bytes}}</div>
<div class="table-cell">{{ statsMem.cached | bytes }}</div>
</div>
</div>
<div class="table">
<div class="table-row">
<div class="table-cell text-left title">SWAP</div>
<div class="table-cell">{{result["memswap"].percent}}%</div>
<div class="table-cell">{{ statsMemSwap.percent }}%</div>
</div>
<div class="table-row">
<div class="table-cell text-left">total:</div>
<div class="table-cell">{{result["memswap"].total | bytes}}</div>
<div class="table-cell">{{ statsMemSwap.total | bytes }}</div>
</div>
<div class="table-row">
<div class="table-cell text-left">used:</div>
<div class="table-cell" ng-class="getAlertLog('memswap', 'memswap_', result['memswap'].percent)">
{{result["memswap"].used | bytes}}
<div class="table-cell" ng-class="statsMemSwap.getDecoration('used')">
{{ statsMemSwap.used | bytes }}
</div>
</div>
<div class="table-row">
<div class="table-cell text-left">free:</div>
<div class="table-cell">{{result["memswap"].free | bytes}}</div>
<div class="table-cell">{{ statsMemSwap.free | bytes }}</div>
</div>
</div>
<div class="table">
<gl-monitor-process class="table-row" ng-repeat="process in processes" process="process"></gl-monitor-process>
<div class="table-row" ng-repeat="process in statsMonitor.processes">
<div class="table-cell" ng-class="statsMonitor.getDesciptionDecoration(process)">{{ process.description }}</div>
<div class="table-cell">{{ process.count > 1 ? process.count : '' }}</div>
<div class="table-cell">{{ process.count > 0 ? 'RUNNING' : 'NOT RUNNING' }}</div>
<div class="table-cell">{{ process.result }}</div>
</div>
</div>
......@@ -3,10 +3,10 @@
<div class="table-cell">Rx/s</div>
<div class="table-cell">Tx/s</div>
</div>
<div class="table-row" ng-repeat="network in result['network'] | orderBy: 'interface_name'">
<div class="table-cell text-left">{{network.interface_name | min_size}}</div>
<div class="table-cell" ng-if="show.network_by_bytes">{{network.rx | bytes}}</div>
<div class="table-cell" ng-if="show.network_by_bytes">{{network.tx | bytes}}</div>
<div class="table-cell" ng-if="!show.network_by_bytes">{{network.rx | bits}}</div>
<div class="table-cell" ng-if="!show.network_by_bytes">{{network.tx | bits}}</div>
<div class="table-row" ng-repeat="network in statsNetwork.networks | orderBy: 'interfaceName'">
<div class="table-cell text-left">{{ network.interfaceName | min_size }}</div>
<div class="table-cell" ng-show="show.network_by_bytes">{{ network.rx | bytes }}</div>
<div class="table-cell" ng-show="show.network_by_bytes">{{ network.tx | bytes }}</div>
<div class="table-cell" ng-show="!show.network_by_bytes">{{ network.rx | bits }}</div>
<div class="table-cell" ng-show="!show.network_by_bytes">{{ network.tx | bits }}</div>
</div>
<div class="table">
<div class="table-row">
<div class="table-cell text-left title">PER CPU</div>
<div class="table-cell" ng-repeat="percpu in result.percpu">{{percpu.total}}%</div>
<div class="table-cell" ng-repeat="percpu in statsPerCpu.cpus">{{ percpu.total }}%</div>
</div>
<div class="table-row">
<div class="table-cell text-left">user:</div>
<div class="table-cell" ng-repeat="percpu in result.percpu" ng-class="getAlert('percpu', 'percpu_user_', percpu.user)">
{{percpu.user}}%
<div class="table-cell" ng-repeat="percpu in statsPerCpu.cpus" ng-class="statsPerCpu.getUserAlert(percpu)">
{{ percpu.user }}%
</div>
</div>
<div class="table-row">
<div class="table-cell text-left">system:</div>
<div class="table-cell" ng-repeat="percpu in result.percpu" ng-class="getAlert('percpu', 'percpu_system_', percpu.system)">
{{percpu.system}}%
<div class="table-cell" ng-repeat="percpu in statsPerCpu.cpus" ng-class="statsPerCpu.getSystemAlert(percpu)">
{{ percpu.system }}%
</div>
</div>
<div class="table-row">
<div class="table-cell text-left">idle:</div>
<div class="table-cell" ng-repeat="percpu in result.percpu">{{percpu.idle}}%</div>
<div class="table-cell" ng-repeat="percpu in statsPerCpu.cpus">{{ percpu.idle }}%</div>
</div>
</div>
<span class="title">TASKS</span>
<span>{{result["processcount"].total}} ({{result["processcount"].thread}} thr),</span>
<span>{{result["processcount"].running}} run,</span>
<span>{{result["processcount"].sleeping}} slp,</span>
<span>{{result["processcount"].stopped}} oth</span>
<span>{{ statsProcessCount.total }} ({{ statsProcessCount.thread }} thr),</span>
<span>{{ statsProcessCount.running }} run,</span>
<span>{{ statsProcessCount.sleeping }} slp,</span>
<span>{{ statsProcessCount.stopped }} oth</span>
<span> sorted {{ sorter.auto ? 'automatically' : '' }} by {{ sorter.getColumnLabel(sorter.column) }}, flat view</span>
......@@ -13,21 +13,21 @@
<div sortable-th sorter="sorter" column="io_write" class="table-cell hidden-xs hidden-sm">IOW/s</div>
<div sortable-th sorter="sorter" column="name" class="table-cell text-left">Command</div>
</div>
<div class="table-row" ng-repeat="process in result['processlist'] | orderBy:sorter.column:sorter.isReverseColumn(sorter.column)">
<div class="table-cell" ng-class="getAlert('processlist', 'processlist_cpu_', process.cpu_percent)">{{process.cpu_percent | number:1}}</div>
<div class="table-cell" ng-class="getAlert('processlist', 'processlist_mem_', process.memory_percent)">{{process.memory_percent | number:1}}</div>
<div class="table-row" ng-repeat="process in statsProcessList.processes | orderBy:sorter.column:sorter.isReverseColumn(sorter.column)">
<div class="table-cell" ng-class="statsProcessList.getCpuPercentAlert(process)">{{process.cpu_percent | number:1}}</div>
<div class="table-cell" ng-class="statsProcessList.getMemoryPercentAlert(process)">{{process.memory_percent | number:1}}</div>
<div class="table-cell hidden-xs hidden-sm">{{process.memvirt | bytes}}</div>
<div class="table-cell hidden-xs hidden-sm">{{process.memres | bytes}}</div>
<div class="table-cell">{{process.pid}}</div>
<div class="table-cell text-left">{{process.username}}</div>
<div class="table-cell" ng-class="{nice: isNice(process.nice)}">{{process.nice | exclamation}}</div>
<div class="table-cell" ng-class="{nice: process.isNice}">{{process.nice | exclamation}}</div>
<div class="table-cell" ng-class="{status: process.status == 'R'}">{{process.status}}</div>
<div class="table-cell hidden-xs hidden-sm">
<span ng-show="process.timeplus.hours > 0" class="highlight">{{ process.timeplus.hours }}h</span>{{ process.timeplus.minutes | leftPad:2:'0' }}:{{ process.timeplus.seconds | leftPad:2:'0' }}<span ng-show="process.timeplus.hours <= 0">.{{ process.timeplus.milliseconds | leftPad:2:'0' }}</span>
</div>
<div class="table-cell hidden-xs hidden-sm">{{process.io_read}}</div>
<div class="table-cell hidden-xs hidden-sm">{{process.io_write}}</div>
<div class="table-cell text-left" ng-if="show.short_process_name">{{process.name}}</div>
<div class="table-cell text-left" ng-if="!show.short_process_name">{{process.cmdline}}</div>
<div class="table-cell hidden-xs hidden-sm">{{process.ioRead}}</div>
<div class="table-cell hidden-xs hidden-sm">{{process.iowrite}}</div>
<div class="table-cell text-left" ng-show="show.short_process_name">{{process.name}}</div>
<div class="table-cell text-left" ng-show="!show.short_process_name">{{process.cmdline}}</div>
</div>
</div>
<div class="table-row">
<div class="table-cell text-left title">SENSORS</div>
</div>
<div class="table-row" ng-repeat="sensor in result['sensors']">
<div class="table-row" ng-repeat="sensor in statsSensors.sensors">
<div class="table-cell text-left">{{ sensor.label }}</div>
<div class="table-cell">{{ sensor.unit }}</div>
<div class="table-cell" ng-if="sensor.type != 'battery'" ng-class="getAlert('sensors', 'sensors_' + sensor.type + '_', sensor.value)">
{{ sensor.value }}
</div>
<div class="table-cell" ng-if="sensor.type == 'battery'" ng-class="getAlert('sensors', 'sensors_' + sensor.type + '_', 100 - sensor.value)">
{{ sensor.value }}
</div>
<div class="table-cell" ng-class="statsSensors.getAlert(sensor)">{{ sensor.value }}</div>
</div>
<span ng-if="is_disconnected" class="critical">Disconnected from</span>
<span class="title">{{ result["system"].hostname }}</span>
<span ng-if="is_linux" class="hidden-xs hidden-sm">({{ result["system"].hr_name }} / {{ result["system"].os_name }} {{ result["system"].os_version }})</span>
<span ng-if="!is_linux" class="hidden-xs hidden-sm">({{ result["system"].os_name }} {{ result["system"].os_version }} {{ result["system"].platform }})</span>
<span class="title">{{ statsSystem.hostname }}</span>
<span ng-show="statsSystem.isLinux()" class="hidden-xs hidden-sm">({{ statsSystem.humanReadableName }} / {{ statsSystem.os.name }} {{ statsSystem.os.version }})</span>
<span ng-show="!statsSystem.isLinux()" class="hidden-xs hidden-sm">({{ statsSystem.os.name }} {{ statsSystem.os.version }} {{ statsSystem.platform }})</span>
\ No newline at end of file
<span>Uptime: {{result["uptime"]}}</span>
<span>Uptime: {{ statsUptime.uptime }}</span>
<div ng-show="!result" class="container-fluid" id="loading-page">
<div ng-show="!dataLoaded" class="container-fluid" id="loading-page">
<div class="glances-logo"></div>
<div class="loader">Loading...</div>
</div>
<div ng-show="help_screen" class="container-fluid" ng-include src="'help.html'"></div>
<div ng-show="result && !help_screen" class="container-fluid">
<div ng-show="dataLoaded && !help_screen" class="container-fluid">
<div class="row">
<div class="col-sm-12">
<div class="pull-left">
<section id="system" class="plugin" ng-include src="'plugins/system.html'"></section>
</div>
<div class="pull-left">
<section id="ip" class="plugin" ng-if="result['ip'].address != undefined" ng-include src="'plugins/ip.html'"></section>
<section id="ip" class="plugin" ng-if="statsIp.address != undefined" ng-include src="'plugins/ip.html'"></section>
</div>
<div class="pull-right">
<section id="uptime" class="plugin" ng-include src="'plugins/uptime.html'"></section>
......@@ -24,13 +24,13 @@
<section id="cpu" class="plugin" ng-include src="'plugins/cpu.html'"></section>
</div>
<div class="hidden-xs hidden-sm col-md-2" ng-show="!show.per_cpu">
<section id="cpu_more" class="plugin" ng-if="result['cpu'].nice != undefined" ng-include src="'plugins/cpu_more.html'"></section>
<section id="cpu_more" class="plugin" ng-if="statsCpu.nice != undefined" ng-include src="'plugins/cpu_more.html'"></section>
</div>
<div class="col-sm-6 col-md-4" ng-show="show.per_cpu">
<section id="per_cpu" class="plugin" ng-include src="'plugins/per_cpu.html'"></section>
</div>
<div class="col-sm-3 col-md-2">
<section id="load" class="plugin" ng-if="result['load'].cpucore != undefined" ng-include src="'plugins/load.html'"></section>
<section id="load" class="plugin" ng-if="statsLoad.cpucore != undefined" ng-include src="'plugins/load.html'"></section>
</div>
<div class="col-sm-3 col-md-2">
<section id="mem" class="plugin" ng-include src="'plugins/mem.html'"></section>
......@@ -48,17 +48,17 @@
<section id="network" class="plugin table-row-group" ng-show="show.network" ng-include src="'plugins/network.html'"></section>
<section id="diskio" class="plugin table-row-group" ng-show="show.diskio" ng-include src="'plugins/diskio.html'"></section>
<section id="fs" class="plugin table-row-group" ng-show="show.fs" ng-include src="'plugins/fs.html'"></section>
<section id="sensors" class="plugin table-row-group" ng-show="show.sensors && result['sensors'].length > 0" ng-include src="'plugins/sensors.html'"></section>
<section id="sensors" class="plugin table-row-group" ng-show="show.sensors && statsSensors.sensors.length > 0" ng-include src="'plugins/sensors.html'"></section>
</div>
</div>
<div class="col-sm-9">
<section id="containers" class="plugin" ng-if="result['docker']['containers'].length" ng-include src="'plugins/docker.html'"></section>
<section id="containers" class="plugin" ng-if="statsDocker.containers.length" ng-include src="'plugins/docker.html'"></section>
<section id="alerts" ng-show="show.alert" ng-include src="'plugins/alerts.html'"></section>
<section id="alert" class="plugin" ng-show="show.alert" ng-include src="'plugins/alert.html'"></section>
<section id="processcount" class="plugin" ng-include src="'plugins/processcount.html'"></section>
<div class="row">
<div class="col-lg-9">
<gl-monitor-list class="plugin" processes="result['monitor']"></gl-monitor-list>
<section id="monitor" class="plugin" ng-include src="'plugins/monitor.html'"></section>
</div>
</div>
<section id="processlist" class="plugin" ng-include src="'plugins/processlist.html'"></section>
......
......@@ -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
......@@ -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)
};
}
});
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);
});
});
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;
};
});
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();
}
});
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);
}
};
});
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'];
};
});
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();
};
});
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'];
};
});
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();
};
});
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();
};
});
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();
};
});
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;
}
});
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);
}
};
});
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);
};
});
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;
});
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'];
};
});
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);
};
});
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);
};
});
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';
};
});
glancesApp.service('GlancesPluginUptime', function() {
this.uptime = null;
this.setData = function(data, views) {
this.uptime = data['uptime'];
};
});
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
}
}
};
});
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册