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.
Go aialertsdashboarddockerdocker-monitoringgohomelabinfrastructure-monitoringkubernetesmonitoringmspproxmoxproxmox-backup-serverproxmox-mail-gatewayproxmox-veself-hostedtruenastypescriptvspherewebhooks
Propagate PBS datastore health into monitoring
rcourtman6e9c36030135
diff --git a/internal/monitoring/monitor_pbs_coverage_test.go b/internal/monitoring/monitor_pbs_coverage_test.goindex d5a6a5c1b1..797b3143c8 100644--- a/internal/monitoring/monitor_pbs_coverage_test.go+++ b/internal/monitoring/monitor_pbs_coverage_test.go@@ -102,6 +102,7 @@ func TestMonitor_PollPBSInstance_DatastoreDetails(t *testing.T) {"data": []map[string]interface{}{{"store": "ds1", "comment": "comment1"}, // GetDatastores list returns small subset of fields{"store": "ds2", "comment": "comment2"},+ {"store": "ds-error", "comment": "status failure"},},})return@@ -113,7 +114,10 @@ func TestMonitor_PollPBSInstance_DatastoreDetails(t *testing.T) {if strings.Contains(r.URL.Path, "ds1") {data = map[string]interface{}{"total": 100.0, "used": 50.0, "avail": 50.0}} else if strings.Contains(r.URL.Path, "ds2") {- data = map[string]interface{}{"total-space": 200.0, "used-space": 100.0, "avail-space": 100.0, "deduplication-factor": 1.5}+ data = map[string]interface{}{"total-space": 200.0, "used-space": 100.0, "avail-space": 100.0, "deduplication-factor": 1.5, "status": "read_only"}+ } else if strings.Contains(r.URL.Path, "ds-error") {+ http.Error(w, "datastore unavailable", http.StatusInternalServerError)+ return}json.NewEncoder(w).Encode(map[string]interface{}{"data": data})return@@ -190,29 +194,46 @@ func TestMonitor_PollPBSInstance_DatastoreDetails(t *testing.T) {t.Fatal("Instance not found")}- if len(inst.Datastores) != 2 {- t.Errorf("Expected 2 datastores, got %d", len(inst.Datastores))+ if len(inst.Datastores) != 3 {+ t.Errorf("Expected 3 datastores, got %d", len(inst.Datastores))}- // Check DS2 size calculation+ // Check DS2 size calculation and status propagation.var ds2 *models.PBSDatastore+ var dsError *models.PBSDatastorefor _, ds := range inst.Datastores {if ds.Name == "ds2" {copy := dsds2 = ©- break+ }+ if ds.Name == "ds-error" {+ copy := ds+ dsError = ©}}if ds2 != nil {if ds2.Total != 200 {t.Errorf("Expected DS2 total 200, got %d", ds2.Total)}+ if ds2.Status != "read_only" {+ t.Errorf("Expected DS2 status read_only, got %q", ds2.Status)+ }if len(ds2.Namespaces) != 4 {t.Errorf("Expected 4 namespaces for DS2, got %d", len(ds2.Namespaces))}} else {t.Error("DS2 not found")}+ if dsError == nil {+ t.Error("ds-error not found")+ } else {+ if dsError.Status != "unavailable" {+ t.Errorf("Expected ds-error status unavailable, got %q", dsError.Status)+ }+ if !strings.Contains(dsError.Error, "Failed to get status") {+ t.Errorf("Expected ds-error to preserve status error, got %q", dsError.Error)+ }+ }}// TestPBSAndPMGPollSkipDisabledInstances asserts that the PBS and PMG polldiff --git a/internal/monitoring/monitor_pbs_pmg.go b/internal/monitoring/monitor_pbs_pmg.goindex b16958bc2a..37344d12cf 100644--- a/internal/monitoring/monitor_pbs_pmg.go+++ b/internal/monitoring/monitor_pbs_pmg.go@@ -63,6 +63,17 @@ func matchesDatastoreExclude(datastoreName string, excludePatterns []string) booreturn false}+func pbsDatastoreStatus(ds pbs.Datastore) string {+ status := strings.TrimSpace(ds.Status)+ if status != "" {+ return status+ }+ if strings.TrimSpace(ds.Error) != "" {+ return "unavailable"+ }+ return "available"+}+// pollPBSInstance polls a single PBS instancefunc (m *Monitor) pollPBSInstance(ctx context.Context, instanceName string, client *pbs.Client) {defer recoverFromPanic(fmt.Sprintf("pollPBSInstance-%s", instanceName))@@ -274,7 +285,8 @@ func (m *Monitor) pollPBSInstance(ctx context.Context, instanceName string, clieUsed: used,Free: avail,Usage: safePercentage(float64(used), float64(total)),- Status: "available",+ Status: pbsDatastoreStatus(ds),+ Error: ds.Error,DeduplicationFactor: ds.DeduplicationFactor,}diff --git a/pkg/pbs/client.go b/pkg/pbs/client.goindex e89eef1f3c..2d523d528d 100644--- a/pkg/pbs/client.go+++ b/pkg/pbs/client.go@@ -578,6 +578,7 @@ type Datastore struct {UsedSpace int64 `json:"used-space,omitempty"`AvailSpace int64 `json:"avail-space,omitempty"`// Status fields+ Status string `json:"status,omitempty"`GCStatus string `json:"gc-status,omitempty"`DeduplicationFactor float64 `json:"deduplication_factor,omitempty"`Error string `json:"error,omitempty"`@@ -747,8 +748,9 @@ func (c *Client) GetDatastores(ctx context.Context) ([]Datastore, error) {log.Error().Str("store", ds.Store).Err(err).Msg("Failed to get datastore status")// Create entry with no size info if status failsdatastores = append(datastores, Datastore{- Store: ds.Store,- Error: fmt.Sprintf("Failed to get status: %v", err),+ Store: ds.Store,+ Status: "unavailable",+ Error: fmt.Sprintf("Failed to get status: %v", err),})continue}@@ -758,8 +760,9 @@ func (c *Client) GetDatastores(ctx context.Context) ([]Datastore, error) {if err != nil {log.Error().Str("store", ds.Store).Err(err).Msg("Failed to read datastore status response")datastores = append(datastores, Datastore{- Store: ds.Store,- Error: fmt.Sprintf("Failed to read status: %v", err),+ Store: ds.Store,+ Status: "unavailable",+ Error: fmt.Sprintf("Failed to read status: %v", err),})continue}@@ -775,8 +778,9 @@ func (c *Client) GetDatastores(ctx context.Context) ([]Datastore, error) {Err(err).Msg("Failed to parse datastore status")datastores = append(datastores, Datastore{- Store: ds.Store,- Error: fmt.Sprintf("Failed to parse status: %v", err),+ Store: ds.Store,+ Status: "unavailable",+ Error: fmt.Sprintf("Failed to parse status: %v", err),})continue}@@ -797,6 +801,12 @@ func (c *Client) GetDatastores(ctx context.Context) ([]Datastore, error) {dedupFactor = df}+ status := "available"+ if rawStatus, ok := statusResult.Data["status"].(string); ok && strings.TrimSpace(rawStatus) != "" {+ status = strings.TrimSpace(rawStatus)+ }+ gcStatus, _ := statusResult.Data["gc-status"].(string)+// If still no dedup factor, try gc-status endpointif dedupFactor == 0 {gcResp, err := c.get(ctx, fmt.Sprintf("/admin/datastore/%s/gc", ds.Store))@@ -837,6 +847,8 @@ func (c *Client) GetDatastores(ctx context.Context) ([]Datastore, error) {TotalSpace: int64(totalSpace),UsedSpace: int64(usedSpace),AvailSpace: int64(availSpace),+ Status: status,+ GCStatus: strings.TrimSpace(gcStatus),DeduplicationFactor: dedupFactor,}diff --git a/pkg/pbs/client_full_coverage_test.go b/pkg/pbs/client_full_coverage_test.goindex 209df5dcd6..4e2c1b6c83 100644--- a/pkg/pbs/client_full_coverage_test.go+++ b/pkg/pbs/client_full_coverage_test.go@@ -470,9 +470,10 @@ func TestClient_GetDatastores_Full(t *testing.T) {if r.URL.Path == "/api2/json/admin/datastore/store1/status" {json.NewEncoder(w).Encode(map[string]any{"data": map[string]any{- "total": 1000.0,- "used": 200.0,- "avail": 800.0,+ "total": 1000.0,+ "used": 200.0,+ "avail": 800.0,+ "status": "read_only",},})return@@ -522,6 +523,9 @@ func TestClient_GetDatastores_Full(t *testing.T) {if dss[0].DeduplicationFactor != 2.5 {t.Errorf("Expected store1 dedup 2.5, got %f", dss[0].DeduplicationFactor)}+ if dss[0].Status != "read_only" {+ t.Errorf("Expected store1 status read_only, got %q", dss[0].Status)+ }// Check store2 (GC dedup: 300/100 = 3.0)if dss[1].Store != "store2" {@@ -787,6 +791,12 @@ func TestClient_GetDatastores_PartialErrors(t *testing.T) {if !strings.Contains(dss[1].Error, "get status") {t.Errorf("Expected get status error for store2, got field: %v", dss[1].Error)}+ if dss[0].Status != "unavailable" {+ t.Errorf("Expected unavailable status for store1, got %q", dss[0].Status)+ }+ if dss[1].Status != "unavailable" {+ t.Errorf("Expected unavailable status for store2, got %q", dss[1].Status)+ }}func TestClient_Request_Reauthentication(t *testing.T) {diff --git a/pkg/pbs/client_test.go b/pkg/pbs/client_test.goindex 53f43fb381..53f91dbde7 100644--- a/pkg/pbs/client_test.go+++ b/pkg/pbs/client_test.go@@ -218,6 +218,7 @@ func TestDatastore_Fields(t *testing.T) {Used: 500000000000,Avail: 500000000000,DeduplicationFactor: 1.5,+ Status: "available",GCStatus: "ok",Error: "",}@@ -237,6 +238,9 @@ func TestDatastore_Fields(t *testing.T) {if ds.DeduplicationFactor != 1.5 {t.Errorf("DeduplicationFactor = %f, want 1.5", ds.DeduplicationFactor)}+ if ds.Status != "available" {+ t.Errorf("Status = %q, want available", ds.Status)+ }}func TestVersion_Fields(t *testing.T) {