From 71327bcbf1525383b676f936d4ff0725b93b9b87 Mon Sep 17 00:00:00 2001 From: kqjy Date: Thu, 22 Jan 2026 11:06:53 +0800 Subject: [PATCH] Add dynamic updates to System Health section on metrics page --- templates/metrics.html | 81 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 66 insertions(+), 15 deletions(-) diff --git a/templates/metrics.html b/templates/metrics.html index f108213..6425531 100644 --- a/templates/metrics.html +++ b/templates/metrics.html @@ -218,10 +218,10 @@
{% set has_issues = (cpu_percent > 80) or (memory.percent > 85) or (disk.percent > 90) %} -
+
- + {% if has_issues %} @@ -232,8 +232,8 @@
- - + + {% if has_issues %} {% else %} @@ -244,22 +244,24 @@

System Health

- {% if has_issues %} -
    - {% if cpu_percent > 80 %}
  • CPU usage is high ({{ cpu_percent }}%)
  • {% endif %} - {% if memory.percent > 85 %}
  • Memory usage is high ({{ memory.percent }}%)
  • {% endif %} - {% if disk.percent > 90 %}
  • Disk space is critically low ({{ disk.percent }}% used)
  • {% endif %} -
- {% else %} -

All resources are within normal operating parameters.

- {% endif %} +
+ {% if has_issues %} +
    + {% if cpu_percent > 80 %}
  • CPU usage is high ({{ cpu_percent }}%)
  • {% endif %} + {% if memory.percent > 85 %}
  • Memory usage is high ({{ memory.percent }}%)
  • {% endif %} + {% if disk.percent > 90 %}
  • Disk space is critically low ({{ disk.percent }}% used)
  • {% endif %} +
+ {% else %} +

All resources are within normal operating parameters.

+ {% endif %} +
-
{{ app.uptime_days }}d
+
{{ app.uptime_days }}d
Uptime
-
{{ app.buckets }}
+
{{ app.buckets }}
Active Buckets
@@ -480,6 +482,55 @@ el = document.querySelector('[data-metric="objects_count"]'); if (el) el.textContent = data.app.objects; + var cpuHigh = data.cpu_percent > 80; + var memHigh = data.memory.percent > 85; + var diskHigh = data.disk.percent > 90; + var hasIssues = cpuHigh || memHigh || diskHigh; + + var healthCard = document.getElementById('systemHealthCard'); + if (healthCard) { + healthCard.style.background = hasIssues + ? 'linear-gradient(135deg, #ef4444 0%, #f97316 100%)' + : 'linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%)'; + } + + var healthIcon = document.getElementById('healthIcon'); + if (healthIcon) { + healthIcon.innerHTML = hasIssues + ? '' + : ''; + } + + var healthBadge = document.getElementById('healthBadge'); + if (healthBadge) { + healthBadge.className = 'badge bg-white fw-semibold px-3 py-2 ' + (hasIssues ? 'text-danger' : 'text-primary'); + } + + var healthBadgeIcon = document.getElementById('healthBadgeIcon'); + if (healthBadgeIcon) { + healthBadgeIcon.innerHTML = hasIssues + ? '' + : ''; + } + + var healthContent = document.getElementById('healthContent'); + if (healthContent) { + if (hasIssues) { + var issues = []; + if (cpuHigh) issues.push('
  • CPU usage is high (' + data.cpu_percent.toFixed(1) + '%)
  • '); + if (memHigh) issues.push('
  • Memory usage is high (' + data.memory.percent.toFixed(1) + '%)
  • '); + if (diskHigh) issues.push('
  • Disk space is critically low (' + data.disk.percent.toFixed(1) + '% used)
  • '); + healthContent.innerHTML = '
      ' + issues.join('') + '
    '; + } else { + healthContent.innerHTML = '

    All resources are within normal operating parameters.

    '; + } + } + + el = document.querySelector('[data-metric="health_uptime"]'); + if (el) el.textContent = data.app.uptime_days + 'd'; + el = document.querySelector('[data-metric="health_buckets"]'); + if (el) el.textContent = data.app.buckets; + countdown = 5; }) .catch(function(err) {