Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hyperv: Added DataStore, Virtual SMB and Dynamic Memory Balancer metrics #1712

Draft
wants to merge 13 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/spelling.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ jobs:
check_filenames: true
# When using this Action in other repos, the --skip option below can be removed
skip: ./.git,go.mod,go.sum
ignore_words_list: calle
ignore_words_list: calle,Entires
274 changes: 172 additions & 102 deletions docs/collector.hyperv.md

Large diffs are not rendered by default.

25 changes: 0 additions & 25 deletions internal/collector/cpu/cpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,31 +120,6 @@ func (c *Collector) Build(_ *slog.Logger, _ *mi.Session) error {
nil,
nil,
)

c.cStateSecondsTotal = prometheus.NewDesc(
prometheus.BuildFQName(types.Namespace, Name, "cstate_seconds_total"),
"Time spent in low-power idle state",
[]string{"core", "state"},
nil,
)
c.timeTotal = prometheus.NewDesc(
prometheus.BuildFQName(types.Namespace, Name, "time_total"),
"Time that processor spent in different modes (dpc, idle, interrupt, privileged, user)",
[]string{"core", "mode"},
nil,
)
c.interruptsTotal = prometheus.NewDesc(
prometheus.BuildFQName(types.Namespace, Name, "interrupts_total"),
"Total number of received and serviced hardware interrupts",
[]string{"core"},
nil,
)
c.dpcsTotal = prometheus.NewDesc(
prometheus.BuildFQName(types.Namespace, Name, "dpcs_total"),
"Total number of received and serviced deferred procedure calls (DPCs)",
[]string{"core"},
nil,
)
c.cStateSecondsTotal = prometheus.NewDesc(
prometheus.BuildFQName(types.Namespace, Name, "cstate_seconds_total"),
"Time spent in low-power idle state",
Expand Down
4 changes: 2 additions & 2 deletions internal/collector/cs/cs.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ type Collector struct {
config Config

// physicalMemoryBytes
// Deprecated: Use windows_cpu_logical_processor instead
// Deprecated: Use windows_physical_memory_total_bytes instead
physicalMemoryBytes *prometheus.Desc
// logicalProcessors
// Deprecated: Use windows_physical_memory_total_bytes instead
// Deprecated: Use windows_cpu_logical_processor instead
logicalProcessors *prometheus.Desc
// hostname
// Deprecated: Use windows_os_hostname instead
Expand Down
1,985 changes: 312 additions & 1,673 deletions internal/collector/hyperv/hyperv.go

Large diffs are not rendered by default.

111 changes: 111 additions & 0 deletions internal/collector/hyperv/hyperv_dynamic_memory_balancer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package hyperv

import (
"errors"
"fmt"

"github.com/prometheus-community/windows_exporter/internal/perfdata"
"github.com/prometheus-community/windows_exporter/internal/types"
"github.com/prometheus-community/windows_exporter/internal/utils"
"github.com/prometheus/client_golang/prometheus"
)

// collectorDynamicMemoryBalancer Hyper-V Dynamic Memory Balancer metrics
type collectorDynamicMemoryBalancer struct {
perfDataCollectorDynamicMemoryBalancer perfdata.Collector
vmDynamicMemoryBalancerAvailableMemoryForBalancing *prometheus.Desc // \Hyper-V Dynamic Memory Balancer(*)\Available Memory For Balancing
vmDynamicMemoryBalancerSystemCurrentPressure *prometheus.Desc // \Hyper-V Dynamic Memory Balancer(*)\System Current Pressure
vmDynamicMemoryBalancerAvailableMemory *prometheus.Desc // \Hyper-V Dynamic Memory Balancer(*)\Available Memory
vmDynamicMemoryBalancerAveragePressure *prometheus.Desc // \Hyper-V Dynamic Memory Balancer(*)\Average Pressure
}

const (
// Hyper-V Dynamic Memory Balancer metrics
vmDynamicMemoryBalancerAvailableMemory = "Available Memory"
vmDynamicMemoryBalancerAvailableMemoryForBalancing = "Available Memory For Balancing"
vmDynamicMemoryBalancerAveragePressure = "Average Pressure"
vmDynamicMemoryBalancerSystemCurrentPressure = "System Current Pressure"
)

func (c *Collector) buildDynamicMemoryBalancer() error {
var err error

// https://learn.microsoft.com/en-us/archive/blogs/chrisavis/monitoring-dynamic-memory-in-windows-server-hyper-v-2012
c.perfDataCollectorDynamicMemoryBalancer, err = perfdata.NewCollector(perfdata.V2, "Hyper-V Dynamic Memory Balancer", perfdata.AllInstances, []string{
vmDynamicMemoryBalancerAvailableMemory,
vmDynamicMemoryBalancerAvailableMemoryForBalancing,
vmDynamicMemoryBalancerAveragePressure,
vmDynamicMemoryBalancerSystemCurrentPressure,
})
if err != nil {
return fmt.Errorf("failed to create Hyper-V Virtual Machine Health Summary collector: %w", err)
}

c.vmDynamicMemoryBalancerAvailableMemory = prometheus.NewDesc(
prometheus.BuildFQName(types.Namespace, Name, "dynamic_memory_balancer_available_memory_bytes"),
"Represents the amount of memory left on the node.",
[]string{"balancer"},
nil,
)
c.vmDynamicMemoryBalancerAvailableMemoryForBalancing = prometheus.NewDesc(
prometheus.BuildFQName(types.Namespace, Name, "dynamic_memory_balancer_available_memory_for_balancing_bytes"),
"Represents the available memory for balancing purposes.",
[]string{"balancer"},
nil,
)
c.vmDynamicMemoryBalancerAveragePressure = prometheus.NewDesc(
prometheus.BuildFQName(types.Namespace, Name, "dynamic_memory_balancer_average_pressure_ratio"),
"Represents the average system pressure on the balancer node among all balanced objects.",
[]string{"balancer"},
nil,
)
c.vmDynamicMemoryBalancerSystemCurrentPressure = prometheus.NewDesc(
prometheus.BuildFQName(types.Namespace, Name, "dynamic_memory_balancer_system_current_pressure_ratio"),
"Represents the current pressure in the system.",
[]string{"balancer"},
nil,
)

return nil
}

func (c *Collector) collectDynamicMemoryBalancer(ch chan<- prometheus.Metric) error {
data, err := c.perfDataCollectorDynamicMemoryBalancer.Collect()
if err != nil {
return fmt.Errorf("failed to collect Hyper-V Dynamic Memory Balancer metrics: %w", err)
} else if len(data) == 0 {
return errors.New("perflib query for Hyper-V Dynamic Memory Balancer returned empty result set")
}

for name, page := range data {
ch <- prometheus.MustNewConstMetric(
c.vmDynamicMemoryBalancerAvailableMemory,
prometheus.GaugeValue,
utils.MBToBytes(page[vmDynamicMemoryBalancerAvailableMemory].FirstValue),
name,
)

ch <- prometheus.MustNewConstMetric(
c.vmDynamicMemoryBalancerAvailableMemoryForBalancing,
prometheus.GaugeValue,
utils.MBToBytes(page[vmDynamicMemoryBalancerAvailableMemoryForBalancing].FirstValue),
name,
)

ch <- prometheus.MustNewConstMetric(
c.vmDynamicMemoryBalancerAveragePressure,
prometheus.GaugeValue,
utils.PercentageToRatio(page[vmDynamicMemoryBalancerAveragePressure].FirstValue),
name,
)

ch <- prometheus.MustNewConstMetric(
c.vmDynamicMemoryBalancerSystemCurrentPressure,
prometheus.GaugeValue,
utils.PercentageToRatio(page[vmDynamicMemoryBalancerSystemCurrentPressure].FirstValue),
name,
)
}

return nil
}
203 changes: 203 additions & 0 deletions internal/collector/hyperv/hyperv_dynamic_memory_vm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
package hyperv

import (
"fmt"

"github.com/prometheus-community/windows_exporter/internal/perfdata"
"github.com/prometheus-community/windows_exporter/internal/types"
"github.com/prometheus-community/windows_exporter/internal/utils"
"github.com/prometheus/client_golang/prometheus"
)

// collectorDynamicMemoryVM Hyper-V Dynamic Memory VM metrics
type collectorDynamicMemoryVM struct {
perfDataCollectorDynamicMemoryVM perfdata.Collector
vmMemoryAddedMemory *prometheus.Desc // \Hyper-V Dynamic Memory VM(*)\Added Memory
vmMemoryCurrentPressure *prometheus.Desc // \Hyper-V Dynamic Memory VM(*)\Current Pressure
vmMemoryGuestVisiblePhysicalMemory *prometheus.Desc // \Hyper-V Dynamic Memory VM(*)\Guest Visible Physical Memory
vmMemoryMaximumPressure *prometheus.Desc // \Hyper-V Dynamic Memory VM(*)\Maximum Pressure
vmMemoryMemoryAddOperations *prometheus.Desc // \Hyper-V Dynamic Memory VM(*)\Memory Add Operations
vmMemoryMemoryRemoveOperations *prometheus.Desc // \Hyper-V Dynamic Memory VM(*)\Memory Remove Operations
vmMemoryMinimumPressure *prometheus.Desc // \Hyper-V Dynamic Memory VM(*)\Minimum Pressure
vmMemoryPhysicalMemory *prometheus.Desc // \Hyper-V Dynamic Memory VM(*)\Physical Memory
vmMemoryRemovedMemory *prometheus.Desc // \Hyper-V Dynamic Memory VM(*)\Removed Memory
vmMemoryGuestAvailableMemory *prometheus.Desc // \Hyper-V Dynamic Memory VM(*)\Guest Available Memory
}

const (
// Hyper-V Dynamic Memory VM metrics
vmMemoryAddedMemory = "Added Memory"
vmMemoryCurrentPressure = "Current Pressure"
vmMemoryGuestAvailableMemory = "Guest Available Memory"
vmMemoryGuestVisiblePhysicalMemory = "Guest Visible Physical Memory"
vmMemoryMaximumPressure = "Maximum Pressure"
vmMemoryMemoryAddOperations = "Memory Add Operations"
vmMemoryMemoryRemoveOperations = "Memory Remove Operations"
vmMemoryMinimumPressure = "Minimum Pressure"
vmMemoryPhysicalMemory = "Physical Memory"
vmMemoryRemovedMemory = "Removed Memory"
)

func (c *Collector) buildDynamicMemoryVM() error {
var err error

c.perfDataCollectorDynamicMemoryVM, err = perfdata.NewCollector(perfdata.V2, "Hyper-V Dynamic Memory VM", perfdata.AllInstances, []string{
vmMemoryAddedMemory,
vmMemoryCurrentPressure,
vmMemoryGuestVisiblePhysicalMemory,
vmMemoryMaximumPressure,
vmMemoryMemoryAddOperations,
vmMemoryMemoryRemoveOperations,
vmMemoryMinimumPressure,
vmMemoryPhysicalMemory,
vmMemoryRemovedMemory,
vmMemoryGuestAvailableMemory,
})
if err != nil {
return fmt.Errorf("failed to create Hyper-V Dynamic Memory VM collector: %w", err)
}

c.vmMemoryAddedMemory = prometheus.NewDesc(
prometheus.BuildFQName(types.Namespace, Name, "dynamic_memory_vm_added_total"),
"Represents the cumulative amount of memory added to the VM.",
[]string{"vm"},
nil,
)
c.vmMemoryCurrentPressure = prometheus.NewDesc(
prometheus.BuildFQName(types.Namespace, Name, "dynamic_memory_vm_pressure_current_ratio"),
"Represents the current pressure in the VM.",
[]string{"vm"},
nil,
)
c.vmMemoryGuestAvailableMemory = prometheus.NewDesc(
prometheus.BuildFQName(types.Namespace, Name, "dynamic_memory_vm_guest_available_bytes"),
"Represents the current amount of available memory in the VM (reported by the VM).",
[]string{"vm"},
nil,
)
c.vmMemoryGuestVisiblePhysicalMemory = prometheus.NewDesc(
prometheus.BuildFQName(types.Namespace, Name, "dynamic_memory_vm_guest_visible_physical_memory_bytes"),
"Represents the amount of memory visible in the VM.'",
[]string{"vm"},
nil,
)
c.vmMemoryMaximumPressure = prometheus.NewDesc(
prometheus.BuildFQName(types.Namespace, Name, "dynamic_memory_vm_pressure_maximum_ratio"),
"Represents the maximum pressure band in the VM.",
[]string{"vm"},
nil,
)
c.vmMemoryMemoryAddOperations = prometheus.NewDesc(
prometheus.BuildFQName(types.Namespace, Name, "dynamic_memory_vm_add_operations_total"),
"Represents the total number of add operations for the VM.",
[]string{"vm"},
nil,
)
c.vmMemoryMemoryRemoveOperations = prometheus.NewDesc(
prometheus.BuildFQName(types.Namespace, Name, "dynamic_memory_vm_remove_operations_total"),
"Represents the total number of remove operations for the VM.",
[]string{"vm"},
nil,
)
c.vmMemoryMinimumPressure = prometheus.NewDesc(
prometheus.BuildFQName(types.Namespace, Name, "dynamic_memory_vm_pressure_minimum_ratio"),
"Represents the minimum pressure band in the VM.",
[]string{"vm"},
nil,
)
c.vmMemoryPhysicalMemory = prometheus.NewDesc(
prometheus.BuildFQName(types.Namespace, Name, "dynamic_memory_vm_physical_bytes"),
"Represents the current amount of memory in the VM.",
[]string{"vm"},
nil,
)
c.vmMemoryRemovedMemory = prometheus.NewDesc(
prometheus.BuildFQName(types.Namespace, Name, "dynamic_memory_vm_removed_bytes_total"),
"Represents the cumulative amount of memory removed from the VM.",
[]string{"vm"},
nil,
)

return nil
}

func (c *Collector) collectDynamicMemoryVM(ch chan<- prometheus.Metric) error {
data, err := c.perfDataCollectorDynamicMemoryVM.Collect()
if err != nil {
return fmt.Errorf("failed to collect Hyper-V Dynamic Memory VM metrics: %w", err)
}

for vmName, vmData := range data {
ch <- prometheus.MustNewConstMetric(
c.vmMemoryAddedMemory,
prometheus.CounterValue,
utils.MBToBytes(vmData[vmMemoryAddedMemory].FirstValue),
vmName,
)

ch <- prometheus.MustNewConstMetric(
c.vmMemoryCurrentPressure,
prometheus.GaugeValue,
utils.PercentageToRatio(vmData[vmMemoryCurrentPressure].FirstValue),
vmName,
)

ch <- prometheus.MustNewConstMetric(
c.vmMemoryGuestAvailableMemory,
prometheus.GaugeValue,
utils.MBToBytes(vmData[vmMemoryGuestAvailableMemory].FirstValue),
vmName,
)

ch <- prometheus.MustNewConstMetric(
c.vmMemoryGuestVisiblePhysicalMemory,
prometheus.GaugeValue,
utils.MBToBytes(vmData[vmMemoryGuestVisiblePhysicalMemory].FirstValue),
vmName,
)

ch <- prometheus.MustNewConstMetric(
c.vmMemoryMaximumPressure,
prometheus.GaugeValue,
utils.PercentageToRatio(vmData[vmMemoryMaximumPressure].FirstValue),
vmName,
)

ch <- prometheus.MustNewConstMetric(
c.vmMemoryMemoryAddOperations,
prometheus.CounterValue,
vmData[vmMemoryMemoryAddOperations].FirstValue,
vmName,
)

ch <- prometheus.MustNewConstMetric(
c.vmMemoryMemoryRemoveOperations,
prometheus.CounterValue,
vmData[vmMemoryMemoryRemoveOperations].FirstValue,
vmName,
)

ch <- prometheus.MustNewConstMetric(
c.vmMemoryMinimumPressure,
prometheus.GaugeValue,
utils.PercentageToRatio(vmData[vmMemoryMinimumPressure].FirstValue),
vmName,
)

ch <- prometheus.MustNewConstMetric(
c.vmMemoryPhysicalMemory,
prometheus.GaugeValue,
utils.MBToBytes(vmData[vmMemoryPhysicalMemory].FirstValue),
vmName,
)

ch <- prometheus.MustNewConstMetric(
c.vmMemoryRemovedMemory,
prometheus.CounterValue,
utils.MBToBytes(vmData[vmMemoryRemovedMemory].FirstValue),
vmName,
)
}

return nil
}
Loading
Loading