diff --git a/metrics/pve_node_storage_collector.go b/metrics/pve_node_storage_collector.go index 040b5cc..b1779db 100644 --- a/metrics/pve_node_storage_collector.go +++ b/metrics/pve_node_storage_collector.go @@ -85,7 +85,7 @@ func (c *PveStorageCollector) CollectMetrics() error { "node": node.Name, "storage": storage.Storage, "type": storage.Type, - "content": storage.Content, + "content": storage.GetContentSorted(), "shared": strconv.Itoa(storage.Shared), } diff --git a/proxmox/model.go b/proxmox/model.go index 96006d2..1494df5 100644 --- a/proxmox/model.go +++ b/proxmox/model.go @@ -3,6 +3,8 @@ package proxmox import ( "errors" "fmt" + "sort" + "strings" ) // PveVersion represents the version information of a PVE (Proxmox Virtual Environment). @@ -492,3 +494,11 @@ func (r *PveClusterStatus) GetClusterName() string { } return r.Name } + +// GetContentSorted returns sorted storage content. +// This is crucial for labeling because PVE API returns these walues randomly sorted. +func (r *PveStorage) GetContentSorted() string { + parts := strings.Split(r.Content, ",") + sort.Strings(parts) + return strings.Join(parts, ",") +}