From 09ec6e68adb9ad54869be9ab79a36f0f90a3a758 Mon Sep 17 00:00:00 2001 From: Andrew Banman Date: Fri, 8 Apr 2022 09:01:06 -0700 Subject: [PATCH 1/7] Add Hyper-V VM Memory metrics Signed-off-by: Andrew Banman --- collector/hyperv.go | 181 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 181 insertions(+) diff --git a/collector/hyperv.go b/collector/hyperv.go index 1ec29995..309e96d7 100644 --- a/collector/hyperv.go +++ b/collector/hyperv.go @@ -111,6 +111,18 @@ type HyperVCollector struct { VMNetworkDroppedPacketsOutgoing *prometheus.Desc VMNetworkPacketsReceived *prometheus.Desc VMNetworkPacketsSent *prometheus.Desc + + // Win32_PerfRawData_BalancerStats_HyperVDynamicMemoryVM + VMMemoryAddedMemory *prometheus.Desc + VMMemoryAveragePressure *prometheus.Desc + VMMemoryCurrentPressure *prometheus.Desc + VMMemoryGuestVisiblePhysicalMemory *prometheus.Desc + VMMemoryMaximumPressure *prometheus.Desc + VMMemoryMemoryAddOperations *prometheus.Desc + VMMemoryMemoryRemoveOperations *prometheus.Desc + VMMemoryMinimumPressure *prometheus.Desc + VMMemoryPhysicalMemory *prometheus.Desc + VMMemoryRemovedMemory *prometheus.Desc } // NewHyperVCollector ... @@ -593,6 +605,69 @@ func NewHyperVCollector() (Collector, error) { []string{"vm_interface"}, nil, ), + + // + + VMMemoryAddedMemory: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, buildSubsystemName("vm_memory"), "added"), + "", + []string{"vm"}, + nil, + ), + VMMemoryAveragePressure: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, buildSubsystemName("vm_memory"), "pressure_average"), + "This counter represents the average pressure in the VM.", + []string{"vm"}, + nil, + ), + VMMemoryCurrentPressure: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, buildSubsystemName("vm_memory"), "pressure_current"), + "This counter represents the current pressure in the VM.", + []string{"vm"}, + nil, + ), + VMMemoryGuestVisiblePhysicalMemory: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, buildSubsystemName("vm_memory"), "physical_guest_visible"), + "'This counter represents the amount of memory visible in the VM.'", + []string{"vm"}, + nil, + ), + VMMemoryMaximumPressure: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, buildSubsystemName("vm_memory"), "pressure_maximum"), + "This counter represents the maximum pressure band in the VM.", + []string{"vm"}, + nil, + ), + VMMemoryMemoryAddOperations: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, buildSubsystemName("vm_memory"), "add_operations"), + "", + []string{"vm"}, + nil, + ), + VMMemoryMemoryRemoveOperations: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, buildSubsystemName("vm_memory"), "remove_operations"), + "", + []string{"vm"}, + nil, + ), + VMMemoryMinimumPressure: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, buildSubsystemName("vm_memory"), "pressure_minimum"), + "This counter represents the minmum pressure band in the VM.", + []string{"vm"}, + nil, + ), + VMMemoryPhysicalMemory: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, buildSubsystemName("vm_memory"), "physical_memory"), + "This counter represents the current amount of memory in the VM.", + []string{"vm"}, + nil, + ), + VMMemoryRemovedMemory: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, buildSubsystemName("vm_memory"), "removed"), + "", + []string{"vm"}, + nil, + ), }, nil } @@ -649,6 +724,11 @@ func (c *HyperVCollector) Collect(ctx *ScrapeContext, ch chan<- prometheus.Metri return err } + if desc, err := c.collectVmMemory(ch); err != nil { + log.Error("failed collecting hyperV virtual memory metrics:", desc, err) + return err + } + return nil } @@ -1431,3 +1511,104 @@ func (c *HyperVCollector) collectVmNetwork(ch chan<- prometheus.Metric) (*promet return nil, nil } + +// Win32_PerfRawData_BalancerStats_HyperVDynamicMemoryVM ... +type Win32_PerfRawData_BalancerStats_HyperVDynamicMemoryVM struct { + Name string + AddedMemory uint64 + AveragePressure uint64 + CurrentPressure uint64 + GuestVisiblePhysicalMemory uint64 + MaximumPressure uint64 + MemoryAddOperations uint64 + MemoryRemoveOperations uint64 + MinimumPressure uint64 + PhysicalMemory uint64 + RemovedMemory uint64 +} + +func (c *HyperVCollector) collectVmMemory(ch chan<- prometheus.Metric) (*prometheus.Desc, error) { + var dst []Win32_PerfRawData_BalancerStats_HyperVDynamicMemoryVM + q := queryAll(&dst) + if err := wmi.Query(q, &dst); err != nil { + return nil, err + } + + for _, obj := range dst { + if strings.Contains(obj.Name, "_Total") { + continue + } + + ch <- prometheus.MustNewConstMetric( + c.VMMemoryAddedMemory, + prometheus.CounterValue, + float64(obj.AddedMemory), + obj.Name, + ) + + ch <- prometheus.MustNewConstMetric( + c.VMMemoryAveragePressure, + prometheus.CounterValue, + float64(obj.AveragePressure), + obj.Name, + ) + + ch <- prometheus.MustNewConstMetric( + c.VMMemoryCurrentPressure, + prometheus.CounterValue, + float64(obj.CurrentPressure), + obj.Name, + ) + + ch <- prometheus.MustNewConstMetric( + c.VMMemoryGuestVisiblePhysicalMemory, + prometheus.CounterValue, + float64(obj.GuestVisiblePhysicalMemory), + obj.Name, + ) + + ch <- prometheus.MustNewConstMetric( + c.VMMemoryMaximumPressure, + prometheus.CounterValue, + float64(obj.MaximumPressure), + obj.Name, + ) + + ch <- prometheus.MustNewConstMetric( + c.VMMemoryMemoryAddOperations, + prometheus.CounterValue, + float64(obj.MemoryAddOperations), + obj.Name, + ) + + ch <- prometheus.MustNewConstMetric( + c.VMMemoryMemoryRemoveOperations, + prometheus.CounterValue, + float64(obj.MemoryRemoveOperations), + obj.Name, + ) + + ch <- prometheus.MustNewConstMetric( + c.VMMemoryMinimumPressure, + prometheus.CounterValue, + float64(obj.MinimumPressure), + obj.Name, + ) + + ch <- prometheus.MustNewConstMetric( + c.VMMemoryPhysicalMemory, + prometheus.CounterValue, + float64(obj.PhysicalMemory), + obj.Name, + ) + + ch <- prometheus.MustNewConstMetric( + c.VMMemoryRemovedMemory, + prometheus.CounterValue, + float64(obj.RemovedMemory), + obj.Name, + ) + } + + return nil, nil +} From a01f72a8b09fde9b5ccde04d740da6bee06e5931 Mon Sep 17 00:00:00 2001 From: Andrew Banman Date: Fri, 8 Apr 2022 09:27:22 -0700 Subject: [PATCH 2/7] Fix Hyper-V VM memory metric types Signed-off-by: Andrew Banman --- collector/hyperv.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/collector/hyperv.go b/collector/hyperv.go index 309e96d7..1131ef93 100644 --- a/collector/hyperv.go +++ b/collector/hyperv.go @@ -1548,28 +1548,28 @@ func (c *HyperVCollector) collectVmMemory(ch chan<- prometheus.Metric) (*prometh ch <- prometheus.MustNewConstMetric( c.VMMemoryAveragePressure, - prometheus.CounterValue, + prometheus.GaugeValue, float64(obj.AveragePressure), obj.Name, ) ch <- prometheus.MustNewConstMetric( c.VMMemoryCurrentPressure, - prometheus.CounterValue, + prometheus.GaugeValue, float64(obj.CurrentPressure), obj.Name, ) ch <- prometheus.MustNewConstMetric( c.VMMemoryGuestVisiblePhysicalMemory, - prometheus.CounterValue, + prometheus.GaugeValue, float64(obj.GuestVisiblePhysicalMemory), obj.Name, ) ch <- prometheus.MustNewConstMetric( c.VMMemoryMaximumPressure, - prometheus.CounterValue, + prometheus.GaugeValue, float64(obj.MaximumPressure), obj.Name, ) @@ -1590,14 +1590,14 @@ func (c *HyperVCollector) collectVmMemory(ch chan<- prometheus.Metric) (*prometh ch <- prometheus.MustNewConstMetric( c.VMMemoryMinimumPressure, - prometheus.CounterValue, + prometheus.GaugeValue, float64(obj.MinimumPressure), obj.Name, ) ch <- prometheus.MustNewConstMetric( c.VMMemoryPhysicalMemory, - prometheus.CounterValue, + prometheus.GaugeValue, float64(obj.PhysicalMemory), obj.Name, ) From 68c338b4796edc4f13c1a484e32b7552c09066ee Mon Sep 17 00:00:00 2001 From: Andrew Banman Date: Thu, 12 May 2022 09:48:51 -0700 Subject: [PATCH 3/7] Fix hyper-v collector memory metric descriptions Signed-off-by: Andrew Banman --- collector/hyperv.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/collector/hyperv.go b/collector/hyperv.go index 1131ef93..3309c50f 100644 --- a/collector/hyperv.go +++ b/collector/hyperv.go @@ -610,61 +610,61 @@ func NewHyperVCollector() (Collector, error) { VMMemoryAddedMemory: prometheus.NewDesc( prometheus.BuildFQName(Namespace, buildSubsystemName("vm_memory"), "added"), - "", + "This counter represents memory in MB added to the VM", []string{"vm"}, nil, ), VMMemoryAveragePressure: prometheus.NewDesc( prometheus.BuildFQName(Namespace, buildSubsystemName("vm_memory"), "pressure_average"), - "This counter represents the average pressure in the VM.", + "This gauge represents the average pressure in the VM.", []string{"vm"}, nil, ), VMMemoryCurrentPressure: prometheus.NewDesc( prometheus.BuildFQName(Namespace, buildSubsystemName("vm_memory"), "pressure_current"), - "This counter represents the current pressure in the VM.", + "This gauge represents the current pressure in the VM.", []string{"vm"}, nil, ), VMMemoryGuestVisiblePhysicalMemory: prometheus.NewDesc( prometheus.BuildFQName(Namespace, buildSubsystemName("vm_memory"), "physical_guest_visible"), - "'This counter represents the amount of memory visible in the VM.'", + "'This gauge represents the amount of memory in MB visible to the VM guest.'", []string{"vm"}, nil, ), VMMemoryMaximumPressure: prometheus.NewDesc( prometheus.BuildFQName(Namespace, buildSubsystemName("vm_memory"), "pressure_maximum"), - "This counter represents the maximum pressure band in the VM.", + "This gauge represents the maximum pressure band in the VM.", []string{"vm"}, nil, ), VMMemoryMemoryAddOperations: prometheus.NewDesc( prometheus.BuildFQName(Namespace, buildSubsystemName("vm_memory"), "add_operations"), - "", + "This counter represents the number of operations adding memory to the VM.", []string{"vm"}, nil, ), VMMemoryMemoryRemoveOperations: prometheus.NewDesc( prometheus.BuildFQName(Namespace, buildSubsystemName("vm_memory"), "remove_operations"), - "", + "This counter represents the number of operations removing memory from the VM.", []string{"vm"}, nil, ), VMMemoryMinimumPressure: prometheus.NewDesc( prometheus.BuildFQName(Namespace, buildSubsystemName("vm_memory"), "pressure_minimum"), - "This counter represents the minmum pressure band in the VM.", + "This gauge represents the minmum pressure band in the VM.", []string{"vm"}, nil, ), VMMemoryPhysicalMemory: prometheus.NewDesc( prometheus.BuildFQName(Namespace, buildSubsystemName("vm_memory"), "physical_memory"), - "This counter represents the current amount of memory in the VM.", + "This gauge represents the current amount of memory in MB assigned to the VM.", []string{"vm"}, nil, ), VMMemoryRemovedMemory: prometheus.NewDesc( prometheus.BuildFQName(Namespace, buildSubsystemName("vm_memory"), "removed"), - "", + "This counter represents memory in MB removed from the VM", []string{"vm"}, nil, ), From 9f384e3db19b403e9a38355f070a7ccdf758f14d Mon Sep 17 00:00:00 2001 From: Andrew Banman Date: Thu, 12 May 2022 09:54:41 -0700 Subject: [PATCH 4/7] Fix hyper-v collector memory metric names Remove "memory", which is redundant with the module and breaks symmetry with vm_memory_physical_guest_visible. Signed-off-by: Andrew Banman --- collector/hyperv.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/collector/hyperv.go b/collector/hyperv.go index 3309c50f..390a81db 100644 --- a/collector/hyperv.go +++ b/collector/hyperv.go @@ -657,7 +657,7 @@ func NewHyperVCollector() (Collector, error) { nil, ), VMMemoryPhysicalMemory: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, buildSubsystemName("vm_memory"), "physical_memory"), + prometheus.BuildFQName(Namespace, buildSubsystemName("vm_memory"), "physical"), "This gauge represents the current amount of memory in MB assigned to the VM.", []string{"vm"}, nil, From dd494b11bb4cb08a2fc93b25af61db96459d1b4c Mon Sep 17 00:00:00 2001 From: Andrew Banman Date: Thu, 12 May 2022 10:00:49 -0700 Subject: [PATCH 5/7] Add _total to hyper-v memory counter metrics Signed-off-by: Andrew Banman --- collector/hyperv.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/collector/hyperv.go b/collector/hyperv.go index 390a81db..33211cfe 100644 --- a/collector/hyperv.go +++ b/collector/hyperv.go @@ -609,7 +609,7 @@ func NewHyperVCollector() (Collector, error) { // VMMemoryAddedMemory: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, buildSubsystemName("vm_memory"), "added"), + prometheus.BuildFQName(Namespace, buildSubsystemName("vm_memory"), "added_total"), "This counter represents memory in MB added to the VM", []string{"vm"}, nil, @@ -639,13 +639,13 @@ func NewHyperVCollector() (Collector, error) { nil, ), VMMemoryMemoryAddOperations: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, buildSubsystemName("vm_memory"), "add_operations"), + prometheus.BuildFQName(Namespace, buildSubsystemName("vm_memory"), "add_operations_total"), "This counter represents the number of operations adding memory to the VM.", []string{"vm"}, nil, ), VMMemoryMemoryRemoveOperations: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, buildSubsystemName("vm_memory"), "remove_operations"), + prometheus.BuildFQName(Namespace, buildSubsystemName("vm_memory"), "remove_operations_total"), "This counter represents the number of operations removing memory from the VM.", []string{"vm"}, nil, @@ -663,7 +663,7 @@ func NewHyperVCollector() (Collector, error) { nil, ), VMMemoryRemovedMemory: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, buildSubsystemName("vm_memory"), "removed"), + prometheus.BuildFQName(Namespace, buildSubsystemName("vm_memory"), "removed_total"), "This counter represents memory in MB removed from the VM", []string{"vm"}, nil, From 8f6204f960706138e4f88a89855de32a0983d2a2 Mon Sep 17 00:00:00 2001 From: Andrew Banman Date: Thu, 12 May 2022 13:04:04 -0700 Subject: [PATCH 6/7] Fix typo in vm_memory_pressure_minimum description Signed-off-by: Andrew Banman --- collector/hyperv.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/collector/hyperv.go b/collector/hyperv.go index 33211cfe..42b1b7c6 100644 --- a/collector/hyperv.go +++ b/collector/hyperv.go @@ -652,7 +652,7 @@ func NewHyperVCollector() (Collector, error) { ), VMMemoryMinimumPressure: prometheus.NewDesc( prometheus.BuildFQName(Namespace, buildSubsystemName("vm_memory"), "pressure_minimum"), - "This gauge represents the minmum pressure band in the VM.", + "This gauge represents the minimum pressure band in the VM.", []string{"vm"}, nil, ), From 4aba3e1222a1c12ac164ccbdbf6539fd7d304209 Mon Sep 17 00:00:00 2001 From: Ben Reedy Date: Fri, 13 May 2022 06:10:39 +1000 Subject: [PATCH 7/7] Add initial docs for hyperv memory metrics Signed-off-by: Ben Reedy --- docs/collector.hyperv.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/docs/collector.hyperv.md b/docs/collector.hyperv.md index 919a0070..9c3658ac 100644 --- a/docs/collector.hyperv.md +++ b/docs/collector.hyperv.md @@ -51,6 +51,16 @@ Name | Description | Type | Labels `windows_hyperv_vm_cpu_guest_run_time` | _Not yet documented_ | counter | `vm`, `core` `windows_hyperv_vm_cpu_hypervisor_run_time` | _Not yet documented_ | counter | `vm`, `core` `windows_hyperv_vm_cpu_remote_run_time` | _Not yet documented_ | counter | `vm`, `core` +`windows_hyperv_vm_memory_added_total` | _Not yet documented_ | counter | `vm` +`windows_hyperv_vm_memory_pressure_average` | _Not yet documented_ | gauge | `vm` +`windows_hyperv_vm_memory_pressure_current` | _Not yet documented_ | counter | `vm` +`windows_hyperv_vm_memory_physical_guest_visible` | _Not yet documented_ | gauge | `vm` +`windows_hyperv_vm_memory_pressure_maximum` | _Not yet documented_ | gauge | `vm` +`windows_hyperv_vm_memory_add_operations_total` | _Not yet documented_ | counter | `vm` +`windows_hyperv_vm_memory_remove_operations_total` | _Not yet documented_ | counter | `vm` +`windows_hyperv_vm_memory_pressure_minumim` | _Not yet documented_ | gauge | `vm` +`windows_hyperv_vm_memory_physical` | _Not yet documented_ | gauge | `vm` +`windows_hyperv_vm_memory_removed_total` | _Not yet documented_ | counter | `vm` `windows_hyperv_vm_cpu_total_run_time` | _Not yet documented_ | counter | `vm`, `core` `windows_hyperv_vswitch_broadcast_packets_received_total` | _Not yet documented_ | counter | `vswitch` `windows_hyperv_vswitch_broadcast_packets_sent_total` | _Not yet documented_ | counter | `vswitch`