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 workload drawer history metrics targeting

rcourtman1943a1e97fb8
diff --git a/frontend-modern/browser-verification.json b/frontend-modern/browser-verification.json
index e31efaa432..44f3e4a921 100644
--- a/frontend-modern/browser-verification.json
+++ b/frontend-modern/browser-verification.json
@@ -1,23 +1,23 @@
{
"version": 1,
- "base_sha": "09b11719765180a2b7097748e20bc3862dbb3fa9",
- "verified_at": "2026-08-26T09:54:53Z",
+ "base_sha": "e27585b0a25bfcfc5b99d72f8dd3dcf7c668811e",
+ "verified_at": "2026-08-26T10:17:12Z",
"result": "passed",
"changed_paths": [
- "frontend-modern/src/constants/apiScopes.ts",
- "frontend-modern/src/components/Settings/apiTokenManagerModel.ts"
+ "frontend-modern/src/components/Workloads/guestDrawerModel.ts",
+ "frontend-modern/src/hooks/useWorkloads.ts",
+ "frontend-modern/src/types/workloads.ts"
],
"content_sha256": {
- "frontend-modern/src/constants/apiScopes.ts": "fd85effc73f4791390f96d7bcc03893abe688138fe616e5b039c5e01ae9160f6",
- "frontend-modern/src/components/Settings/apiTokenManagerModel.ts": "b1ec43891a5342da234604efecd8a32d1117c50a3ad8c00408181b3eef7006ed"
+ "frontend-modern/src/components/Workloads/guestDrawerModel.ts": "8cf63f54a06cd0d2d0a02fbec871c553dc61d31d82724efa4dfa737ddbd5745e",
+ "frontend-modern/src/hooks/useWorkloads.ts": "87d048e258d71d04087d76d3fb5a3fcf109d454beaed915d1992f50ab4996c94",
+ "frontend-modern/src/types/workloads.ts": "b10648f1bcc689e1cd078ae1ab8f9f0651a6fab6d0106c30f0eddc797d13c249"
},
- "routes": [
- "/settings/security/api"
- ],
+ "routes": ["/proxmox/overview"],
"viewports": [
{
- "width": 1440,
- "height": 1000
+ "width": 1280,
+ "height": 800
},
{
"width": 390,
@@ -25,19 +25,17 @@
}
],
"states": [
- "loaded API Access token creation and inventory surface",
- "expanded custom Agent scopes",
- "Agent quick preset selected",
- "generated Agent token inventory row",
- "opened in-place token scope editor",
- "loaded and exercised the scope picker at narrow mobile width"
+ "checkout-web-265 VM row filtered and expanded from the Proxmox guest table",
+ "24-hour History tab with utilization, network I/O, and disk I/O series rendered",
+ "1-hour History range loaded with the same three drawable chart groups",
+ "narrow History layout stacked vertically without page-level horizontal overflow",
+ "drawer collapsed with focus returned to the workload row toggle"
],
"interactions": [
- "opened Settings API Access in an isolated mock-backed development build",
- "expanded Custom scopes and confirmed Agent lifecycle management is selectable",
- "selected the Agent preset and confirmed agent:report, agent:config:read, and agent:manage are active while agent:exec remains opt-in",
- "generated an isolated replacement Agent token and confirmed all three lifecycle scopes appear on its inventory row",
- "opened Edit scopes and confirmed Agent lifecycle management is present and checked",
- "repeated the custom-scope and Agent-preset checks at 390x844 and confirmed all lifecycle choices remain reachable"
+ "signed into the current local build and filtered the Proxmox guest table to checkout-web-265",
+ "expanded checkout-web-265 and selected History at 1280 by 800; confirmed three chart groups, seven SVG paths, and zero Collecting history placeholders",
+ "switched the history selector from 24 hours to 1 hour and back; both ranges retained seven drawable SVG paths with no collection placeholder",
+ "rechecked the open History drawer at 390 by 844; confirmed the three charts stack vertically and the 390-pixel page has no horizontal overflow",
+ "restored the viewport override, collapsed checkout-web-265, and confirmed focus returned to the row expansion control"
]
}
diff --git a/frontend-modern/src/components/Workloads/__tests__/guestDrawerModel.branchcov2.test.ts b/frontend-modern/src/components/Workloads/__tests__/guestDrawerModel.branchcov2.test.ts
index f4e5d9bf9d..c0e1fbd806 100644
--- a/frontend-modern/src/components/Workloads/__tests__/guestDrawerModel.branchcov2.test.ts
+++ b/frontend-modern/src/components/Workloads/__tests__/guestDrawerModel.branchcov2.test.ts
@@ -355,6 +355,19 @@ describe('guestDrawerModel (branch coverage)', () => {
});
describe('getGuestDrawerHistoryTarget', () => {
+ it('prefers the backend metrics target over the workload row identity', () => {
+ expect(
+ getGuestDrawerHistoryTarget(
+ makeGuest({
+ id: 'cluster-a:pve1:101',
+ type: 'qemu',
+ workloadType: 'vm',
+ metricsTarget: { resourceType: 'vm', resourceId: 'mock-cluster-a-pve1-101' },
+ }),
+ ),
+ ).toStrictEqual({ resourceType: 'vm', resourceId: 'mock-cluster-a-pve1-101' });
+ });
+
it('returns null when the canonical id trims to empty', () => {
expect(
getGuestDrawerHistoryTarget(
diff --git a/frontend-modern/src/components/Workloads/guestDrawerModel.ts b/frontend-modern/src/components/Workloads/guestDrawerModel.ts
index 766c563e36..f37f96ba96 100644
--- a/frontend-modern/src/components/Workloads/guestDrawerModel.ts
+++ b/frontend-modern/src/components/Workloads/guestDrawerModel.ts
@@ -256,6 +256,12 @@ export const getGuestDrawerHistoryRangeBounds = (
};
export const getGuestDrawerHistoryTarget = (guest: Guest): GuestDrawerHistoryTarget | null => {
+ const explicitResourceType = guest.metricsTarget?.resourceType;
+ const explicitResourceId = guest.metricsTarget?.resourceId?.trim();
+ if (explicitResourceType && explicitResourceId) {
+ return { resourceType: explicitResourceType, resourceId: explicitResourceId };
+ }
+
const resourceId = getCanonicalWorkloadId(guest).trim();
if (!resourceId) return null;
diff --git a/frontend-modern/src/hooks/__tests__/useWorkloads.test.ts b/frontend-modern/src/hooks/__tests__/useWorkloads.test.ts
index c5917ea119..631e6bb388 100644
--- a/frontend-modern/src/hooks/__tests__/useWorkloads.test.ts
+++ b/frontend-modern/src/hooks/__tests__/useWorkloads.test.ts
@@ -239,7 +239,7 @@ describe('useWorkloads', () => {
platformType: 'proxmox-pve',
sources: ['proxmox'],
identity: { hostname: 'vm-101', ips: ['192.0.2.101'] },
- metricsTarget: { resourceId: 'cluster-a-pve1-101' },
+ metricsTarget: { resourceType: 'vm', resourceId: 'mock-cluster-a-pve1-101' },
canonicalIdentity: {
primaryId: 'vm:cluster-a-pve1-101',
aliases: ['legacy-vm-101'],
@@ -275,8 +275,10 @@ describe('useWorkloads', () => {
name: 'vm-101',
vmid: 101,
node: 'pve1',
+ metricsTarget: { resourceType: 'vm', resourceId: 'mock-cluster-a-pve1-101' },
alertResourceIds: expect.arrayContaining([
'cluster-a-pve1-101',
+ 'mock-cluster-a-pve1-101',
'vm:cluster-a-pve1-101',
'legacy-vm-101',
]),
diff --git a/frontend-modern/src/hooks/useWorkloads.ts b/frontend-modern/src/hooks/useWorkloads.ts
index cb1f34b074..cdf5caa270 100644
--- a/frontend-modern/src/hooks/useWorkloads.ts
+++ b/frontend-modern/src/hooks/useWorkloads.ts
@@ -25,6 +25,7 @@ import type {
ResourceAvailabilityMeta,
ResourceDiscoveryReadiness,
ResourceDiscoveryTarget,
+ ResourceMetricsTarget,
ResourceVMwareTag,
} from '@/types/resource';
@@ -71,9 +72,7 @@ type APIResource = {
lastSeen?: string;
sources?: string[];
platformScopes?: string[];
- metricsTarget?: {
- resourceId?: string;
- };
+ metricsTarget?: ResourceMetricsTarget;
canonicalIdentity?: {
primaryId?: string;
aliases?: string[];
@@ -523,6 +522,7 @@ const mapResourceToWorkload = (resource: APIResource): WorkloadGuest | null => {
return {
id: guestId,
alertResourceIds: buildAlertResourceIds(resource),
+ metricsTarget: resource.metricsTarget,
vmid: Number.isFinite(vmid) ? vmid : 0,
name: name || resource.id,
node,
diff --git a/frontend-modern/src/types/workloads.ts b/frontend-modern/src/types/workloads.ts
index 2e27d81829..bf079ab599 100644
--- a/frontend-modern/src/types/workloads.ts
+++ b/frontend-modern/src/types/workloads.ts
@@ -4,6 +4,7 @@ import type {
ResourceAvailabilityMeta,
ResourceDiscoveryReadiness,
ResourceDiscoveryTarget,
+ ResourceMetricsTarget,
} from './resource';
export type WorkloadType = 'vm' | 'system-container' | 'app-container' | 'pod';
@@ -23,6 +24,8 @@ export type WorkloadGuest = (VM | Container) & {
workloadType?: WorkloadType;
/** Backend identities that may own active alerts for this canonical workload. */
alertResourceIds?: string[];
+ /** Backend-owned coordinates for metrics history; distinct from the stable workload row id. */
+ metricsTarget?: ResourceMetricsTarget;
/** Canonical unified-resource health, kept separate from runtime power state in `status`. */
resourceStatus?: string;
displayId?: string;
diff --git a/internal/api/metrics_history_fallback_test.go b/internal/api/metrics_history_fallback_test.go
index f9296eaefa..1cc148fef8 100644
--- a/internal/api/metrics_history_fallback_test.go
+++ b/internal/api/metrics_history_fallback_test.go
@@ -167,6 +167,40 @@ func TestMetricsHistoryFallbackUsesLivePoint(t *testing.T) {
}
}
+func TestMetricsHistoryFallbackSynthesizesUnseededMockWorkloadHistory(t *testing.T) {
+ setMockModeForTest(t, true)
+
+ monitor := &monitoring.Monitor{}
+ setUnexportedField(t, monitor, "metricsHistory", monitoring.NewMetricsHistory(10, time.Hour))
+ router := &Router{monitor: monitor}
+
+ req := httptest.NewRequest(
+ http.MethodGet,
+ "/api/metrics-store/history?resourceType=vm&resourceId=mock-cluster-6-pve31-673&range=24h",
+ nil,
+ )
+ rec := httptest.NewRecorder()
+ router.handleMetricsHistory(rec, req)
+
+ if rec.Code != http.StatusOK {
+ t.Fatalf("expected status 200, got %d: %s", rec.Code, rec.Body.String())
+ }
+
+ var resp struct {
+ Source string `json:"source"`
+ Metrics map[string][]json.RawMessage `json:"metrics"`
+ }
+ if err := json.Unmarshal(rec.Body.Bytes(), &resp); err != nil {
+ t.Fatalf("failed to unmarshal response: %v", err)
+ }
+ if resp.Source != "mock_synthetic" {
+ t.Fatalf("expected source mock_synthetic, got %q", resp.Source)
+ }
+ if len(resp.Metrics["cpu"]) < 2 {
+ t.Fatalf("expected drawable mock CPU history, got %d points", len(resp.Metrics["cpu"]))
+ }
+}
+
func TestMetricsHistoryFallbackMockDiskSynthesizesSeries(t *testing.T) {
setMockModeForTest(t, true)
diff --git a/internal/api/router.go b/internal/api/router.go
index 9012be2b2a..93702391ce 100644
--- a/internal/api/router.go
+++ b/internal/api/router.go
@@ -6710,6 +6710,37 @@ func (r *Router) handleMetricsHistory(w http.ResponseWriter, req *http.Request)
return points
}
+ guestChartMetrics := func() (map[string][]monitoring.MetricPoint, bool) {
+ inMemoryKey := resourceID
+ sqlResourceType := ""
+ switch runtimeResourceType {
+ case "vm":
+ sqlResourceType = "vm"
+ case "system-container", "oci-container":
+ sqlResourceType = "container"
+ case "k8s":
+ sqlResourceType = "k8s"
+ case "docker-host":
+ inMemoryKey = fmt.Sprintf("dockerHost:%s", resourceID)
+ sqlResourceType = "dockerHost"
+ case "agent":
+ inMemoryKey = fmt.Sprintf("agent:%s", resourceID)
+ sqlResourceType = "agent"
+ case "app-container":
+ inMemoryKey = fmt.Sprintf("docker:%s", resourceID)
+ sqlResourceType = "dockerContainer"
+ default:
+ return nil, false
+ }
+ return monitor.GetGuestMetricsForChart(inMemoryKey, sqlResourceType, resourceID, duration), true
+ }
+ guestChartSource := func() string {
+ if mock.IsMockEnabled() {
+ return historySourceMock
+ }
+ return historySourceMemory
+ }
+
fallbackSingle := func() ([]map[string]interface{}, string, bool) {
if !fallbackAllowed || metricType == "" {
return nil, "", false
@@ -6738,7 +6769,7 @@ func (r *Router) handleMetricsHistory(w http.ResponseWriter, req *http.Request)
switch runtimeResourceType {
case "vm", "system-container", "oci-container":
- metrics := monitor.GetGuestMetrics(resourceID, duration)
+ metrics, _ := guestChartMetrics()
points := metrics[metricType]
if len(points) == 0 {
livePoints := liveMetricPoints(runtimeResourceType, resourceID)
@@ -6747,9 +6778,9 @@ func (r *Router) handleMetricsHistory(w http.ResponseWriter, req *http.Request)
}
return nil, "", false
}
- return buildHistoryPoints(points, stepSecs), historySourceMemory, true
+ return buildHistoryPoints(points, stepSecs), guestChartSource(), true
case "docker-host":
- metrics := monitor.GetGuestMetrics(fmt.Sprintf("dockerHost:%s", resourceID), duration)
+ metrics, _ := guestChartMetrics()
points := metrics[metricType]
if len(points) == 0 {
livePoints := liveMetricPoints(runtimeResourceType, resourceID)
@@ -6758,9 +6789,9 @@ func (r *Router) handleMetricsHistory(w http.ResponseWriter, req *http.Request)
}
return nil, "", false
}
- return buildHistoryPoints(points, stepSecs), historySourceMemory, true
+ return buildHistoryPoints(points, stepSecs), guestChartSource(), true
case "agent":
- metrics := monitor.GetGuestMetrics(fmt.Sprintf("agent:%s", resourceID), duration)
+ metrics, _ := guestChartMetrics()
points := metrics[metricType]
if len(points) == 0 {
points = monitor.GetNodeMetrics(resourceID, metricType, duration)
@@ -6772,9 +6803,9 @@ func (r *Router) handleMetricsHistory(w http.ResponseWriter, req *http.Request)
}
return nil, "", false
}
- return buildHistoryPoints(points, stepSecs), historySourceMemory, true
+ return buildHistoryPoints(points, stepSecs), guestChartSource(), true
case "app-container":
- metrics := monitor.GetGuestMetrics(fmt.Sprintf("docker:%s", resourceID), duration)
+ metrics, _ := guestChartMetrics()
points := metrics[metricType]
if len(points) == 0 {
livePoints := liveMetricPoints(runtimeResourceType, resourceID)
@@ -6783,9 +6814,9 @@ func (r *Router) handleMetricsHistory(w http.ResponseWriter, req *http.Request)
}
return nil, "", false
}
- return buildHistoryPoints(points, stepSecs), historySourceMemory, true
+ return buildHistoryPoints(points, stepSecs), guestChartSource(), true
case "k8s":
- metrics := monitor.GetGuestMetrics(resourceID, duration)
+ metrics, _ := guestChartMetrics()
points := metrics[metricType]
if len(points) == 0 {
livePoints := liveMetricPoints(runtimeResourceType, resourceID)
@@ -6794,7 +6825,7 @@ func (r *Router) handleMetricsHistory(w http.ResponseWriter, req *http.Request)
}
return nil, "", false
}
- return buildHistoryPoints(points, stepSecs), historySourceMemory, true
+ return buildHistoryPoints(points, stepSecs), guestChartSource(), true
case "node":
points := monitor.GetNodeMetrics(resourceID, metricType, duration)
if len(points) == 0 {
@@ -6841,15 +6872,12 @@ func (r *Router) handleMetricsHistory(w http.ResponseWriter, req *http.Request)
}
var metrics map[string][]monitoring.MetricPoint
+ guestHistory := false
switch runtimeResourceType {
- case "vm", "system-container", "oci-container":
- metrics = monitor.GetGuestMetrics(resourceID, duration)
- case "k8s":
- metrics = monitor.GetGuestMetrics(resourceID, duration)
- case "docker-host":
- metrics = monitor.GetGuestMetrics(fmt.Sprintf("dockerHost:%s", resourceID), duration)
+ case "vm", "system-container", "oci-container", "k8s", "docker-host":
+ metrics, guestHistory = guestChartMetrics()
case "agent":
- metrics = monitor.GetGuestMetrics(fmt.Sprintf("agent:%s", resourceID), duration)
+ metrics, guestHistory = guestChartMetrics()
if len(metrics) == 0 {
metrics = map[string][]monitoring.MetricPoint{
"cpu": monitor.GetNodeMetrics(resourceID, "cpu", duration),
@@ -6858,7 +6886,7 @@ func (r *Router) handleMetricsHistory(w http.ResponseWriter, req *http.Request)
}
}
case "app-container":
- metrics = monitor.GetGuestMetrics(fmt.Sprintf("docker:%s", resourceID), duration)
+ metrics, guestHistory = guestChartMetrics()
case "storage":
metrics = monitor.GetStorageMetrics(resourceID, duration)
case "disk":
@@ -6882,6 +6910,9 @@ func (r *Router) handleMetricsHistory(w http.ResponseWriter, req *http.Request)
apiData := make(map[string][]map[string]interface{})
source := historySourceMemory
+ if guestHistory {
+ source = guestChartSource()
+ }
for metric, points := range metrics {
if len(points) == 0 {
continue