From b43978eeb4e2978f1d6eaed98cf030f3b43097c7 Mon Sep 17 00:00:00 2001 From: Anton Akhmedzyanov Date: Thu, 28 Jul 2022 19:07:19 +0300 Subject: [PATCH 1/3] Add Hyper-V Hypervisor Logical Processor metrics Signed-off-by: Anton Akhmedzyanov --- collector/hyperv.go | 84 ++++++++++++++++++++++++++++++++++++++++ docs/collector.hyperv.md | 5 ++- 2 files changed, 88 insertions(+), 1 deletion(-) diff --git a/collector/hyperv.go b/collector/hyperv.go index 42b1b7c6..bde525d8 100644 --- a/collector/hyperv.go +++ b/collector/hyperv.go @@ -53,6 +53,11 @@ type HyperVCollector struct { LogicalProcessors *prometheus.Desc VirtualProcessors *prometheus.Desc + // Win32_PerfRawData_HvStats_HyperVHypervisorLogicalProcessor + HostLPGuestRunTime *prometheus.Desc + HostLPHypervisorRunTime *prometheus.Desc + HostLPTotalRunTime *prometheus.Desc + // Win32_PerfRawData_HvStats_HyperVHypervisorRootVirtualProcessor HostGuestRunTime *prometheus.Desc HostHypervisorRunTime *prometheus.Desc @@ -309,6 +314,27 @@ func NewHyperVCollector() (Collector, error) { // + HostLPGuestRunTime: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, buildSubsystemName("host_lp"), "guest_run_time"), + "The percentage of time spent by the processor in guest code", + []string{"core"}, + nil, + ), + HostLPHypervisorRunTime: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, buildSubsystemName("host_lp"), "hypervisor_run_time"), + "The percentage of time spent by the processor in hypervisor code", + []string{"core"}, + nil, + ), + HostLPTotalRunTime: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, buildSubsystemName("host_lp"), "total_run_time"), + "The percentage of time spent by the processor in guest and hypervisor code", + []string{"core"}, + nil, + ), + + // + HostGuestRunTime: prometheus.NewDesc( prometheus.BuildFQName(Namespace, buildSubsystemName("host_cpu"), "guest_run_time"), "The time spent by the virtual processor in guest code", @@ -694,6 +720,11 @@ func (c *HyperVCollector) Collect(ctx *ScrapeContext, ch chan<- prometheus.Metri return err } + if desc, err := c.collectHostLPUsage(ch); err != nil { + log.Error("failed collecting hyperV host logical processors metrics:", desc, err) + return err + } + if desc, err := c.collectHostCpuUsage(ch); err != nil { log.Error("failed collecting hyperV host CPU metrics:", desc, err) return err @@ -999,6 +1030,59 @@ func (c *HyperVCollector) collectVmProcessor(ch chan<- prometheus.Metric) (*prom return nil, nil } +// Win32_PerfRawData_HvStats_HyperVHypervisorLogicalProcessor ... +type Win32_PerfRawData_HvStats_HyperVHypervisorLogicalProcessor struct { + Name string + PercentGuestRunTime uint64 + PercentHypervisorRunTime uint64 + PercentTotalRunTime uint +} + +func (c *HyperVCollector) collectHostLPUsage(ch chan<- prometheus.Metric) (*prometheus.Desc, error) { + var dst []Win32_PerfRawData_HvStats_HyperVHypervisorLogicalProcessor + 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 + } + // The name format is Hv LP + parts := strings.Split(obj.Name, " ") + if len(parts) != 3 { + log.Warnf("Unexpected format of Name in collectHostLPUsage: %q", obj.Name) + continue + } + coreId := parts[2] + + ch <- prometheus.MustNewConstMetric( + c.HostLPGuestRunTime, + prometheus.GaugeValue, + float64(obj.PercentGuestRunTime), + coreId, + ) + + ch <- prometheus.MustNewConstMetric( + c.HostLPHypervisorRunTime, + prometheus.GaugeValue, + float64(obj.PercentHypervisorRunTime), + coreId, + ) + + ch <- prometheus.MustNewConstMetric( + c.HostLPTotalRunTime, + prometheus.GaugeValue, + float64(obj.PercentTotalRunTime), + coreId, + ) + + } + + return nil, nil +} + // Win32_PerfRawData_HvStats_HyperVHypervisorRootVirtualProcessor ... type Win32_PerfRawData_HvStats_HyperVHypervisorRootVirtualProcessor struct { Name string diff --git a/docs/collector.hyperv.md b/docs/collector.hyperv.md index 9c3658ac..0900d9f4 100644 --- a/docs/collector.hyperv.md +++ b/docs/collector.hyperv.md @@ -5,7 +5,7 @@ The hyperv collector exposes metrics about the Hyper-V hypervisor ||| -|- Metric name prefix | `hyperv` -Classes | `Win32_PerfRawData_VmmsVirtualMachineStats_HyperVVirtualMachineHealthSummary`
`Win32_PerfRawData_VidPerfProvider_HyperVVMVidPartition`
`Win32_PerfRawData_HvStats_HyperVHypervisorRootPartition`
`Win32_PerfRawData_HvStats_HyperVHypervisor`
`Win32_PerfRawData_HvStats_HyperVHypervisorRootVirtualProcessor`
`Win32_PerfRawData_HvStats_HyperVHypervisorVirtualProcessor`
`Win32_PerfRawData_NvspSwitchStats_HyperVVirtualSwitch`
`Win32_PerfRawData_EthernetPerfProvider_HyperVLegacyNetworkAdapter`
`Win32_PerfRawData_Counters_HyperVVirtualStorageDevice`
`Win32_PerfRawData_NvspNicStats_HyperVVirtualNetworkAdapter` +Classes | `Win32_PerfRawData_VmmsVirtualMachineStats_HyperVVirtualMachineHealthSummary`
`Win32_PerfRawData_VidPerfProvider_HyperVVMVidPartition`
`Win32_PerfRawData_HvStats_HyperVHypervisorRootPartition`
`Win32_PerfRawData_HvStats_HyperVHypervisor`
`Win32_PerfRawData_HvStats_HyperVHypervisorLogicalProcessor`
`Win32_PerfRawData_HvStats_HyperVHypervisorRootVirtualProcessor`
`Win32_PerfRawData_HvStats_HyperVHypervisorVirtualProcessor`
`Win32_PerfRawData_NvspSwitchStats_HyperVVirtualSwitch`
`Win32_PerfRawData_EthernetPerfProvider_HyperVLegacyNetworkAdapter`
`Win32_PerfRawData_Counters_HyperVVirtualStorageDevice`
`Win32_PerfRawData_NvspNicStats_HyperVVirtualNetworkAdapter` Enabled by default? | No ## Flags @@ -44,6 +44,9 @@ Name | Description | Type | Labels `windows_hyperv_root_partition_virtual_tlb_pages` | _Not yet documented_ | counter | None `windows_hyperv_hypervisor_virtual_processors` | _Not yet documented_ | counter | None `windows_hyperv_hypervisor_logical_processors` | _Not yet documented_ | counter | None +`windows_hyperv_host_lp_guest_run_time` | _Not yet documented_ | counter | `core` +`windows_hyperv_host_lp_hypervisor_run_time` | _Not yet documented_ | counter | `core` +`windows_hyperv_host_lp_total_run_time` | _Not yet documented_ | counter | `core` `windows_hyperv_host_cpu_guest_run_time` | _Not yet documented_ | counter | `core` `windows_hyperv_host_cpu_hypervisor_run_time` | _Not yet documented_ | counter | `core` `windows_hyperv_host_cpu_remote_run_time` | _Not yet documented_ | counter | `core` From a722cee32204a05766e5f6b0500416b90e5f378a Mon Sep 17 00:00:00 2001 From: Anton Akhmedzyanov Date: Thu, 28 Jul 2022 20:15:00 +0300 Subject: [PATCH 2/3] Add Hyper-V Hypervisor CPU utilization query. Signed-off-by: Anton Akhmedzyanov --- docs/collector.hyperv.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/collector.hyperv.md b/docs/collector.hyperv.md index 0900d9f4..0be4bfd4 100644 --- a/docs/collector.hyperv.md +++ b/docs/collector.hyperv.md @@ -121,6 +121,10 @@ Percent of physical CPU resources by the hosts themselves (on all monitored host ``` (sum by (instance)(rate(windows_hyperv_host_cpu_total_run_time{}[1m]))) / sum by (instance)(windows_cs_logical_processors{}) / 100000 ``` +Percent of physical CPU resources by the hypervisor (on all monitored hosts) +``` +(sum by (instance)(rate(windows_hyperv_host_lp_total_run_time{}[1m]))) / sum by (instance)(windows_hyperv_hypervisor_logical_processors{}) / 100000 +``` ## Alerting examples _This collector does not yet have alerting examples, we would appreciate your help adding them!_ From 37ea988125c2dcace28ae37ab1333e6df4a58898 Mon Sep 17 00:00:00 2001 From: Anton Akhmedzyanov Date: Sun, 21 Aug 2022 15:36:59 +0300 Subject: [PATCH 3/3] Added percent suffix for metric names Signed-off-by: Anton Akhmedzyanov --- collector/hyperv.go | 24 ++++++++++++------------ docs/collector.hyperv.md | 8 ++++---- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/collector/hyperv.go b/collector/hyperv.go index bde525d8..761b5d94 100644 --- a/collector/hyperv.go +++ b/collector/hyperv.go @@ -54,9 +54,9 @@ type HyperVCollector struct { VirtualProcessors *prometheus.Desc // Win32_PerfRawData_HvStats_HyperVHypervisorLogicalProcessor - HostLPGuestRunTime *prometheus.Desc - HostLPHypervisorRunTime *prometheus.Desc - HostLPTotalRunTime *prometheus.Desc + HostLPGuestRunTimePercent *prometheus.Desc + HostLPHypervisorRunTimePercent *prometheus.Desc + HostLPTotalRunTimePercent *prometheus.Desc // Win32_PerfRawData_HvStats_HyperVHypervisorRootVirtualProcessor HostGuestRunTime *prometheus.Desc @@ -314,20 +314,20 @@ func NewHyperVCollector() (Collector, error) { // - HostLPGuestRunTime: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, buildSubsystemName("host_lp"), "guest_run_time"), + HostLPGuestRunTimePercent: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, buildSubsystemName("host_lp"), "guest_run_time_percent"), "The percentage of time spent by the processor in guest code", []string{"core"}, nil, ), - HostLPHypervisorRunTime: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, buildSubsystemName("host_lp"), "hypervisor_run_time"), + HostLPHypervisorRunTimePercent: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, buildSubsystemName("host_lp"), "hypervisor_run_time_percent"), "The percentage of time spent by the processor in hypervisor code", []string{"core"}, nil, ), - HostLPTotalRunTime: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, buildSubsystemName("host_lp"), "total_run_time"), + HostLPTotalRunTimePercent: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, buildSubsystemName("host_lp"), "total_run_time_percent"), "The percentage of time spent by the processor in guest and hypervisor code", []string{"core"}, nil, @@ -1058,21 +1058,21 @@ func (c *HyperVCollector) collectHostLPUsage(ch chan<- prometheus.Metric) (*prom coreId := parts[2] ch <- prometheus.MustNewConstMetric( - c.HostLPGuestRunTime, + c.HostLPGuestRunTimePercent, prometheus.GaugeValue, float64(obj.PercentGuestRunTime), coreId, ) ch <- prometheus.MustNewConstMetric( - c.HostLPHypervisorRunTime, + c.HostLPHypervisorRunTimePercent, prometheus.GaugeValue, float64(obj.PercentHypervisorRunTime), coreId, ) ch <- prometheus.MustNewConstMetric( - c.HostLPTotalRunTime, + c.HostLPTotalRunTimePercent, prometheus.GaugeValue, float64(obj.PercentTotalRunTime), coreId, diff --git a/docs/collector.hyperv.md b/docs/collector.hyperv.md index 0be4bfd4..b6ebfeb2 100644 --- a/docs/collector.hyperv.md +++ b/docs/collector.hyperv.md @@ -44,9 +44,9 @@ Name | Description | Type | Labels `windows_hyperv_root_partition_virtual_tlb_pages` | _Not yet documented_ | counter | None `windows_hyperv_hypervisor_virtual_processors` | _Not yet documented_ | counter | None `windows_hyperv_hypervisor_logical_processors` | _Not yet documented_ | counter | None -`windows_hyperv_host_lp_guest_run_time` | _Not yet documented_ | counter | `core` -`windows_hyperv_host_lp_hypervisor_run_time` | _Not yet documented_ | counter | `core` -`windows_hyperv_host_lp_total_run_time` | _Not yet documented_ | counter | `core` +`windows_hyperv_host_lp_guest_run_time_percent` | _Not yet documented_ | counter | `core` +`windows_hyperv_host_lp_hypervisor_run_time_percent` | _Not yet documented_ | counter | `core` +`windows_hyperv_host_lp_total_run_time_percent` | _Not yet documented_ | counter | `core` `windows_hyperv_host_cpu_guest_run_time` | _Not yet documented_ | counter | `core` `windows_hyperv_host_cpu_hypervisor_run_time` | _Not yet documented_ | counter | `core` `windows_hyperv_host_cpu_remote_run_time` | _Not yet documented_ | counter | `core` @@ -123,7 +123,7 @@ Percent of physical CPU resources by the hosts themselves (on all monitored host ``` Percent of physical CPU resources by the hypervisor (on all monitored hosts) ``` -(sum by (instance)(rate(windows_hyperv_host_lp_total_run_time{}[1m]))) / sum by (instance)(windows_hyperv_hypervisor_logical_processors{}) / 100000 +(sum by (instance)(rate(windows_hyperv_host_lp_total_run_time_percent{}[1m]))) / sum by (instance)(windows_hyperv_hypervisor_logical_processors{}) / 100000 ``` ## Alerting examples