Skip to content

Commit

Permalink
fix: handle None system metrics in user admin panel
Browse files Browse the repository at this point in the history
- Add default values for system metrics when None
- Add conditional system metrics display in template
- Show informative message when metrics unavailable

Closes #1028
  • Loading branch information
imprvhub committed Dec 19, 2024
1 parent 6c28d04 commit 2f825e2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,25 @@ <h5 class="card-title">Usage</h5>
<div class="card-body">
<h5>System</h5>
<p>Below is system metrics.</p>
<ul class="list-group">
<li class="list-group-item">Storage Total<span class="badge badge-light">{{ system_metrics.disk_total | filesizeformat(true) }}</span></li>
<li class="list-group-item">Storage Free<span class="badge badge-light">{{ system_metrics.disk_free | filesizeformat(true) }}</span></li>
<li class="list-group-item">Storage Used<span class="badge badge-light">{{ system_metrics.disk_usage | filesizeformat(true) }}</span></li>
</ul>

<div class="progress">
<div class="progress-bar" role="progressbar" style="width: {{ (system_metrics.disk_usage / system_metrics.disk_total * 100) | round | int }}%;" aria-valuenow="{{ (system_metrics.disk_usage / system_metrics.disk_total * 100) | round | int }}" aria-valuemin="0" aria-valuemax="100">{{ (system_metrics.disk_usage / system_metrics.disk_total * 100) | round | int }}%</div>
</div>
{% if system_metrics.disk_total == 0 %}
<div class="alert alert-info">
System metrics are not available yet. They will be populated once the conda-store worker starts.
</div>
{% else %}
<ul class="list-group">
<li class="list-group-item">Storage Total<span class="badge badge-light">{{ system_metrics.disk_total | filesizeformat(true) }}</span></li>
<li class="list-group-item">Storage Free<span class="badge badge-light">{{ system_metrics.disk_free | filesizeformat(true) }}</span></li>
<li class="list-group-item">Storage Used<span class="badge badge-light">{{ system_metrics.disk_usage | filesizeformat(true) }}</span></li>
</ul>

<div class="progress">
<div class="progress-bar" role="progressbar"
style="width: {{ (system_metrics.disk_usage / system_metrics.disk_total * 100) | round | int }}%;"
aria-valuenow="{{ (system_metrics.disk_usage / system_metrics.disk_total * 100) | round | int }}"
aria-valuemin="0"
aria-valuemax="100">{{ (system_metrics.disk_usage / system_metrics.disk_total * 100) | round | int }}%</div>
</div>
{% endif %}
</div>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,11 @@ async def ui_get_user(
entity, api.list_namespaces(db, show_soft_deleted=False)
)

system_metrics = api.get_system_metrics(db)
system_metrics = api.get_system_metrics(db) or {
"disk_total": 0,
"disk_free": 0,
"disk_usage": 0
}

namespace_usage_metrics = auth.filter_namespaces(
entity, api.get_namespace_metrics(db)
Expand Down

0 comments on commit 2f825e2

Please sign in to comment.