mirror of
https://github.com/prometheus-community/windows_exporter.git
synced 2026-10-21 20:19:05 +02:00
mscluster: use AllocatedSize for virtual disk storage efficiency (#2432)
Co-authored-by: EisenbergD <dominik.eisenberg@beiersdorf.com> Signed-off-by: EisenbergD <dominik.eisenberg@beiersdorf.com>
This commit is contained in:
co-authored by
EisenbergD
parent
e3089f0164
commit
70a1777422
@@ -34,6 +34,7 @@ type collectorVirtualDisk struct {
|
||||
virtualDiskInfo *prometheus.Desc
|
||||
virtualDiskHealthStatus *prometheus.Desc
|
||||
virtualDiskSize *prometheus.Desc
|
||||
virtualDiskAllocatedSize *prometheus.Desc
|
||||
virtualDiskFootprintOnPool *prometheus.Desc
|
||||
virtualDiskStorageEfficiency *prometheus.Desc
|
||||
}
|
||||
@@ -44,12 +45,13 @@ type msftVirtualDisk struct {
|
||||
UniqueId string `mi:"UniqueId"`
|
||||
HealthStatus uint16 `mi:"HealthStatus"`
|
||||
Size uint64 `mi:"Size"`
|
||||
AllocatedSize uint64 `mi:"AllocatedSize"`
|
||||
FootprintOnPool uint64 `mi:"FootprintOnPool"`
|
||||
// OperationalStatus []uint16 `mi:"OperationalStatus"` Not supported my mi query: https://github.com/prometheus-community/windows_exporter/pull/2296#issuecomment-3736584632
|
||||
}
|
||||
|
||||
func (c *Collector) buildVirtualDisk() error {
|
||||
wmiSelect := "FriendlyName,UniqueId,HealthStatus,Size,FootprintOnPool"
|
||||
wmiSelect := "FriendlyName,UniqueId,HealthStatus,Size,AllocatedSize,FootprintOnPool"
|
||||
|
||||
virtualDiskMIQuery, err := mi.NewQuery(fmt.Sprintf("SELECT %s FROM MSFT_VirtualDisk", wmiSelect))
|
||||
if err != nil {
|
||||
@@ -79,6 +81,13 @@ func (c *Collector) buildVirtualDisk() error {
|
||||
nil,
|
||||
)
|
||||
|
||||
c.virtualDiskAllocatedSize = prometheus.NewDesc(
|
||||
prometheus.BuildFQName(types.Namespace, nameVirtualDisk, "allocated_size_bytes"),
|
||||
"Allocated size of the virtual disk in bytes (data actually provisioned, excludes thin-provisioned unused capacity)",
|
||||
[]string{"name", "unique_id"},
|
||||
nil,
|
||||
)
|
||||
|
||||
c.virtualDiskFootprintOnPool = prometheus.NewDesc(
|
||||
prometheus.BuildFQName(types.Namespace, nameVirtualDisk, "footprint_on_pool_bytes"),
|
||||
"Physical storage consumed by the virtual disk on the storage pool in bytes",
|
||||
@@ -88,7 +97,7 @@ func (c *Collector) buildVirtualDisk() error {
|
||||
|
||||
c.virtualDiskStorageEfficiency = prometheus.NewDesc(
|
||||
prometheus.BuildFQName(types.Namespace, nameVirtualDisk, "storage_efficiency_percent"),
|
||||
"Storage efficiency percentage (Size / FootprintOnPool * 100)",
|
||||
"Storage efficiency percentage (AllocatedSize / FootprintOnPool * 100)",
|
||||
[]string{"name", "unique_id"},
|
||||
nil,
|
||||
)
|
||||
@@ -134,6 +143,14 @@ func (c *Collector) collectVirtualDisk(ch chan<- prometheus.Metric, maxScrapeDur
|
||||
vdisk.UniqueId,
|
||||
)
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.virtualDiskAllocatedSize,
|
||||
prometheus.GaugeValue,
|
||||
float64(vdisk.AllocatedSize),
|
||||
vdisk.FriendlyName,
|
||||
vdisk.UniqueId,
|
||||
)
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.virtualDiskFootprintOnPool,
|
||||
prometheus.GaugeValue,
|
||||
@@ -142,10 +159,14 @@ func (c *Collector) collectVirtualDisk(ch chan<- prometheus.Metric, maxScrapeDur
|
||||
vdisk.UniqueId,
|
||||
)
|
||||
|
||||
// Calculate storage efficiency (avoid division by zero)
|
||||
// Calculate storage efficiency (avoid division by zero).
|
||||
// AllocatedSize (not Size) is the correct numerator: Size is the
|
||||
// thin-provisioned ceiling, while AllocatedSize reflects the capacity
|
||||
// actually provisioned. Using Size inflates the ratio on thin-provisioned
|
||||
// disks (e.g. S2D FTT2 CSVs).
|
||||
var storageEfficiency float64
|
||||
if vdisk.FootprintOnPool > 0 {
|
||||
storageEfficiency = float64(vdisk.Size) / float64(vdisk.FootprintOnPool) * 100
|
||||
storageEfficiency = float64(vdisk.AllocatedSize) / float64(vdisk.FootprintOnPool) * 100
|
||||
} else {
|
||||
storageEfficiency = 0
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user