Merge branch 'tweak/dashboard-storage' into 'dev'

Fix traceback for users without disks

See merge request crafty-controller/crafty-4!571
This commit is contained in:
Iain Powrie 2023-04-01 13:52:12 +00:00
commit 50eb948441
3 changed files with 25 additions and 19 deletions

View File

@ -3,7 +3,7 @@
### New features ### New features
TBD TBD
### Bug fixes ### Bug fixes
TBD - Fix dashboard crash for users without disks or if crafty doesn't have permission to access mount point ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/571))
### Tweaks ### Tweaks
- Improve logging on tz failures ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/569)) - Improve logging on tz failures ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/569))
- Add fallback for ping domain to provide better feedback on internet connection ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/570)) - Add fallback for ping domain to provide better feedback on internet connection ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/570))

View File

@ -191,6 +191,7 @@ class Stats:
# ENOENT, pop-up a Windows GUI error for a non-ready # ENOENT, pop-up a Windows GUI error for a non-ready
# partition or just hang. # partition or just hang.
continue continue
try:
usage = psutil.disk_usage(part.mountpoint) usage = psutil.disk_usage(part.mountpoint)
disk_data.append( disk_data.append(
{ {
@ -206,6 +207,9 @@ class Stats:
"mount": part.mountpoint, "mount": part.mountpoint,
} }
) )
except PermissionError:
logger.debug(f"Permission error accessing {part.mountpoint}")
continue
return disk_data return disk_data

View File

@ -100,6 +100,7 @@
</div> </div>
</div> </div>
</div> </div>
{% if len(data['hosts_data']['disk_json']) > 0 %}
<div class="col-12 mt-4"> <div class="col-12 mt-4">
<div class="d-flex"> <div class="d-flex">
<div class="wrapper" style="width: 100%;"> <div class="wrapper" style="width: 100%;">
@ -107,7 +108,7 @@
</h5> </h5>
<div id="storage_data"> <div id="storage_data">
<div class="row"> <div class="row">
{% for item in data.get('hosts_data').get('disk_json') %} {% for item in data['hosts_data']['disk_json'] %}
{% if item["mount"] in data["monitored"] %} {% if item["mount"] in data["monitored"] %}
<div id="{{item['device']}}" class="col-xl-3 col-lg-3 col-md-4 col-12"> <div id="{{item['device']}}" class="col-xl-3 col-lg-3 col-md-4 col-12">
<h4 class="mb-0 font-weight-semibold d-inline-block text-truncate storage-heading" <h4 class="mb-0 font-weight-semibold d-inline-block text-truncate storage-heading"
@ -137,6 +138,7 @@
</div> </div>
</div> </div>
</div> </div>
{% end %}
</div> </div>
</div> </div>
</div> </div>
@ -931,8 +933,8 @@
var storage_html = '<div class="row">'; var storage_html = '<div class="row">';
for (i = 0; i < hostStats.disk_usage.length; i++) { for (i = 0; i < hostStats.disk_usage.length; i++) {
if (hostStats.mounts.includes(hostStats.disk_usage[i].mount)) { if (hostStats.mounts.includes(hostStats.disk_usage[i].mount)) {
storage_html += `<div id="{{item['device']}}" class="col-xl-3 col-lg-3 col-md-4 col-12"> storage_html += `<div id="host_storage" class="col-xl-3 col-lg-3 col-md-4 col-12">
<h4 class="mb-0 font-weight-semibold d-inline-block text-truncate storage-heading" id="title_{{item['device']}}" data-toggle="tooltip" data-placement="bottom" title="${hostStats.disk_usage[i].mount}" style="max-width: 100%;"><i class="fas fa-hdd"></i> ${hostStats.disk_usage[i].mount}</h4> <h4 class="mb-0 font-weight-semibold d-inline-block text-truncate storage-heading" id="title_host_storage" data-toggle="tooltip" data-placement="bottom" title="${hostStats.disk_usage[i].mount}" style="max-width: 100%;"><i class="fas fa-hdd"></i> ${hostStats.disk_usage[i].mount}</h4>
<div class="progress" style="display: inline-block; height: 20px; width: 100%; background-color: rgb(139, 139, 139) !important;"> <div class="progress" style="display: inline-block; height: 20px; width: 100%; background-color: rgb(139, 139, 139) !important;">
<div class="progress-bar`; <div class="progress-bar`;
if (hostStats.disk_usage[i].percent_used <= 58) { if (hostStats.disk_usage[i].percent_used <= 58) {