Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

fix(frontend): memory tooltip Used label tracks bar severity color

rcourtman1685358872ee
diff --git a/frontend-modern/src/components/Workloads/__tests__/stackedMemoryBarModel.test.ts b/frontend-modern/src/components/Workloads/__tests__/stackedMemoryBarModel.test.ts
index be61885d98..b4b961a5dd 100644
--- a/frontend-modern/src/components/Workloads/__tests__/stackedMemoryBarModel.test.ts
+++ b/frontend-modern/src/components/Workloads/__tests__/stackedMemoryBarModel.test.ts
@@ -61,6 +61,29 @@ describe('buildStackedMemoryBarPresentation', () => {
expect(rows['Free']).toBe('2.00 GB');
});
+ it('colors the Used tooltip label with the same severity as the bar segment', () => {
+ const normal = buildStackedMemoryBarPresentation(
+ { used: 4 * GiB, total: 16 * GiB, cache: 6 * GiB },
+ 400,
+ );
+ expect(normal.tooltipRows[0].label).toBe('Used');
+ expect(normal.tooltipRows[0].labelClass).toBe('text-green-400');
+
+ // 80% used trips the default memory warning threshold (75), so the used
+ // segment renders yellow and the legend must not claim green.
+ const warning = buildStackedMemoryBarPresentation(
+ { used: 12.8 * GiB, total: 16 * GiB, cache: 3.2 * GiB },
+ 400,
+ );
+ expect(warning.tooltipRows[0].labelClass).toBe('text-yellow-400');
+
+ const critical = buildStackedMemoryBarPresentation(
+ { used: 14 * GiB, total: 16 * GiB, cache: 2 * GiB },
+ 400,
+ );
+ expect(critical.tooltipRows[0].labelClass).toBe('text-red-400');
+ });
+
it('matches the pre-cache layout when no cache is reported', () => {
const presentation = buildStackedMemoryBarPresentation(
{ used: 4 * GiB, total: 16 * GiB },
diff --git a/frontend-modern/src/components/Workloads/stackedMemoryBarModel.ts b/frontend-modern/src/components/Workloads/stackedMemoryBarModel.ts
index 51af923a37..06e1970118 100644
--- a/frontend-modern/src/components/Workloads/stackedMemoryBarModel.ts
+++ b/frontend-modern/src/components/Workloads/stackedMemoryBarModel.ts
@@ -6,8 +6,8 @@ import {
formatBytes,
formatPercent,
} from '@/utils/format';
-import { getMetricColorRgba } from '@/utils/metricThresholds';
-import type { MetricDisplayThresholds } from '@/utils/metricThresholds';
+import { getMetricColorRgba, getMetricSeverity } from '@/utils/metricThresholds';
+import type { MetricDisplayThresholds, MetricSeverity } from '@/utils/metricThresholds';
export interface StackedMemoryBarProps {
used: number;
@@ -53,6 +53,14 @@ export interface StackedMemoryBarPresentation {
tooltipTitle: string;
}
+// Tooltip legend for the used segment tracks the same severity that colors
+// the bar, so the legend never claims green while the bar shows warning/red.
+const USED_LABEL_CLASS: Record<MetricSeverity, string> = {
+ normal: 'text-green-400',
+ warning: 'text-yellow-400',
+ critical: 'text-red-400',
+};
+
const MEMORY_COLORS = {
active: 'rgba(34, 197, 94, 0.6)',
// Muted amber: reclaimable buff/cache, matching the v5 segment tone.
@@ -154,10 +162,11 @@ function getTooltipRows(
const hasSwap = (props.swapTotal || 0) > 0;
if (props.total > 0) {
+ const usedPercent = (props.used / props.total) * 100;
rows.push({
borderTop: false,
label: 'Used',
- labelClass: 'text-green-400',
+ labelClass: USED_LABEL_CLASS[getMetricSeverity(usedPercent, 'memory', props.thresholds)],
value: formatBytes(props.used),
});