From 3b88460eb55baffeb3fb87dfb961158a323cf799 Mon Sep 17 00:00:00 2001 From: ghj Date: Tue, 23 Jan 2018 20:56:00 +0800 Subject: [PATCH 1/8] add hyperv --- collector/hyperv.go | 1083 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1083 insertions(+) create mode 100644 collector/hyperv.go diff --git a/collector/hyperv.go b/collector/hyperv.go new file mode 100644 index 00000000..35ad3385 --- /dev/null +++ b/collector/hyperv.go @@ -0,0 +1,1083 @@ +package collector + +import ( + "log" + "strings" + + "github.com/StackExchange/wmi" + "github.com/prometheus/client_golang/prometheus" +) + +func init() { + Factories["hyperv"] = NewHyperVCollector +} + +// HyperVCollector is a Prometheus collector for hyper-v +type HyperVCollector struct { + // Win32_PerfRawData_VmmsVirtualMachineStats_HyperVVirtualMachineHealthSummary + HealthCritical *prometheus.Desc + HealthOk *prometheus.Desc + + // Win32_PerfRawData_VidPerfProvider_HyperVVMVidPartition + PhysicalPagesAllocated *prometheus.Desc + PreferredNUMANodeIndex *prometheus.Desc + RemotePhysicalPages *prometheus.Desc + + // Win32_PerfRawData_HvStats_HyperVHypervisorRootPartition + AddressSpaces *prometheus.Desc + AttachedDevices *prometheus.Desc + DepositedPages *prometheus.Desc + DeviceDMAErrors *prometheus.Desc + DeviceInterruptErrors *prometheus.Desc + DeviceInterruptMappings *prometheus.Desc + DeviceInterruptThrottleEvents *prometheus.Desc + GPAPages *prometheus.Desc + GPASpaceModificationsPersec *prometheus.Desc + IOTLBFlushCost *prometheus.Desc + IOTLBFlushesPersec *prometheus.Desc + RecommendedVirtualTLBSize *prometheus.Desc + SkippedTimerTicks *prometheus.Desc + Value1Gdevicepages *prometheus.Desc + Value1GGPApages *prometheus.Desc + Value2Mdevicepages *prometheus.Desc + Value2MGPApages *prometheus.Desc + Value4Kdevicepages *prometheus.Desc + Value4KGPApages *prometheus.Desc + VirtualTLBFlushEntiresPersec *prometheus.Desc + VirtualTLBPages *prometheus.Desc + + // Win32_PerfRawData_HvStats_HyperVHypervisor + LogicalProcessors *prometheus.Desc + VirtualProcessors *prometheus.Desc + + // Win32_PerfRawData_HvStats_HyperVHypervisorVirtualProcessor + PercentGuestRunTime *prometheus.Desc + PercentHypervisorRunTime *prometheus.Desc + PercentRemoteRunTime *prometheus.Desc + PercentTotalRunTime *prometheus.Desc + + // Win32_PerfRawData_NvspSwitchStats_HyperVVirtualSwitch + BroadcastPacketsReceivedPersec *prometheus.Desc + BroadcastPacketsSentPersec *prometheus.Desc + BytesPersec *prometheus.Desc + BytesReceivedPersec *prometheus.Desc + BytesSentPersec *prometheus.Desc + DirectedPacketsReceivedPersec *prometheus.Desc + DirectedPacketsSentPersec *prometheus.Desc + DroppedPacketsIncomingPersec *prometheus.Desc + DroppedPacketsOutgoingPersec *prometheus.Desc + ExtensionsDroppedPacketsIncomingPersec *prometheus.Desc + ExtensionsDroppedPacketsOutgoingPersec *prometheus.Desc + LearnedMacAddresses *prometheus.Desc + LearnedMacAddressesPersec *prometheus.Desc + MulticastPacketsReceivedPersec *prometheus.Desc + MulticastPacketsSentPersec *prometheus.Desc + NumberofSendChannelMovesPersec *prometheus.Desc + NumberofVMQMovesPersec *prometheus.Desc + PacketsFlooded *prometheus.Desc + PacketsFloodedPersec *prometheus.Desc + PacketsPersec *prometheus.Desc + PacketsReceivedPersec *prometheus.Desc + PacketsSentPersec *prometheus.Desc + PurgedMacAddresses *prometheus.Desc + PurgedMacAddressesPersec *prometheus.Desc + + // Win32_PerfRawData_EthernetPerfProvider_HyperVLegacyNetworkAdapter + AdapterBytesDropped *prometheus.Desc + AdapterBytesReceivedPersec *prometheus.Desc + AdapterBytesSentPersec *prometheus.Desc + AdapterFramesDropped *prometheus.Desc + AdapterFramesReceivedPersec *prometheus.Desc + AdapterFramesSentPersec *prometheus.Desc +} + +// NewHyperVCollector ... +func NewHyperVCollector() (Collector, error) { + return &HyperVCollector{ + HealthCritical: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "health", "health_critical"), + "This counter represents the number of virtual machines with critical health", + nil, + nil, + ), + HealthOk: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "health", "health_ok"), + "This counter represents the number of virtual machines with ok health", + nil, + nil, + ), + + // + + PhysicalPagesAllocated: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "vid", "physical_pages_allocated"), + "The number of physical pages allocated", + nil, + nil, + ), + PreferredNUMANodeIndex: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "vid", "preferred_numa_node_index"), + "The preferred NUMA node index associated with this partition", + nil, + nil, + ), + RemotePhysicalPages: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "vid", "remote_physical_pages"), + "The number of physical pages not allocated from the preferred NUMA node", + nil, + nil, + ), + + // + + AddressSpaces: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "hv", "address_spaces"), + "The number of address spaces in the virtual TLB of the partition", + nil, + nil, + ), + AttachedDevices: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "hv", "attached_devices"), + "The number of devices attached to the partition", + nil, + nil, + ), + DepositedPages: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "hv", "deposited_pages"), + "The number of pages deposited into the partition", + nil, + nil, + ), + DeviceDMAErrors: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "hv", "device_dma_errors"), + "An indicator of illegal DMA requests generated by all devices assigned to the partition", + nil, + nil, + ), + DeviceInterruptErrors: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "hv", "device_interrupt_errors"), + "An indicator of illegal interrupt requests generated by all devices assigned to the partition", + nil, + nil, + ), + DeviceInterruptMappings: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "hv", "device_interrupt_mappings"), + "The number of device interrupt mappings used by the partition", + nil, + nil, + ), + DeviceInterruptThrottleEvents: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "hv", "device_interrupt_throttle_events"), + "The number of times an interrupt from a device assigned to the partition was temporarily throttled because the device was generating too many interrupts", + nil, + nil, + ), + GPAPages: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "hv", "preferred_numa_node_index"), + "The number of pages present in the GPA space of the partition (zero for root partition)", + nil, + nil, + ), + GPASpaceModificationsPersec: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "hv", "gpa_space_modifications_persec"), + "The rate of modifications to the GPA space of the partition", + nil, + nil, + ), + IOTLBFlushCost: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "hv", "io_tlb_flush_cost"), + "The average time (in nanoseconds) spent processing an I/O TLB flush", + nil, + nil, + ), + IOTLBFlushesPersec: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "hv", "io_tlb_flush_persec"), + "The rate of flushes of I/O TLBs of the partition", + nil, + nil, + ), + RecommendedVirtualTLBSize: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "hv", "recommended_virtual_tlb_size"), + "The recommended number of pages to be deposited for the virtual TLB", + nil, + nil, + ), + SkippedTimerTicks: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "hv", "physical_pages_allocated"), + "The number of timer interrupts skipped for the partition", + nil, + nil, + ), + Value1Gdevicepages: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "hv", "1G_device_pages"), + "The number of 1G pages present in the device space of the partition", + nil, + nil, + ), + Value1GGPApages: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "hv", "1G_gpa_pages"), + "The number of 1G pages present in the GPA space of the partition", + nil, + nil, + ), + Value2Mdevicepages: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "hv", "2M_device_pages"), + "The number of 2M pages present in the device space of the partition", + nil, + nil, + ), + Value2MGPApages: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "hv", "2M_gpa_pages"), + "The number of 2M pages present in the GPA space of the partition", + nil, + nil, + ), + Value4Kdevicepages: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "hv", "4K_device_pages"), + "The number of 4K pages present in the device space of the partition", + nil, + nil, + ), + Value4KGPApages: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "hv", "4K_gpa_pages"), + "The number of 4K pages present in the GPA space of the partition", + nil, + nil, + ), + VirtualTLBFlushEntiresPersec: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "hv", "virtual_tlb_flush_entires_persec"), + "The rate of flushes of the entire virtual TLB", + nil, + nil, + ), + VirtualTLBPages: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "hv", "virtual_tlb_pages"), + "The number of pages used by the virtual TLB of the partition", + nil, + nil, + ), + + // + + VirtualProcessors: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "processor", "virtual_processors"), + "The number of virtual processors present in the system", + nil, + nil, + ), + LogicalProcessors: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "processor", "logical_processors"), + "The number of logical processors present in the system", + nil, + nil, + ), + + // + + PercentGuestRunTime: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "rate", "guest_run_time"), + "The percentage of time spent by the virtual processor in guest code", + []string{"core"}, + nil, + ), + PercentHypervisorRunTime: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "rate", "hypervisor_run_time"), + "The percentage of time spent by the virtual processor in hypervisor code", + []string{"core"}, + nil, + ), + PercentRemoteRunTime: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "rate", "remote_run_time"), + "The percentage of time spent by the virtual processor running on a remote node", + []string{"core"}, + nil, + ), + PercentTotalRunTime: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "rate", "total_run_time"), + "The percentage of time spent by the virtual processor in guest and hypervisor code", + []string{"core"}, + nil, + ), + + // + BroadcastPacketsReceivedPersec: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "switch", "broadcast_packets_received_persec"), + "This counter represents the total number of broadcast packets received per second by the virtual switch", + nil, + nil, + ), + BroadcastPacketsSentPersec: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "switch", "broadcast_packets_sent_persec"), + "This counter represents the total number of broadcast packets sent per second by the virtual switch", + nil, + nil, + ), + BytesPersec: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "switch", "bytes_persec"), + "This counter represents the total number of bytes per second traversing the virtual switch", + nil, + nil, + ), + BytesReceivedPersec: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "switch", "bytes_received_persec"), + "This counter represents the total number of bytes received per second by the virtual switch", + nil, + nil, + ), + BytesSentPersec: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "switch", "bytes_sent_persec"), + "This counter represents the total number of bytes sent per second by the virtual switch", + nil, + nil, + ), + DirectedPacketsReceivedPersec: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "switch", "directed_packets_received_persec"), + "This counter represents the total number of directed packets received per second by the virtual switch", + nil, + nil, + ), + DirectedPacketsSentPersec: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "switch", "directed_packets_send_persec"), + "This counter represents the total number of directed packets sent per second by the virtual switch", + nil, + nil, + ), + DroppedPacketsIncomingPersec: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "switch", "dropped_packets_incoming_persec"), + "This counter represents the total number of packet dropped per second by the virtual switch in the incoming direction", + nil, + nil, + ), + DroppedPacketsOutgoingPersec: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "switch", "dropped_packets_outcoming_persec"), + "This counter represents the total number of packet dropped per second by the virtual switch in the outgoing direction", + nil, + nil, + ), + ExtensionsDroppedPacketsIncomingPersec: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "switch", "extensions_dropped_packets_incoming_persec"), + "This counter represents the total number of packet dropped per second by the virtual switch extensions in the incoming direction", + nil, + nil, + ), + ExtensionsDroppedPacketsOutgoingPersec: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "switch", "extensions_dropped_packets_outcoming_persec"), + "This counter represents the total number of packet dropped per second by the virtual switch extensions in the outgoing direction", + nil, + nil, + ), + LearnedMacAddresses: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "switch", "learned_mac_addresses"), + "This counter represents the total number of learned MAC addresses of the virtual switch", + nil, + nil, + ), + LearnedMacAddressesPersec: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "switch", "learned_mac_addresses_persec"), + "This counter represents the total number MAC addresses learned per second by the virtual switch", + nil, + nil, + ), + MulticastPacketsReceivedPersec: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "switch", "multicast_packets_received_persec"), + "This counter represents the total number of multicast packets received per second by the virtual switch", + nil, + nil, + ), + MulticastPacketsSentPersec: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "switch", "multicast_packets_sent_persec"), + "This counter represents the total number of multicast packets sent per second by the virtual switch", + nil, + nil, + ), + NumberofSendChannelMovesPersec: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "switch", "number_of_send_channel_moves_persec"), + "This counter represents the total number of send channel moves per second on this virtual switch", + nil, + nil, + ), + NumberofVMQMovesPersec: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "switch", "number_of_vmq_moves_persec"), + "This counter represents the total number of VMQ moves per second on this virtual switch", + nil, + nil, + ), + PacketsFlooded: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "switch", "packets_flooded"), + "This counter represents the total number of packets flooded by the virtual switch", + nil, + nil, + ), + PacketsFloodedPersec: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "switch", "packets_flooded_persec"), + "This counter represents the total number of packets flooded per second by the virtual switch", + nil, + nil, + ), + PacketsPersec: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "switch", "packets_persec"), + "This counter represents the total number of packets per second traversing the virtual switch", + nil, + nil, + ), + PacketsReceivedPersec: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "switch", "packets_received_persec"), + "This counter represents the total number of packets received per second by the virtual switch", + nil, + nil, + ), + PacketsSentPersec: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "switch", "packets_sent_persec"), + "This counter represents the total number of packets send per second by the virtual switch", + nil, + nil, + ), + PurgedMacAddresses: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "switch", "purged_mac_addresses"), + "This counter represents the total number of purged MAC addresses of the virtual switch", + nil, + nil, + ), + PurgedMacAddressesPersec: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "switch", "purged_mac_addresses_persec"), + "This counter represents the total number MAC addresses purged per second by the virtual switch", + nil, + nil, + ), + + // + + AdapterBytesDropped: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "ethernet", "bytes_persec"), + "Bytes Dropped is the number of bytes dropped on the network adapter", + nil, + nil, + ), + AdapterBytesReceivedPersec: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "ethernet", "bytes_received_persec"), + "Bytes Received/sec is the number of bytes received per second on the network adapter", + nil, + nil, + ), + AdapterBytesSentPersec: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "ethernet", "bytes_sent_persec"), + "Bytes Sent/sec is the number of bytes sent per second over the network adapter", + nil, + nil, + ), + AdapterFramesDropped: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "ethernet", "frames_dropped"), + "Frames Dropped is the number of frames dropped on the network adapter", + nil, + nil, + ), + AdapterFramesReceivedPersec: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "ethernet", "frames_received_persec"), + "Frames Received/sec is the number of frames received per second on the network adapter", + nil, + nil, + ), + AdapterFramesSentPersec: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "ethernet", "frames_sent_persec"), + "Frames Sent/sec is the number of frames sent per second over the network adapter", + nil, + nil, + ), + }, nil +} + +// Collect sends the metric values for each metric +// to the provided prometheus Metric channel. +func (c *HyperVCollector) Collect(ch chan<- prometheus.Metric) error { + if desc, err := c.collectVmHealth(ch); err != nil { + log.Println("[ERROR] failed collecting hyperV health status metrics:", desc, err) + return err + } + + if desc, err := c.collectVmVid(ch); err != nil { + log.Println("[ERROR] failed collecting hyperV pages metrics:", desc, err) + return err + } + + if desc, err := c.collectVmHv(ch); err != nil { + log.Println("[ERROR] failed collecting hyperV hv status metrics:", desc, err) + return err + } + + if desc, err := c.collectVmProcessor(ch); err != nil { + log.Println("[ERROR] failed collecting hyperV processor metrics:", desc, err) + return err + } + + if desc, err := c.collectVmRate(ch); err != nil { + log.Println("[ERROR] failed collecting hyperV rate metrics:", desc, err) + return err + } + + if desc, err := c.collectVmSwitch(ch); err != nil { + log.Println("[ERROR] failed collecting hyperV switch metrics:", desc, err) + return err + } + + if desc, err := c.collectVmEthernet(ch); err != nil { + log.Println("[ERROR] failed collecting hyperV ethernet metrics:", desc, err) + return err + } + return nil +} + +// Win32_PerfRawData_VmmsVirtualMachineStats_HyperVVirtualMachineHealthSummary vm health status +type Win32_PerfRawData_VmmsVirtualMachineStats_HyperVVirtualMachineHealthSummary struct { + HealthCritical uint32 + HealthOk uint32 +} + +func (c *HyperVCollector) collectVmHealth(ch chan<- prometheus.Metric) (*prometheus.Desc, error) { + var dst []Win32_PerfRawData_VmmsVirtualMachineStats_HyperVVirtualMachineHealthSummary + if err := wmi.Query(wmi.CreateQuery(&dst, ""), &dst); err != nil { + return nil, err + } + + for _, health := range dst { + ch <- prometheus.MustNewConstMetric( + c.HealthCritical, + prometheus.GaugeValue, + float64(health.HealthCritical), + ) + + ch <- prometheus.MustNewConstMetric( + c.HealthOk, + prometheus.GaugeValue, + float64(health.HealthOk), + ) + + } + + return nil, nil +} + +// Win32_PerfRawData_VidPerfProvider_HyperVVMVidPartition .., +type Win32_PerfRawData_VidPerfProvider_HyperVVMVidPartition struct { + Name string + PhysicalPagesAllocated uint64 + PreferredNUMANodeIndex uint64 + RemotePhysicalPages uint64 +} + +func (c *HyperVCollector) collectVmVid(ch chan<- prometheus.Metric) (*prometheus.Desc, error) { + var dst []Win32_PerfRawData_VidPerfProvider_HyperVVMVidPartition + if err := wmi.Query(wmi.CreateQuery(&dst, ""), &dst); err != nil { + return nil, err + } + + for _, page := range dst { + if strings.Contains(page.Name, "_Total") { + continue + } + + ch <- prometheus.MustNewConstMetric( + c.PhysicalPagesAllocated, + prometheus.GaugeValue, + float64(page.PhysicalPagesAllocated), + ) + + ch <- prometheus.MustNewConstMetric( + c.PreferredNUMANodeIndex, + prometheus.GaugeValue, + float64(page.PreferredNUMANodeIndex), + ) + + ch <- prometheus.MustNewConstMetric( + c.RemotePhysicalPages, + prometheus.GaugeValue, + float64(page.RemotePhysicalPages), + ) + + } + + return nil, nil +} + +// Win32_PerfRawData_HvStats_HyperVHypervisorRootPartition ... +type Win32_PerfRawData_HvStats_HyperVHypervisorRootPartition struct { + Name string + AddressSpaces uint64 + AttachedDevices uint64 + DepositedPages uint64 + DeviceDMAErrors uint64 + DeviceInterruptErrors uint64 + DeviceInterruptMappings uint64 + DeviceInterruptThrottleEvents uint64 + GPAPages uint64 + GPASpaceModificationsPersec uint64 + IOTLBFlushCost uint64 + IOTLBFlushesPersec uint64 + RecommendedVirtualTLBSize uint64 + SkippedTimerTicks uint64 + Value1Gdevicepages uint64 + Value1GGPApages uint64 + Value2Mdevicepages uint64 + Value2MGPApages uint64 + Value4Kdevicepages uint64 + Value4KGPApages uint64 + VirtualTLBFlushEntiresPersec uint64 + VirtualTLBPages uint64 +} + +func (c *HyperVCollector) collectVmHv(ch chan<- prometheus.Metric) (*prometheus.Desc, error) { + var dst []Win32_PerfRawData_HvStats_HyperVHypervisorRootPartition + if err := wmi.Query(wmi.CreateQuery(&dst, ""), &dst); err != nil { + return nil, err + } + + for _, obj := range dst { + if strings.Contains(obj.Name, "_Total") { + continue + } + + ch <- prometheus.MustNewConstMetric( + c.AddressSpaces, + prometheus.GaugeValue, + float64(obj.AddressSpaces), + ) + + ch <- prometheus.MustNewConstMetric( + c.AttachedDevices, + prometheus.GaugeValue, + float64(obj.AttachedDevices), + ) + + ch <- prometheus.MustNewConstMetric( + c.DepositedPages, + prometheus.GaugeValue, + float64(obj.DepositedPages), + ) + + ch <- prometheus.MustNewConstMetric( + c.DeviceDMAErrors, + prometheus.GaugeValue, + float64(obj.DeviceDMAErrors), + ) + + ch <- prometheus.MustNewConstMetric( + c.DeviceInterruptErrors, + prometheus.GaugeValue, + float64(obj.DeviceInterruptErrors), + ) + + ch <- prometheus.MustNewConstMetric( + c.DeviceInterruptThrottleEvents, + prometheus.GaugeValue, + float64(obj.DeviceInterruptThrottleEvents), + ) + + ch <- prometheus.MustNewConstMetric( + c.GPAPages, + prometheus.GaugeValue, + float64(obj.GPAPages), + ) + + ch <- prometheus.MustNewConstMetric( + c.GPASpaceModificationsPersec, + prometheus.GaugeValue, + float64(obj.GPASpaceModificationsPersec), + ) + + ch <- prometheus.MustNewConstMetric( + c.IOTLBFlushCost, + prometheus.GaugeValue, + float64(obj.IOTLBFlushCost), + ) + + ch <- prometheus.MustNewConstMetric( + c.IOTLBFlushesPersec, + prometheus.GaugeValue, + float64(obj.IOTLBFlushesPersec), + ) + + ch <- prometheus.MustNewConstMetric( + c.RecommendedVirtualTLBSize, + prometheus.GaugeValue, + float64(obj.RecommendedVirtualTLBSize), + ) + + ch <- prometheus.MustNewConstMetric( + c.SkippedTimerTicks, + prometheus.GaugeValue, + float64(obj.SkippedTimerTicks), + ) + + ch <- prometheus.MustNewConstMetric( + c.Value1Gdevicepages, + prometheus.GaugeValue, + float64(obj.Value1Gdevicepages), + ) + + ch <- prometheus.MustNewConstMetric( + c.Value1GGPApages, + prometheus.GaugeValue, + float64(obj.Value1GGPApages), + ) + + ch <- prometheus.MustNewConstMetric( + c.Value2Mdevicepages, + prometheus.GaugeValue, + float64(obj.Value2Mdevicepages), + ) + ch <- prometheus.MustNewConstMetric( + c.Value2MGPApages, + prometheus.GaugeValue, + float64(obj.Value2MGPApages), + ) + ch <- prometheus.MustNewConstMetric( + c.Value4Kdevicepages, + prometheus.GaugeValue, + float64(obj.Value4Kdevicepages), + ) + ch <- prometheus.MustNewConstMetric( + c.Value4KGPApages, + prometheus.GaugeValue, + float64(obj.Value4KGPApages), + ) + ch <- prometheus.MustNewConstMetric( + c.VirtualTLBFlushEntiresPersec, + prometheus.GaugeValue, + float64(obj.VirtualTLBFlushEntiresPersec), + ) + ch <- prometheus.MustNewConstMetric( + c.VirtualTLBPages, + prometheus.GaugeValue, + float64(obj.VirtualTLBPages), + ) + + } + + return nil, nil +} + +// Win32_PerfRawData_HvStats_HyperVHypervisor ... +type Win32_PerfRawData_HvStats_HyperVHypervisor struct { + LogicalProcessors uint64 + VirtualProcessors uint64 +} + +func (c *HyperVCollector) collectVmProcessor(ch chan<- prometheus.Metric) (*prometheus.Desc, error) { + var dst []Win32_PerfRawData_HvStats_HyperVHypervisor + if err := wmi.Query(wmi.CreateQuery(&dst, ""), &dst); err != nil { + return nil, err + } + + for _, obj := range dst { + + ch <- prometheus.MustNewConstMetric( + c.LogicalProcessors, + prometheus.GaugeValue, + float64(obj.LogicalProcessors), + ) + + ch <- prometheus.MustNewConstMetric( + c.VirtualProcessors, + prometheus.GaugeValue, + float64(obj.VirtualProcessors), + ) + + } + + return nil, nil +} + +// Win32_PerfRawData_HvStats_HyperVHypervisorRootVirtualProcessor ... +type Win32_PerfRawData_HvStats_HyperVHypervisorRootVirtualProcessor struct { + Name string + PercentGuestRunTime uint64 + PercentHypervisorRunTime uint64 + PercentRemoteRunTime uint64 + PercentTotalRunTime uint64 +} + +func (c *HyperVCollector) collectVmRate(ch chan<- prometheus.Metric) (*prometheus.Desc, error) { + var dst []Win32_PerfRawData_HvStats_HyperVHypervisorRootVirtualProcessor + if err := wmi.Query(wmi.CreateQuery(&dst, ""), &dst); err != nil { + return nil, err + } + + for _, obj := range dst { + if strings.Contains(obj.Name, "_Total") { + continue + } + // Root VP 3 + names := strings.Split(obj.Name, " ") + if len(names) == 0 { + continue + } + label := names[len(names)-1] + + ch <- prometheus.MustNewConstMetric( + c.PercentGuestRunTime, + prometheus.GaugeValue, + float64(obj.PercentGuestRunTime), + label, + ) + + ch <- prometheus.MustNewConstMetric( + c.PercentHypervisorRunTime, + prometheus.GaugeValue, + float64(obj.PercentHypervisorRunTime), + label, + ) + + ch <- prometheus.MustNewConstMetric( + c.PercentRemoteRunTime, + prometheus.GaugeValue, + float64(obj.PercentRemoteRunTime), + label, + ) + + ch <- prometheus.MustNewConstMetric( + c.PercentTotalRunTime, + prometheus.GaugeValue, + float64(obj.PercentTotalRunTime), + label, + ) + + } + + return nil, nil +} + +// Win32_PerfRawData_NvspSwitchStats_HyperVVirtualSwitch ... +type Win32_PerfRawData_NvspSwitchStats_HyperVVirtualSwitch struct { + Name string + BroadcastPacketsReceivedPersec uint64 + BroadcastPacketsSentPersec uint64 + BytesPersec uint64 + BytesReceivedPersec uint64 + BytesSentPersec uint64 + DirectedPacketsReceivedPersec uint64 + DirectedPacketsSentPersec uint64 + DroppedPacketsIncomingPersec uint64 + DroppedPacketsOutgoingPersec uint64 + ExtensionsDroppedPacketsIncomingPersec uint64 + ExtensionsDroppedPacketsOutgoingPersec uint64 + LearnedMacAddresses uint64 + LearnedMacAddressesPersec uint64 + MulticastPacketsReceivedPersec uint64 + MulticastPacketsSentPersec uint64 + NumberofSendChannelMovesPersec uint64 + NumberofVMQMovesPersec uint64 + PacketsFlooded uint64 + PacketsFloodedPersec uint64 + PacketsPersec uint64 + PacketsReceivedPersec uint64 + PacketsSentPersec uint64 + PurgedMacAddresses uint64 + PurgedMacAddressesPersec uint64 +} + +func (c *HyperVCollector) collectVmSwitch(ch chan<- prometheus.Metric) (*prometheus.Desc, error) { + var dst []Win32_PerfRawData_NvspSwitchStats_HyperVVirtualSwitch + if err := wmi.Query(wmi.CreateQuery(&dst, ""), &dst); err != nil { + return nil, err + } + + for _, obj := range dst { + if strings.Contains(obj.Name, "_Total") { + continue + } + + ch <- prometheus.MustNewConstMetric( + c.BroadcastPacketsReceivedPersec, + prometheus.GaugeValue, + float64(obj.BroadcastPacketsReceivedPersec), + ) + + ch <- prometheus.MustNewConstMetric( + c.BroadcastPacketsSentPersec, + prometheus.GaugeValue, + float64(obj.BroadcastPacketsSentPersec), + ) + + ch <- prometheus.MustNewConstMetric( + c.BytesPersec, + prometheus.GaugeValue, + float64(obj.BytesPersec), + ) + + ch <- prometheus.MustNewConstMetric( + c.BytesReceivedPersec, + prometheus.GaugeValue, + float64(obj.BytesReceivedPersec), + ) + + ch <- prometheus.MustNewConstMetric( + c.BytesSentPersec, + prometheus.GaugeValue, + float64(obj.BytesSentPersec), + ) + + ch <- prometheus.MustNewConstMetric( + c.DirectedPacketsReceivedPersec, + prometheus.GaugeValue, + float64(obj.DirectedPacketsReceivedPersec), + ) + ch <- prometheus.MustNewConstMetric( + c.DirectedPacketsSentPersec, + prometheus.GaugeValue, + float64(obj.DirectedPacketsSentPersec), + ) + + ch <- prometheus.MustNewConstMetric( + c.DroppedPacketsIncomingPersec, + prometheus.GaugeValue, + float64(obj.DroppedPacketsIncomingPersec), + ) + ch <- prometheus.MustNewConstMetric( + c.DroppedPacketsOutgoingPersec, + prometheus.GaugeValue, + float64(obj.DroppedPacketsOutgoingPersec), + ) + ch <- prometheus.MustNewConstMetric( + c.ExtensionsDroppedPacketsIncomingPersec, + prometheus.GaugeValue, + float64(obj.ExtensionsDroppedPacketsIncomingPersec), + ) + ch <- prometheus.MustNewConstMetric( + c.ExtensionsDroppedPacketsOutgoingPersec, + prometheus.GaugeValue, + float64(obj.ExtensionsDroppedPacketsOutgoingPersec), + ) + + ch <- prometheus.MustNewConstMetric( + c.LearnedMacAddresses, + prometheus.GaugeValue, + float64(obj.LearnedMacAddresses), + ) + ch <- prometheus.MustNewConstMetric( + c.LearnedMacAddressesPersec, + prometheus.GaugeValue, + float64(obj.LearnedMacAddressesPersec), + ) + ch <- prometheus.MustNewConstMetric( + c.MulticastPacketsReceivedPersec, + prometheus.GaugeValue, + float64(obj.MulticastPacketsReceivedPersec), + ) + ch <- prometheus.MustNewConstMetric( + c.MulticastPacketsSentPersec, + prometheus.GaugeValue, + float64(obj.MulticastPacketsSentPersec), + ) + ch <- prometheus.MustNewConstMetric( + c.NumberofSendChannelMovesPersec, + prometheus.GaugeValue, + float64(obj.NumberofSendChannelMovesPersec), + ) + ch <- prometheus.MustNewConstMetric( + c.NumberofVMQMovesPersec, + prometheus.GaugeValue, + float64(obj.NumberofVMQMovesPersec), + ) + + // ... + ch <- prometheus.MustNewConstMetric( + c.PacketsFlooded, + prometheus.GaugeValue, + float64(obj.PacketsFlooded), + ) + + ch <- prometheus.MustNewConstMetric( + c.PacketsFloodedPersec, + prometheus.GaugeValue, + float64(obj.PacketsFloodedPersec), + ) + + ch <- prometheus.MustNewConstMetric( + c.PacketsPersec, + prometheus.GaugeValue, + float64(obj.PacketsPersec), + ) + + ch <- prometheus.MustNewConstMetric( + c.PacketsReceivedPersec, + prometheus.GaugeValue, + float64(obj.PacketsReceivedPersec), + ) + ch <- prometheus.MustNewConstMetric( + c.PurgedMacAddresses, + prometheus.GaugeValue, + float64(obj.PurgedMacAddresses), + ) + + ch <- prometheus.MustNewConstMetric( + c.PurgedMacAddressesPersec, + prometheus.GaugeValue, + float64(obj.PurgedMacAddressesPersec), + ) + + } + + return nil, nil +} + +// Win32_PerfRawData_EthernetPerfProvider_HyperVLegacyNetworkAdapter ... +type Win32_PerfRawData_EthernetPerfProvider_HyperVLegacyNetworkAdapter struct { + Name string + BytesDropped uint64 + BytesReceivedPersec uint64 + BytesSentPersec uint64 + FramesDropped uint64 + FramesReceivedPersec uint64 + FramesSentPersec uint64 +} + +func (c *HyperVCollector) collectVmEthernet(ch chan<- prometheus.Metric) (*prometheus.Desc, error) { + var dst []Win32_PerfRawData_EthernetPerfProvider_HyperVLegacyNetworkAdapter + if err := wmi.Query(wmi.CreateQuery(&dst, ""), &dst); err != nil { + return nil, err + } + + for _, obj := range dst { + if strings.Contains(obj.Name, "_Total") { + continue + } + + ch <- prometheus.MustNewConstMetric( + c.AdapterBytesDropped, + prometheus.GaugeValue, + float64(obj.BytesDropped), + ) + + ch <- prometheus.MustNewConstMetric( + c.AdapterBytesReceivedPersec, + prometheus.GaugeValue, + float64(obj.BytesReceivedPersec), + ) + + ch <- prometheus.MustNewConstMetric( + c.AdapterBytesSentPersec, + prometheus.GaugeValue, + float64(obj.BytesSentPersec), + ) + + ch <- prometheus.MustNewConstMetric( + c.AdapterFramesReceivedPersec, + prometheus.GaugeValue, + float64(obj.FramesReceivedPersec), + ) + + ch <- prometheus.MustNewConstMetric( + c.AdapterFramesDropped, + prometheus.GaugeValue, + float64(obj.BytesSentPersec), + ) + + ch <- prometheus.MustNewConstMetric( + c.AdapterFramesSentPersec, + prometheus.GaugeValue, + float64(obj.FramesSentPersec), + ) + + } + + return nil, nil +} From afa17b2a1b36a16f8634e0dff0dcc4064bed167b Mon Sep 17 00:00:00 2001 From: ghj Date: Wed, 24 Jan 2018 11:05:42 +0800 Subject: [PATCH 2/8] rename some metrics that maybe misleading --- collector/hyperv.go | 90 ++++++++++++++++++++++----------------------- 1 file changed, 45 insertions(+), 45 deletions(-) diff --git a/collector/hyperv.go b/collector/hyperv.go index 35ad3385..6e8d4d43 100644 --- a/collector/hyperv.go +++ b/collector/hyperv.go @@ -301,68 +301,68 @@ func NewHyperVCollector() (Collector, error) { // BroadcastPacketsReceivedPersec: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "switch", "broadcast_packets_received_persec"), - "This counter represents the total number of broadcast packets received per second by the virtual switch", + prometheus.BuildFQName(Namespace, "switch", "broadcast_packets_received_total_persec"), + "This represents the total number of broadcast packets received per second by the virtual switch", nil, nil, ), BroadcastPacketsSentPersec: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "switch", "broadcast_packets_sent_persec"), - "This counter represents the total number of broadcast packets sent per second by the virtual switch", + prometheus.BuildFQName(Namespace, "switch", "broadcast_packets_sent_total_persec"), + "This represents the total number of broadcast packets sent per second by the virtual switch", nil, nil, ), BytesPersec: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "switch", "bytes_persec"), - "This counter represents the total number of bytes per second traversing the virtual switch", + prometheus.BuildFQName(Namespace, "switch", "bytes_total_persec"), + "This represents the total number of bytes per second traversing the virtual switch", nil, nil, ), BytesReceivedPersec: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "switch", "bytes_received_persec"), - "This counter represents the total number of bytes received per second by the virtual switch", + prometheus.BuildFQName(Namespace, "switch", "bytes_received_total_persec"), + "This represents the total number of bytes received per second by the virtual switch", nil, nil, ), BytesSentPersec: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "switch", "bytes_sent_persec"), - "This counter represents the total number of bytes sent per second by the virtual switch", + prometheus.BuildFQName(Namespace, "switch", "bytes_sent_total_persec"), + "This represents the total number of bytes sent per second by the virtual switch", nil, nil, ), DirectedPacketsReceivedPersec: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "switch", "directed_packets_received_persec"), - "This counter represents the total number of directed packets received per second by the virtual switch", + prometheus.BuildFQName(Namespace, "switch", "directed_packets_received_total_persec"), + "This represents the total number of directed packets received per second by the virtual switch", nil, nil, ), DirectedPacketsSentPersec: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "switch", "directed_packets_send_persec"), - "This counter represents the total number of directed packets sent per second by the virtual switch", + prometheus.BuildFQName(Namespace, "switch", "directed_packets_send_total_persec"), + "This represents the total number of directed packets sent per second by the virtual switch", nil, nil, ), DroppedPacketsIncomingPersec: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "switch", "dropped_packets_incoming_persec"), - "This counter represents the total number of packet dropped per second by the virtual switch in the incoming direction", + prometheus.BuildFQName(Namespace, "switch", "dropped_packets_incoming_total_persec"), + "This represents the total number of packet dropped per second by the virtual switch in the incoming direction", nil, nil, ), DroppedPacketsOutgoingPersec: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "switch", "dropped_packets_outcoming_persec"), - "This counter represents the total number of packet dropped per second by the virtual switch in the outgoing direction", + prometheus.BuildFQName(Namespace, "switch", "dropped_packets_outcoming_total_persec"), + "This represents the total number of packet dropped per second by the virtual switch in the outgoing direction", nil, nil, ), ExtensionsDroppedPacketsIncomingPersec: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "switch", "extensions_dropped_packets_incoming_persec"), - "This counter represents the total number of packet dropped per second by the virtual switch extensions in the incoming direction", + prometheus.BuildFQName(Namespace, "switch", "extensions_dropped_packets_incoming_total_persec"), + "This represents the total number of packet dropped per second by the virtual switch extensions in the incoming direction", nil, nil, ), ExtensionsDroppedPacketsOutgoingPersec: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "switch", "extensions_dropped_packets_outcoming_persec"), - "This counter represents the total number of packet dropped per second by the virtual switch extensions in the outgoing direction", + prometheus.BuildFQName(Namespace, "switch", "extensions_dropped_packets_outcoming_total_persec"), + "This represents the total number of packet dropped per second by the virtual switch extensions in the outgoing direction", nil, nil, ), @@ -373,32 +373,32 @@ func NewHyperVCollector() (Collector, error) { nil, ), LearnedMacAddressesPersec: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "switch", "learned_mac_addresses_persec"), - "This counter represents the total number MAC addresses learned per second by the virtual switch", + prometheus.BuildFQName(Namespace, "switch", "learned_mac_addresses_total_persec"), + "This represents the total number MAC addresses learned per second by the virtual switch", nil, nil, ), MulticastPacketsReceivedPersec: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "switch", "multicast_packets_received_persec"), - "This counter represents the total number of multicast packets received per second by the virtual switch", + prometheus.BuildFQName(Namespace, "switch", "multicast_packets_received_total_persec"), + "This represents the total number of multicast packets received per second by the virtual switch", nil, nil, ), MulticastPacketsSentPersec: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "switch", "multicast_packets_sent_persec"), - "This counter represents the total number of multicast packets sent per second by the virtual switch", + prometheus.BuildFQName(Namespace, "switch", "multicast_packets_sent_total_persec"), + "This represents the total number of multicast packets sent per second by the virtual switch", nil, nil, ), NumberofSendChannelMovesPersec: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "switch", "number_of_send_channel_moves_persec"), - "This counter represents the total number of send channel moves per second on this virtual switch", + prometheus.BuildFQName(Namespace, "switch", "number_of_send_channel_moves_total_persec"), + "This represents the total number of send channel moves per second on this virtual switch", nil, nil, ), NumberofVMQMovesPersec: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "switch", "number_of_vmq_moves_persec"), - "This counter represents the total number of VMQ moves per second on this virtual switch", + prometheus.BuildFQName(Namespace, "switch", "number_of_vmq_moves_total_persec"), + "This represents the total number of VMQ moves per second on this virtual switch", nil, nil, ), @@ -409,26 +409,26 @@ func NewHyperVCollector() (Collector, error) { nil, ), PacketsFloodedPersec: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "switch", "packets_flooded_persec"), - "This counter represents the total number of packets flooded per second by the virtual switch", + prometheus.BuildFQName(Namespace, "switch", "packets_flooded_total_persec"), + "This represents the total number of packets flooded per second by the virtual switch", nil, nil, ), PacketsPersec: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "switch", "packets_persec"), - "This counter represents the total number of packets per second traversing the virtual switch", + prometheus.BuildFQName(Namespace, "switch", "packets_total_persec"), + "This represents the total number of packets per second traversing the virtual switch", nil, nil, ), PacketsReceivedPersec: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "switch", "packets_received_persec"), - "This counter represents the total number of packets received per second by the virtual switch", + prometheus.BuildFQName(Namespace, "switch", "packets_received_total_persec"), + "This represents the total number of packets received per second by the virtual switch", nil, nil, ), PacketsSentPersec: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "switch", "packets_sent_persec"), - "This counter represents the total number of packets send per second by the virtual switch", + prometheus.BuildFQName(Namespace, "switch", "packets_sent_total_persec"), + "This represents the total number of packets send per second by the virtual switch", nil, nil, ), @@ -439,8 +439,8 @@ func NewHyperVCollector() (Collector, error) { nil, ), PurgedMacAddressesPersec: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "switch", "purged_mac_addresses_persec"), - "This counter represents the total number MAC addresses purged per second by the virtual switch", + prometheus.BuildFQName(Namespace, "switch", "purged_mac_addresses_total_persec"), + "This represents the total number MAC addresses purged per second by the virtual switch", nil, nil, ), @@ -949,7 +949,7 @@ func (c *HyperVCollector) collectVmSwitch(ch chan<- prometheus.Metric) (*prometh ch <- prometheus.MustNewConstMetric( c.LearnedMacAddresses, - prometheus.GaugeValue, + prometheus.CounterValue, float64(obj.LearnedMacAddresses), ) ch <- prometheus.MustNewConstMetric( @@ -981,7 +981,7 @@ func (c *HyperVCollector) collectVmSwitch(ch chan<- prometheus.Metric) (*prometh // ... ch <- prometheus.MustNewConstMetric( c.PacketsFlooded, - prometheus.GaugeValue, + prometheus.CounterValue, float64(obj.PacketsFlooded), ) @@ -1004,7 +1004,7 @@ func (c *HyperVCollector) collectVmSwitch(ch chan<- prometheus.Metric) (*prometh ) ch <- prometheus.MustNewConstMetric( c.PurgedMacAddresses, - prometheus.GaugeValue, + prometheus.CounterValue, float64(obj.PurgedMacAddresses), ) From 353de09798a877c4847528dd7119d169664e39dd Mon Sep 17 00:00:00 2001 From: Calle Pettersson Date: Mon, 16 Apr 2018 20:39:01 +0200 Subject: [PATCH 3/8] Remove/rename persec metrics --- collector/hyperv.go | 307 +++++++++++++++++++------------------------- 1 file changed, 134 insertions(+), 173 deletions(-) diff --git a/collector/hyperv.go b/collector/hyperv.go index 6e8d4d43..c4281471 100644 --- a/collector/hyperv.go +++ b/collector/hyperv.go @@ -32,9 +32,9 @@ type HyperVCollector struct { DeviceInterruptMappings *prometheus.Desc DeviceInterruptThrottleEvents *prometheus.Desc GPAPages *prometheus.Desc - GPASpaceModificationsPersec *prometheus.Desc + GPASpaceModifications *prometheus.Desc IOTLBFlushCost *prometheus.Desc - IOTLBFlushesPersec *prometheus.Desc + IOTLBFlushes *prometheus.Desc RecommendedVirtualTLBSize *prometheus.Desc SkippedTimerTicks *prometheus.Desc Value1Gdevicepages *prometheus.Desc @@ -43,7 +43,7 @@ type HyperVCollector struct { Value2MGPApages *prometheus.Desc Value4Kdevicepages *prometheus.Desc Value4KGPApages *prometheus.Desc - VirtualTLBFlushEntiresPersec *prometheus.Desc + VirtualTLBFlushEntires *prometheus.Desc VirtualTLBPages *prometheus.Desc // Win32_PerfRawData_HvStats_HyperVHypervisor @@ -57,38 +57,35 @@ type HyperVCollector struct { PercentTotalRunTime *prometheus.Desc // Win32_PerfRawData_NvspSwitchStats_HyperVVirtualSwitch - BroadcastPacketsReceivedPersec *prometheus.Desc - BroadcastPacketsSentPersec *prometheus.Desc - BytesPersec *prometheus.Desc - BytesReceivedPersec *prometheus.Desc - BytesSentPersec *prometheus.Desc - DirectedPacketsReceivedPersec *prometheus.Desc - DirectedPacketsSentPersec *prometheus.Desc - DroppedPacketsIncomingPersec *prometheus.Desc - DroppedPacketsOutgoingPersec *prometheus.Desc - ExtensionsDroppedPacketsIncomingPersec *prometheus.Desc - ExtensionsDroppedPacketsOutgoingPersec *prometheus.Desc - LearnedMacAddresses *prometheus.Desc - LearnedMacAddressesPersec *prometheus.Desc - MulticastPacketsReceivedPersec *prometheus.Desc - MulticastPacketsSentPersec *prometheus.Desc - NumberofSendChannelMovesPersec *prometheus.Desc - NumberofVMQMovesPersec *prometheus.Desc - PacketsFlooded *prometheus.Desc - PacketsFloodedPersec *prometheus.Desc - PacketsPersec *prometheus.Desc - PacketsReceivedPersec *prometheus.Desc - PacketsSentPersec *prometheus.Desc - PurgedMacAddresses *prometheus.Desc - PurgedMacAddressesPersec *prometheus.Desc + BroadcastPacketsReceived *prometheus.Desc + BroadcastPacketsSent *prometheus.Desc + Bytes *prometheus.Desc + BytesReceived *prometheus.Desc + BytesSent *prometheus.Desc + DirectedPacketsReceived *prometheus.Desc + DirectedPacketsSent *prometheus.Desc + DroppedPacketsIncoming *prometheus.Desc + DroppedPacketsOutgoing *prometheus.Desc + ExtensionsDroppedPacketsIncoming *prometheus.Desc + ExtensionsDroppedPacketsOutgoing *prometheus.Desc + LearnedMacAddresses *prometheus.Desc + MulticastPacketsReceived *prometheus.Desc + MulticastPacketsSent *prometheus.Desc + NumberofSendChannelMoves *prometheus.Desc + NumberofVMQMoves *prometheus.Desc + PacketsFlooded *prometheus.Desc + Packets *prometheus.Desc + PacketsReceived *prometheus.Desc + PacketsSent *prometheus.Desc + PurgedMacAddresses *prometheus.Desc // Win32_PerfRawData_EthernetPerfProvider_HyperVLegacyNetworkAdapter - AdapterBytesDropped *prometheus.Desc - AdapterBytesReceivedPersec *prometheus.Desc - AdapterBytesSentPersec *prometheus.Desc - AdapterFramesDropped *prometheus.Desc - AdapterFramesReceivedPersec *prometheus.Desc - AdapterFramesSentPersec *prometheus.Desc + AdapterBytesDropped *prometheus.Desc + AdapterBytesReceived *prometheus.Desc + AdapterBytesSent *prometheus.Desc + AdapterFramesDropped *prometheus.Desc + AdapterFramesReceived *prometheus.Desc + AdapterFramesSent *prometheus.Desc } // NewHyperVCollector ... @@ -178,8 +175,8 @@ func NewHyperVCollector() (Collector, error) { nil, nil, ), - GPASpaceModificationsPersec: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "hv", "gpa_space_modifications_persec"), + GPASpaceModifications: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "hv", "gpa_space_modifications"), "The rate of modifications to the GPA space of the partition", nil, nil, @@ -190,8 +187,8 @@ func NewHyperVCollector() (Collector, error) { nil, nil, ), - IOTLBFlushesPersec: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "hv", "io_tlb_flush_persec"), + IOTLBFlushes: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "hv", "io_tlb_flush"), "The rate of flushes of I/O TLBs of the partition", nil, nil, @@ -244,8 +241,8 @@ func NewHyperVCollector() (Collector, error) { nil, nil, ), - VirtualTLBFlushEntiresPersec: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "hv", "virtual_tlb_flush_entires_persec"), + VirtualTLBFlushEntires: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "hv", "virtual_tlb_flush_entires"), "The rate of flushes of the entire virtual TLB", nil, nil, @@ -300,167 +297,149 @@ func NewHyperVCollector() (Collector, error) { ), // - BroadcastPacketsReceivedPersec: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "switch", "broadcast_packets_received_total_persec"), + BroadcastPacketsReceived: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "switch", "broadcast_packets_received_total"), "This represents the total number of broadcast packets received per second by the virtual switch", nil, nil, ), - BroadcastPacketsSentPersec: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "switch", "broadcast_packets_sent_total_persec"), + BroadcastPacketsSent: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "switch", "broadcast_packets_sent_total"), "This represents the total number of broadcast packets sent per second by the virtual switch", nil, nil, ), - BytesPersec: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "switch", "bytes_total_persec"), + Bytes: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "switch", "bytes_total"), "This represents the total number of bytes per second traversing the virtual switch", nil, nil, ), - BytesReceivedPersec: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "switch", "bytes_received_total_persec"), + BytesReceived: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "switch", "bytes_received_total"), "This represents the total number of bytes received per second by the virtual switch", nil, nil, ), - BytesSentPersec: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "switch", "bytes_sent_total_persec"), + BytesSent: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "switch", "bytes_sent_total"), "This represents the total number of bytes sent per second by the virtual switch", nil, nil, ), - DirectedPacketsReceivedPersec: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "switch", "directed_packets_received_total_persec"), + DirectedPacketsReceived: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "switch", "directed_packets_received_total"), "This represents the total number of directed packets received per second by the virtual switch", nil, nil, ), - DirectedPacketsSentPersec: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "switch", "directed_packets_send_total_persec"), + DirectedPacketsSent: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "switch", "directed_packets_send_total"), "This represents the total number of directed packets sent per second by the virtual switch", nil, nil, ), - DroppedPacketsIncomingPersec: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "switch", "dropped_packets_incoming_total_persec"), + DroppedPacketsIncoming: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "switch", "dropped_packets_incoming_total"), "This represents the total number of packet dropped per second by the virtual switch in the incoming direction", nil, nil, ), - DroppedPacketsOutgoingPersec: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "switch", "dropped_packets_outcoming_total_persec"), + DroppedPacketsOutgoing: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "switch", "dropped_packets_outcoming_total"), "This represents the total number of packet dropped per second by the virtual switch in the outgoing direction", nil, nil, ), - ExtensionsDroppedPacketsIncomingPersec: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "switch", "extensions_dropped_packets_incoming_total_persec"), + ExtensionsDroppedPacketsIncoming: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "switch", "extensions_dropped_packets_incoming_total"), "This represents the total number of packet dropped per second by the virtual switch extensions in the incoming direction", nil, nil, ), - ExtensionsDroppedPacketsOutgoingPersec: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "switch", "extensions_dropped_packets_outcoming_total_persec"), + ExtensionsDroppedPacketsOutgoing: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "switch", "extensions_dropped_packets_outcoming_total"), "This represents the total number of packet dropped per second by the virtual switch extensions in the outgoing direction", nil, nil, ), LearnedMacAddresses: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "switch", "learned_mac_addresses"), + prometheus.BuildFQName(Namespace, "switch", "learned_mac_addresses_total"), "This counter represents the total number of learned MAC addresses of the virtual switch", nil, nil, ), - LearnedMacAddressesPersec: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "switch", "learned_mac_addresses_total_persec"), - "This represents the total number MAC addresses learned per second by the virtual switch", - nil, - nil, - ), - MulticastPacketsReceivedPersec: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "switch", "multicast_packets_received_total_persec"), + MulticastPacketsReceived: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "switch", "multicast_packets_received_total"), "This represents the total number of multicast packets received per second by the virtual switch", nil, nil, ), - MulticastPacketsSentPersec: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "switch", "multicast_packets_sent_total_persec"), + MulticastPacketsSent: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "switch", "multicast_packets_sent_total"), "This represents the total number of multicast packets sent per second by the virtual switch", nil, nil, ), - NumberofSendChannelMovesPersec: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "switch", "number_of_send_channel_moves_total_persec"), + NumberofSendChannelMoves: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "switch", "number_of_send_channel_moves_total"), "This represents the total number of send channel moves per second on this virtual switch", nil, nil, ), - NumberofVMQMovesPersec: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "switch", "number_of_vmq_moves_total_persec"), + NumberofVMQMoves: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "switch", "number_of_vmq_moves_total"), "This represents the total number of VMQ moves per second on this virtual switch", nil, nil, ), PacketsFlooded: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "switch", "packets_flooded"), + prometheus.BuildFQName(Namespace, "switch", "packets_flooded_total"), "This counter represents the total number of packets flooded by the virtual switch", nil, nil, ), - PacketsFloodedPersec: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "switch", "packets_flooded_total_persec"), - "This represents the total number of packets flooded per second by the virtual switch", - nil, - nil, - ), - PacketsPersec: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "switch", "packets_total_persec"), + Packets: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "switch", "packets_total"), "This represents the total number of packets per second traversing the virtual switch", nil, nil, ), - PacketsReceivedPersec: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "switch", "packets_received_total_persec"), + PacketsReceived: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "switch", "packets_received_total"), "This represents the total number of packets received per second by the virtual switch", nil, nil, ), - PacketsSentPersec: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "switch", "packets_sent_total_persec"), + PacketsSent: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "switch", "packets_sent_total"), "This represents the total number of packets send per second by the virtual switch", nil, nil, ), PurgedMacAddresses: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "switch", "purged_mac_addresses"), + prometheus.BuildFQName(Namespace, "switch", "purged_mac_addresses_total"), "This counter represents the total number of purged MAC addresses of the virtual switch", nil, nil, ), - PurgedMacAddressesPersec: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "switch", "purged_mac_addresses_total_persec"), - "This represents the total number MAC addresses purged per second by the virtual switch", - nil, - nil, - ), // AdapterBytesDropped: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "ethernet", "bytes_persec"), + prometheus.BuildFQName(Namespace, "ethernet", "bytes"), "Bytes Dropped is the number of bytes dropped on the network adapter", nil, nil, ), - AdapterBytesReceivedPersec: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "ethernet", "bytes_received_persec"), + AdapterBytesReceived: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "ethernet", "bytes_received"), "Bytes Received/sec is the number of bytes received per second on the network adapter", nil, nil, ), - AdapterBytesSentPersec: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "ethernet", "bytes_sent_persec"), + AdapterBytesSent: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "ethernet", "bytes_sent"), "Bytes Sent/sec is the number of bytes sent per second over the network adapter", nil, nil, @@ -471,14 +450,14 @@ func NewHyperVCollector() (Collector, error) { nil, nil, ), - AdapterFramesReceivedPersec: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "ethernet", "frames_received_persec"), + AdapterFramesReceived: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "ethernet", "frames_received"), "Frames Received/sec is the number of frames received per second on the network adapter", nil, nil, ), - AdapterFramesSentPersec: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "ethernet", "frames_sent_persec"), + AdapterFramesSent: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "ethernet", "frames_sent"), "Frames Sent/sec is the number of frames sent per second over the network adapter", nil, nil, @@ -678,8 +657,8 @@ func (c *HyperVCollector) collectVmHv(ch chan<- prometheus.Metric) (*prometheus. ) ch <- prometheus.MustNewConstMetric( - c.GPASpaceModificationsPersec, - prometheus.GaugeValue, + c.GPASpaceModifications, + prometheus.CounterValue, float64(obj.GPASpaceModificationsPersec), ) @@ -690,8 +669,8 @@ func (c *HyperVCollector) collectVmHv(ch chan<- prometheus.Metric) (*prometheus. ) ch <- prometheus.MustNewConstMetric( - c.IOTLBFlushesPersec, - prometheus.GaugeValue, + c.IOTLBFlushes, + prometheus.CounterValue, float64(obj.IOTLBFlushesPersec), ) @@ -740,8 +719,8 @@ func (c *HyperVCollector) collectVmHv(ch chan<- prometheus.Metric) (*prometheus. float64(obj.Value4KGPApages), ) ch <- prometheus.MustNewConstMetric( - c.VirtualTLBFlushEntiresPersec, - prometheus.GaugeValue, + c.VirtualTLBFlushEntires, + prometheus.CounterValue, float64(obj.VirtualTLBFlushEntiresPersec), ) ch <- prometheus.MustNewConstMetric( @@ -886,64 +865,64 @@ func (c *HyperVCollector) collectVmSwitch(ch chan<- prometheus.Metric) (*prometh } ch <- prometheus.MustNewConstMetric( - c.BroadcastPacketsReceivedPersec, - prometheus.GaugeValue, + c.BroadcastPacketsReceived, + prometheus.CounterValue, float64(obj.BroadcastPacketsReceivedPersec), ) ch <- prometheus.MustNewConstMetric( - c.BroadcastPacketsSentPersec, - prometheus.GaugeValue, + c.BroadcastPacketsSent, + prometheus.CounterValue, float64(obj.BroadcastPacketsSentPersec), ) ch <- prometheus.MustNewConstMetric( - c.BytesPersec, - prometheus.GaugeValue, + c.Bytes, + prometheus.CounterValue, float64(obj.BytesPersec), ) ch <- prometheus.MustNewConstMetric( - c.BytesReceivedPersec, - prometheus.GaugeValue, + c.BytesReceived, + prometheus.CounterValue, float64(obj.BytesReceivedPersec), ) ch <- prometheus.MustNewConstMetric( - c.BytesSentPersec, - prometheus.GaugeValue, + c.BytesSent, + prometheus.CounterValue, float64(obj.BytesSentPersec), ) ch <- prometheus.MustNewConstMetric( - c.DirectedPacketsReceivedPersec, - prometheus.GaugeValue, + c.DirectedPacketsReceived, + prometheus.CounterValue, float64(obj.DirectedPacketsReceivedPersec), ) ch <- prometheus.MustNewConstMetric( - c.DirectedPacketsSentPersec, - prometheus.GaugeValue, + c.DirectedPacketsSent, + prometheus.CounterValue, float64(obj.DirectedPacketsSentPersec), ) ch <- prometheus.MustNewConstMetric( - c.DroppedPacketsIncomingPersec, - prometheus.GaugeValue, + c.DroppedPacketsIncoming, + prometheus.CounterValue, float64(obj.DroppedPacketsIncomingPersec), ) ch <- prometheus.MustNewConstMetric( - c.DroppedPacketsOutgoingPersec, - prometheus.GaugeValue, + c.DroppedPacketsOutgoing, + prometheus.CounterValue, float64(obj.DroppedPacketsOutgoingPersec), ) ch <- prometheus.MustNewConstMetric( - c.ExtensionsDroppedPacketsIncomingPersec, - prometheus.GaugeValue, + c.ExtensionsDroppedPacketsIncoming, + prometheus.CounterValue, float64(obj.ExtensionsDroppedPacketsIncomingPersec), ) ch <- prometheus.MustNewConstMetric( - c.ExtensionsDroppedPacketsOutgoingPersec, - prometheus.GaugeValue, + c.ExtensionsDroppedPacketsOutgoing, + prometheus.CounterValue, float64(obj.ExtensionsDroppedPacketsOutgoingPersec), ) @@ -953,28 +932,23 @@ func (c *HyperVCollector) collectVmSwitch(ch chan<- prometheus.Metric) (*prometh float64(obj.LearnedMacAddresses), ) ch <- prometheus.MustNewConstMetric( - c.LearnedMacAddressesPersec, - prometheus.GaugeValue, - float64(obj.LearnedMacAddressesPersec), - ) - ch <- prometheus.MustNewConstMetric( - c.MulticastPacketsReceivedPersec, - prometheus.GaugeValue, + c.MulticastPacketsReceived, + prometheus.CounterValue, float64(obj.MulticastPacketsReceivedPersec), ) ch <- prometheus.MustNewConstMetric( - c.MulticastPacketsSentPersec, - prometheus.GaugeValue, + c.MulticastPacketsSent, + prometheus.CounterValue, float64(obj.MulticastPacketsSentPersec), ) ch <- prometheus.MustNewConstMetric( - c.NumberofSendChannelMovesPersec, - prometheus.GaugeValue, + c.NumberofSendChannelMoves, + prometheus.CounterValue, float64(obj.NumberofSendChannelMovesPersec), ) ch <- prometheus.MustNewConstMetric( - c.NumberofVMQMovesPersec, - prometheus.GaugeValue, + c.NumberofVMQMoves, + prometheus.CounterValue, float64(obj.NumberofVMQMovesPersec), ) @@ -986,20 +960,14 @@ func (c *HyperVCollector) collectVmSwitch(ch chan<- prometheus.Metric) (*prometh ) ch <- prometheus.MustNewConstMetric( - c.PacketsFloodedPersec, - prometheus.GaugeValue, - float64(obj.PacketsFloodedPersec), - ) - - ch <- prometheus.MustNewConstMetric( - c.PacketsPersec, - prometheus.GaugeValue, + c.Packets, + prometheus.CounterValue, float64(obj.PacketsPersec), ) ch <- prometheus.MustNewConstMetric( - c.PacketsReceivedPersec, - prometheus.GaugeValue, + c.PacketsReceived, + prometheus.CounterValue, float64(obj.PacketsReceivedPersec), ) ch <- prometheus.MustNewConstMetric( @@ -1007,13 +975,6 @@ func (c *HyperVCollector) collectVmSwitch(ch chan<- prometheus.Metric) (*prometh prometheus.CounterValue, float64(obj.PurgedMacAddresses), ) - - ch <- prometheus.MustNewConstMetric( - c.PurgedMacAddressesPersec, - prometheus.GaugeValue, - float64(obj.PurgedMacAddressesPersec), - ) - } return nil, nil @@ -1048,32 +1009,32 @@ func (c *HyperVCollector) collectVmEthernet(ch chan<- prometheus.Metric) (*prome ) ch <- prometheus.MustNewConstMetric( - c.AdapterBytesReceivedPersec, - prometheus.GaugeValue, + c.AdapterBytesReceived, + prometheus.CounterValue, float64(obj.BytesReceivedPersec), ) ch <- prometheus.MustNewConstMetric( - c.AdapterBytesSentPersec, - prometheus.GaugeValue, + c.AdapterBytesSent, + prometheus.CounterValue, float64(obj.BytesSentPersec), ) ch <- prometheus.MustNewConstMetric( - c.AdapterFramesReceivedPersec, - prometheus.GaugeValue, + c.AdapterFramesReceived, + prometheus.CounterValue, float64(obj.FramesReceivedPersec), ) ch <- prometheus.MustNewConstMetric( c.AdapterFramesDropped, - prometheus.GaugeValue, - float64(obj.BytesSentPersec), + prometheus.CounterValue, + float64(obj.FramesDropped), ) ch <- prometheus.MustNewConstMetric( - c.AdapterFramesSentPersec, - prometheus.GaugeValue, + c.AdapterFramesSent, + prometheus.CounterValue, float64(obj.FramesSentPersec), ) From a0ec1e2da6830992ad955d25cc5a2fe9bd62a547 Mon Sep 17 00:00:00 2001 From: Calle Pettersson Date: Mon, 16 Apr 2018 20:56:05 +0200 Subject: [PATCH 4/8] Rename hyperv subsystem --- collector/hyperv.go | 135 ++++++++++++++++++++++---------------------- 1 file changed, 68 insertions(+), 67 deletions(-) diff --git a/collector/hyperv.go b/collector/hyperv.go index c4281471..4fb99dc2 100644 --- a/collector/hyperv.go +++ b/collector/hyperv.go @@ -90,15 +90,16 @@ type HyperVCollector struct { // NewHyperVCollector ... func NewHyperVCollector() (Collector, error) { + buildSubsystemName := func(component string) string { return "hyperv_" + component } return &HyperVCollector{ HealthCritical: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "health", "health_critical"), + prometheus.BuildFQName(Namespace, buildSubsystemName("health"), "critical"), "This counter represents the number of virtual machines with critical health", nil, nil, ), HealthOk: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "health", "health_ok"), + prometheus.BuildFQName(Namespace, buildSubsystemName("health"), "ok"), "This counter represents the number of virtual machines with ok health", nil, nil, @@ -107,19 +108,19 @@ func NewHyperVCollector() (Collector, error) { // PhysicalPagesAllocated: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "vid", "physical_pages_allocated"), + prometheus.BuildFQName(Namespace, buildSubsystemName("vid"), "physical_pages_allocated"), "The number of physical pages allocated", nil, nil, ), PreferredNUMANodeIndex: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "vid", "preferred_numa_node_index"), + prometheus.BuildFQName(Namespace, buildSubsystemName("vid"), "preferred_numa_node_index"), "The preferred NUMA node index associated with this partition", nil, nil, ), RemotePhysicalPages: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "vid", "remote_physical_pages"), + prometheus.BuildFQName(Namespace, buildSubsystemName("vid"), "remote_physical_pages"), "The number of physical pages not allocated from the preferred NUMA node", nil, nil, @@ -128,127 +129,127 @@ func NewHyperVCollector() (Collector, error) { // AddressSpaces: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "hv", "address_spaces"), + prometheus.BuildFQName(Namespace, buildSubsystemName("root_partition"), "address_spaces"), "The number of address spaces in the virtual TLB of the partition", nil, nil, ), AttachedDevices: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "hv", "attached_devices"), + prometheus.BuildFQName(Namespace, buildSubsystemName("root_partition"), "attached_devices"), "The number of devices attached to the partition", nil, nil, ), DepositedPages: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "hv", "deposited_pages"), + prometheus.BuildFQName(Namespace, buildSubsystemName("root_partition"), "deposited_pages"), "The number of pages deposited into the partition", nil, nil, ), DeviceDMAErrors: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "hv", "device_dma_errors"), + prometheus.BuildFQName(Namespace, buildSubsystemName("root_partition"), "device_dma_errors"), "An indicator of illegal DMA requests generated by all devices assigned to the partition", nil, nil, ), DeviceInterruptErrors: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "hv", "device_interrupt_errors"), + prometheus.BuildFQName(Namespace, buildSubsystemName("root_partition"), "device_interrupt_errors"), "An indicator of illegal interrupt requests generated by all devices assigned to the partition", nil, nil, ), DeviceInterruptMappings: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "hv", "device_interrupt_mappings"), + prometheus.BuildFQName(Namespace, buildSubsystemName("root_partition"), "device_interrupt_mappings"), "The number of device interrupt mappings used by the partition", nil, nil, ), DeviceInterruptThrottleEvents: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "hv", "device_interrupt_throttle_events"), + prometheus.BuildFQName(Namespace, buildSubsystemName("root_partition"), "device_interrupt_throttle_events"), "The number of times an interrupt from a device assigned to the partition was temporarily throttled because the device was generating too many interrupts", nil, nil, ), GPAPages: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "hv", "preferred_numa_node_index"), + prometheus.BuildFQName(Namespace, buildSubsystemName("root_partition"), "preferred_numa_node_index"), "The number of pages present in the GPA space of the partition (zero for root partition)", nil, nil, ), GPASpaceModifications: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "hv", "gpa_space_modifications"), + prometheus.BuildFQName(Namespace, buildSubsystemName("root_partition"), "gpa_space_modifications"), "The rate of modifications to the GPA space of the partition", nil, nil, ), IOTLBFlushCost: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "hv", "io_tlb_flush_cost"), + prometheus.BuildFQName(Namespace, buildSubsystemName("root_partition"), "io_tlb_flush_cost"), "The average time (in nanoseconds) spent processing an I/O TLB flush", nil, nil, ), IOTLBFlushes: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "hv", "io_tlb_flush"), + prometheus.BuildFQName(Namespace, buildSubsystemName("root_partition"), "io_tlb_flush"), "The rate of flushes of I/O TLBs of the partition", nil, nil, ), RecommendedVirtualTLBSize: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "hv", "recommended_virtual_tlb_size"), + prometheus.BuildFQName(Namespace, buildSubsystemName("root_partition"), "recommended_virtual_tlb_size"), "The recommended number of pages to be deposited for the virtual TLB", nil, nil, ), SkippedTimerTicks: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "hv", "physical_pages_allocated"), + prometheus.BuildFQName(Namespace, buildSubsystemName("root_partition"), "physical_pages_allocated"), "The number of timer interrupts skipped for the partition", nil, nil, ), Value1Gdevicepages: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "hv", "1G_device_pages"), + prometheus.BuildFQName(Namespace, buildSubsystemName("root_partition"), "1G_device_pages"), "The number of 1G pages present in the device space of the partition", nil, nil, ), Value1GGPApages: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "hv", "1G_gpa_pages"), + prometheus.BuildFQName(Namespace, buildSubsystemName("root_partition"), "1G_gpa_pages"), "The number of 1G pages present in the GPA space of the partition", nil, nil, ), Value2Mdevicepages: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "hv", "2M_device_pages"), + prometheus.BuildFQName(Namespace, buildSubsystemName("root_partition"), "2M_device_pages"), "The number of 2M pages present in the device space of the partition", nil, nil, ), Value2MGPApages: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "hv", "2M_gpa_pages"), + prometheus.BuildFQName(Namespace, buildSubsystemName("root_partition"), "2M_gpa_pages"), "The number of 2M pages present in the GPA space of the partition", nil, nil, ), Value4Kdevicepages: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "hv", "4K_device_pages"), + prometheus.BuildFQName(Namespace, buildSubsystemName("root_partition"), "4K_device_pages"), "The number of 4K pages present in the device space of the partition", nil, nil, ), Value4KGPApages: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "hv", "4K_gpa_pages"), + prometheus.BuildFQName(Namespace, buildSubsystemName("root_partition"), "4K_gpa_pages"), "The number of 4K pages present in the GPA space of the partition", nil, nil, ), VirtualTLBFlushEntires: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "hv", "virtual_tlb_flush_entires"), + prometheus.BuildFQName(Namespace, buildSubsystemName("root_partition"), "virtual_tlb_flush_entires"), "The rate of flushes of the entire virtual TLB", nil, nil, ), VirtualTLBPages: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "hv", "virtual_tlb_pages"), + prometheus.BuildFQName(Namespace, buildSubsystemName("root_partition"), "virtual_tlb_pages"), "The number of pages used by the virtual TLB of the partition", nil, nil, @@ -257,13 +258,13 @@ func NewHyperVCollector() (Collector, error) { // VirtualProcessors: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "processor", "virtual_processors"), + prometheus.BuildFQName(Namespace, buildSubsystemName("hypervisor"), "virtual_processors"), "The number of virtual processors present in the system", nil, nil, ), LogicalProcessors: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "processor", "logical_processors"), + prometheus.BuildFQName(Namespace, buildSubsystemName("hypervisor"), "logical_processors"), "The number of logical processors present in the system", nil, nil, @@ -272,153 +273,153 @@ func NewHyperVCollector() (Collector, error) { // PercentGuestRunTime: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "rate", "guest_run_time"), - "The percentage of time spent by the virtual processor in guest code", + prometheus.BuildFQName(Namespace, buildSubsystemName("vcpu"), "guest_run_time"), + "The time spent by the virtual processor in guest code", []string{"core"}, nil, ), PercentHypervisorRunTime: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "rate", "hypervisor_run_time"), - "The percentage of time spent by the virtual processor in hypervisor code", + prometheus.BuildFQName(Namespace, buildSubsystemName("vcpu"), "hypervisor_run_time"), + "The time spent by the virtual processor in hypervisor code", []string{"core"}, nil, ), PercentRemoteRunTime: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "rate", "remote_run_time"), - "The percentage of time spent by the virtual processor running on a remote node", + prometheus.BuildFQName(Namespace, buildSubsystemName("vcpu"), "remote_run_time"), + "The time spent by the virtual processor running on a remote node", []string{"core"}, nil, ), PercentTotalRunTime: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "rate", "total_run_time"), - "The percentage of time spent by the virtual processor in guest and hypervisor code", + prometheus.BuildFQName(Namespace, buildSubsystemName("vcpu"), "total_run_time"), + "The time spent by the virtual processor in guest and hypervisor code", []string{"core"}, nil, ), // BroadcastPacketsReceived: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "switch", "broadcast_packets_received_total"), + prometheus.BuildFQName(Namespace, buildSubsystemName("vswitch"), "broadcast_packets_received_total"), "This represents the total number of broadcast packets received per second by the virtual switch", nil, nil, ), BroadcastPacketsSent: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "switch", "broadcast_packets_sent_total"), + prometheus.BuildFQName(Namespace, buildSubsystemName("vswitch"), "broadcast_packets_sent_total"), "This represents the total number of broadcast packets sent per second by the virtual switch", nil, nil, ), Bytes: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "switch", "bytes_total"), + prometheus.BuildFQName(Namespace, buildSubsystemName("vswitch"), "bytes_total"), "This represents the total number of bytes per second traversing the virtual switch", nil, nil, ), BytesReceived: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "switch", "bytes_received_total"), + prometheus.BuildFQName(Namespace, buildSubsystemName("vswitch"), "bytes_received_total"), "This represents the total number of bytes received per second by the virtual switch", nil, nil, ), BytesSent: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "switch", "bytes_sent_total"), + prometheus.BuildFQName(Namespace, buildSubsystemName("vswitch"), "bytes_sent_total"), "This represents the total number of bytes sent per second by the virtual switch", nil, nil, ), DirectedPacketsReceived: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "switch", "directed_packets_received_total"), + prometheus.BuildFQName(Namespace, buildSubsystemName("vswitch"), "directed_packets_received_total"), "This represents the total number of directed packets received per second by the virtual switch", nil, nil, ), DirectedPacketsSent: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "switch", "directed_packets_send_total"), + prometheus.BuildFQName(Namespace, buildSubsystemName("vswitch"), "directed_packets_send_total"), "This represents the total number of directed packets sent per second by the virtual switch", nil, nil, ), DroppedPacketsIncoming: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "switch", "dropped_packets_incoming_total"), + prometheus.BuildFQName(Namespace, buildSubsystemName("vswitch"), "dropped_packets_incoming_total"), "This represents the total number of packet dropped per second by the virtual switch in the incoming direction", nil, nil, ), DroppedPacketsOutgoing: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "switch", "dropped_packets_outcoming_total"), + prometheus.BuildFQName(Namespace, buildSubsystemName("vswitch"), "dropped_packets_outcoming_total"), "This represents the total number of packet dropped per second by the virtual switch in the outgoing direction", nil, nil, ), ExtensionsDroppedPacketsIncoming: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "switch", "extensions_dropped_packets_incoming_total"), + prometheus.BuildFQName(Namespace, buildSubsystemName("vswitch"), "extensions_dropped_packets_incoming_total"), "This represents the total number of packet dropped per second by the virtual switch extensions in the incoming direction", nil, nil, ), ExtensionsDroppedPacketsOutgoing: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "switch", "extensions_dropped_packets_outcoming_total"), + prometheus.BuildFQName(Namespace, buildSubsystemName("vswitch"), "extensions_dropped_packets_outcoming_total"), "This represents the total number of packet dropped per second by the virtual switch extensions in the outgoing direction", nil, nil, ), LearnedMacAddresses: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "switch", "learned_mac_addresses_total"), + prometheus.BuildFQName(Namespace, buildSubsystemName("vswitch"), "learned_mac_addresses_total"), "This counter represents the total number of learned MAC addresses of the virtual switch", nil, nil, ), MulticastPacketsReceived: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "switch", "multicast_packets_received_total"), + prometheus.BuildFQName(Namespace, buildSubsystemName("vswitch"), "multicast_packets_received_total"), "This represents the total number of multicast packets received per second by the virtual switch", nil, nil, ), MulticastPacketsSent: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "switch", "multicast_packets_sent_total"), + prometheus.BuildFQName(Namespace, buildSubsystemName("vswitch"), "multicast_packets_sent_total"), "This represents the total number of multicast packets sent per second by the virtual switch", nil, nil, ), NumberofSendChannelMoves: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "switch", "number_of_send_channel_moves_total"), + prometheus.BuildFQName(Namespace, buildSubsystemName("vswitch"), "number_of_send_channel_moves_total"), "This represents the total number of send channel moves per second on this virtual switch", nil, nil, ), NumberofVMQMoves: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "switch", "number_of_vmq_moves_total"), + prometheus.BuildFQName(Namespace, buildSubsystemName("vswitch"), "number_of_vmq_moves_total"), "This represents the total number of VMQ moves per second on this virtual switch", nil, nil, ), PacketsFlooded: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "switch", "packets_flooded_total"), + prometheus.BuildFQName(Namespace, buildSubsystemName("vswitch"), "packets_flooded_total"), "This counter represents the total number of packets flooded by the virtual switch", nil, nil, ), Packets: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "switch", "packets_total"), + prometheus.BuildFQName(Namespace, buildSubsystemName("vswitch"), "packets_total"), "This represents the total number of packets per second traversing the virtual switch", nil, nil, ), PacketsReceived: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "switch", "packets_received_total"), + prometheus.BuildFQName(Namespace, buildSubsystemName("vswitch"), "packets_received_total"), "This represents the total number of packets received per second by the virtual switch", nil, nil, ), PacketsSent: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "switch", "packets_sent_total"), + prometheus.BuildFQName(Namespace, buildSubsystemName("vswitch"), "packets_sent_total"), "This represents the total number of packets send per second by the virtual switch", nil, nil, ), PurgedMacAddresses: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "switch", "purged_mac_addresses_total"), + prometheus.BuildFQName(Namespace, buildSubsystemName("vswitch"), "purged_mac_addresses_total"), "This counter represents the total number of purged MAC addresses of the virtual switch", nil, nil, @@ -427,38 +428,38 @@ func NewHyperVCollector() (Collector, error) { // AdapterBytesDropped: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "ethernet", "bytes"), + prometheus.BuildFQName(Namespace, buildSubsystemName("ethernet"), "bytes_dropped"), "Bytes Dropped is the number of bytes dropped on the network adapter", nil, nil, ), AdapterBytesReceived: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "ethernet", "bytes_received"), - "Bytes Received/sec is the number of bytes received per second on the network adapter", + prometheus.BuildFQName(Namespace, buildSubsystemName("ethernet"), "bytes_received"), + "Bytes received is the number of bytes received on the network adapter", nil, nil, ), AdapterBytesSent: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "ethernet", "bytes_sent"), - "Bytes Sent/sec is the number of bytes sent per second over the network adapter", + prometheus.BuildFQName(Namespace, buildSubsystemName("ethernet"), "bytes_sent"), + "Bytes sent is the number of bytes sent over the network adapter", nil, nil, ), AdapterFramesDropped: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "ethernet", "frames_dropped"), + prometheus.BuildFQName(Namespace, buildSubsystemName("ethernet"), "frames_dropped"), "Frames Dropped is the number of frames dropped on the network adapter", nil, nil, ), AdapterFramesReceived: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "ethernet", "frames_received"), - "Frames Received/sec is the number of frames received per second on the network adapter", + prometheus.BuildFQName(Namespace, buildSubsystemName("ethernet"), "frames_received"), + "Frames received is the number of frames received on the network adapter", nil, nil, ), AdapterFramesSent: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "ethernet", "frames_sent"), - "Frames Sent/sec is the number of frames sent per second over the network adapter", + prometheus.BuildFQName(Namespace, buildSubsystemName("ethernet"), "frames_sent"), + "Frames sent is the number of frames sent over the network adapter", nil, nil, ), From 5a538d7682628f2d8575473a928ebead15ba0821 Mon Sep 17 00:00:00 2001 From: Calle Pettersson Date: Mon, 16 Apr 2018 21:00:29 +0200 Subject: [PATCH 5/8] Add missing labels --- collector/hyperv.go | 77 +++++++++++++++++++++++++++++++-------------- 1 file changed, 53 insertions(+), 24 deletions(-) diff --git a/collector/hyperv.go b/collector/hyperv.go index 4fb99dc2..392b7c90 100644 --- a/collector/hyperv.go +++ b/collector/hyperv.go @@ -110,19 +110,19 @@ func NewHyperVCollector() (Collector, error) { PhysicalPagesAllocated: prometheus.NewDesc( prometheus.BuildFQName(Namespace, buildSubsystemName("vid"), "physical_pages_allocated"), "The number of physical pages allocated", - nil, + []string{"interface"}, nil, ), PreferredNUMANodeIndex: prometheus.NewDesc( prometheus.BuildFQName(Namespace, buildSubsystemName("vid"), "preferred_numa_node_index"), "The preferred NUMA node index associated with this partition", - nil, + []string{"interface"}, nil, ), RemotePhysicalPages: prometheus.NewDesc( prometheus.BuildFQName(Namespace, buildSubsystemName("vid"), "remote_physical_pages"), "The number of physical pages not allocated from the preferred NUMA node", - nil, + []string{"interface"}, nil, ), @@ -301,127 +301,127 @@ func NewHyperVCollector() (Collector, error) { BroadcastPacketsReceived: prometheus.NewDesc( prometheus.BuildFQName(Namespace, buildSubsystemName("vswitch"), "broadcast_packets_received_total"), "This represents the total number of broadcast packets received per second by the virtual switch", - nil, + []string{"vswitch"}, nil, ), BroadcastPacketsSent: prometheus.NewDesc( prometheus.BuildFQName(Namespace, buildSubsystemName("vswitch"), "broadcast_packets_sent_total"), "This represents the total number of broadcast packets sent per second by the virtual switch", - nil, + []string{"vswitch"}, nil, ), Bytes: prometheus.NewDesc( prometheus.BuildFQName(Namespace, buildSubsystemName("vswitch"), "bytes_total"), "This represents the total number of bytes per second traversing the virtual switch", - nil, + []string{"vswitch"}, nil, ), BytesReceived: prometheus.NewDesc( prometheus.BuildFQName(Namespace, buildSubsystemName("vswitch"), "bytes_received_total"), "This represents the total number of bytes received per second by the virtual switch", - nil, + []string{"vswitch"}, nil, ), BytesSent: prometheus.NewDesc( prometheus.BuildFQName(Namespace, buildSubsystemName("vswitch"), "bytes_sent_total"), "This represents the total number of bytes sent per second by the virtual switch", - nil, + []string{"vswitch"}, nil, ), DirectedPacketsReceived: prometheus.NewDesc( prometheus.BuildFQName(Namespace, buildSubsystemName("vswitch"), "directed_packets_received_total"), "This represents the total number of directed packets received per second by the virtual switch", - nil, + []string{"vswitch"}, nil, ), DirectedPacketsSent: prometheus.NewDesc( prometheus.BuildFQName(Namespace, buildSubsystemName("vswitch"), "directed_packets_send_total"), "This represents the total number of directed packets sent per second by the virtual switch", - nil, + []string{"vswitch"}, nil, ), DroppedPacketsIncoming: prometheus.NewDesc( prometheus.BuildFQName(Namespace, buildSubsystemName("vswitch"), "dropped_packets_incoming_total"), "This represents the total number of packet dropped per second by the virtual switch in the incoming direction", - nil, + []string{"vswitch"}, nil, ), DroppedPacketsOutgoing: prometheus.NewDesc( prometheus.BuildFQName(Namespace, buildSubsystemName("vswitch"), "dropped_packets_outcoming_total"), "This represents the total number of packet dropped per second by the virtual switch in the outgoing direction", - nil, + []string{"vswitch"}, nil, ), ExtensionsDroppedPacketsIncoming: prometheus.NewDesc( prometheus.BuildFQName(Namespace, buildSubsystemName("vswitch"), "extensions_dropped_packets_incoming_total"), "This represents the total number of packet dropped per second by the virtual switch extensions in the incoming direction", - nil, + []string{"vswitch"}, nil, ), ExtensionsDroppedPacketsOutgoing: prometheus.NewDesc( prometheus.BuildFQName(Namespace, buildSubsystemName("vswitch"), "extensions_dropped_packets_outcoming_total"), "This represents the total number of packet dropped per second by the virtual switch extensions in the outgoing direction", - nil, + []string{"vswitch"}, nil, ), LearnedMacAddresses: prometheus.NewDesc( prometheus.BuildFQName(Namespace, buildSubsystemName("vswitch"), "learned_mac_addresses_total"), "This counter represents the total number of learned MAC addresses of the virtual switch", - nil, + []string{"vswitch"}, nil, ), MulticastPacketsReceived: prometheus.NewDesc( prometheus.BuildFQName(Namespace, buildSubsystemName("vswitch"), "multicast_packets_received_total"), "This represents the total number of multicast packets received per second by the virtual switch", - nil, + []string{"vswitch"}, nil, ), MulticastPacketsSent: prometheus.NewDesc( prometheus.BuildFQName(Namespace, buildSubsystemName("vswitch"), "multicast_packets_sent_total"), "This represents the total number of multicast packets sent per second by the virtual switch", - nil, + []string{"vswitch"}, nil, ), NumberofSendChannelMoves: prometheus.NewDesc( prometheus.BuildFQName(Namespace, buildSubsystemName("vswitch"), "number_of_send_channel_moves_total"), "This represents the total number of send channel moves per second on this virtual switch", - nil, + []string{"vswitch"}, nil, ), NumberofVMQMoves: prometheus.NewDesc( prometheus.BuildFQName(Namespace, buildSubsystemName("vswitch"), "number_of_vmq_moves_total"), "This represents the total number of VMQ moves per second on this virtual switch", - nil, + []string{"vswitch"}, nil, ), PacketsFlooded: prometheus.NewDesc( prometheus.BuildFQName(Namespace, buildSubsystemName("vswitch"), "packets_flooded_total"), "This counter represents the total number of packets flooded by the virtual switch", - nil, + []string{"vswitch"}, nil, ), Packets: prometheus.NewDesc( prometheus.BuildFQName(Namespace, buildSubsystemName("vswitch"), "packets_total"), "This represents the total number of packets per second traversing the virtual switch", - nil, + []string{"vswitch"}, nil, ), PacketsReceived: prometheus.NewDesc( prometheus.BuildFQName(Namespace, buildSubsystemName("vswitch"), "packets_received_total"), "This represents the total number of packets received per second by the virtual switch", - nil, + []string{"vswitch"}, nil, ), PacketsSent: prometheus.NewDesc( prometheus.BuildFQName(Namespace, buildSubsystemName("vswitch"), "packets_sent_total"), "This represents the total number of packets send per second by the virtual switch", - nil, + []string{"vswitch"}, nil, ), PurgedMacAddresses: prometheus.NewDesc( prometheus.BuildFQName(Namespace, buildSubsystemName("vswitch"), "purged_mac_addresses_total"), "This counter represents the total number of purged MAC addresses of the virtual switch", - nil, + []string{"vswitch"}, nil, ), @@ -559,18 +559,21 @@ func (c *HyperVCollector) collectVmVid(ch chan<- prometheus.Metric) (*prometheus c.PhysicalPagesAllocated, prometheus.GaugeValue, float64(page.PhysicalPagesAllocated), + page.Name, ) ch <- prometheus.MustNewConstMetric( c.PreferredNUMANodeIndex, prometheus.GaugeValue, float64(page.PreferredNUMANodeIndex), + page.Name, ) ch <- prometheus.MustNewConstMetric( c.RemotePhysicalPages, prometheus.GaugeValue, float64(page.RemotePhysicalPages), + page.Name, ) } @@ -869,88 +872,104 @@ func (c *HyperVCollector) collectVmSwitch(ch chan<- prometheus.Metric) (*prometh c.BroadcastPacketsReceived, prometheus.CounterValue, float64(obj.BroadcastPacketsReceivedPersec), + obj.Name, ) ch <- prometheus.MustNewConstMetric( c.BroadcastPacketsSent, prometheus.CounterValue, float64(obj.BroadcastPacketsSentPersec), + obj.Name, ) ch <- prometheus.MustNewConstMetric( c.Bytes, prometheus.CounterValue, float64(obj.BytesPersec), + obj.Name, ) ch <- prometheus.MustNewConstMetric( c.BytesReceived, prometheus.CounterValue, float64(obj.BytesReceivedPersec), + obj.Name, ) ch <- prometheus.MustNewConstMetric( c.BytesSent, prometheus.CounterValue, float64(obj.BytesSentPersec), + obj.Name, ) ch <- prometheus.MustNewConstMetric( c.DirectedPacketsReceived, prometheus.CounterValue, float64(obj.DirectedPacketsReceivedPersec), + obj.Name, ) ch <- prometheus.MustNewConstMetric( c.DirectedPacketsSent, prometheus.CounterValue, float64(obj.DirectedPacketsSentPersec), + obj.Name, ) ch <- prometheus.MustNewConstMetric( c.DroppedPacketsIncoming, prometheus.CounterValue, float64(obj.DroppedPacketsIncomingPersec), + obj.Name, ) ch <- prometheus.MustNewConstMetric( c.DroppedPacketsOutgoing, prometheus.CounterValue, float64(obj.DroppedPacketsOutgoingPersec), + obj.Name, ) ch <- prometheus.MustNewConstMetric( c.ExtensionsDroppedPacketsIncoming, prometheus.CounterValue, float64(obj.ExtensionsDroppedPacketsIncomingPersec), + obj.Name, ) ch <- prometheus.MustNewConstMetric( c.ExtensionsDroppedPacketsOutgoing, prometheus.CounterValue, float64(obj.ExtensionsDroppedPacketsOutgoingPersec), + obj.Name, ) ch <- prometheus.MustNewConstMetric( c.LearnedMacAddresses, prometheus.CounterValue, float64(obj.LearnedMacAddresses), + obj.Name, ) ch <- prometheus.MustNewConstMetric( c.MulticastPacketsReceived, prometheus.CounterValue, float64(obj.MulticastPacketsReceivedPersec), + obj.Name, ) ch <- prometheus.MustNewConstMetric( c.MulticastPacketsSent, prometheus.CounterValue, float64(obj.MulticastPacketsSentPersec), + obj.Name, ) ch <- prometheus.MustNewConstMetric( c.NumberofSendChannelMoves, prometheus.CounterValue, float64(obj.NumberofSendChannelMovesPersec), + obj.Name, ) ch <- prometheus.MustNewConstMetric( c.NumberofVMQMoves, prometheus.CounterValue, float64(obj.NumberofVMQMovesPersec), + obj.Name, ) // ... @@ -958,23 +977,27 @@ func (c *HyperVCollector) collectVmSwitch(ch chan<- prometheus.Metric) (*prometh c.PacketsFlooded, prometheus.CounterValue, float64(obj.PacketsFlooded), + obj.Name, ) ch <- prometheus.MustNewConstMetric( c.Packets, prometheus.CounterValue, float64(obj.PacketsPersec), + obj.Name, ) ch <- prometheus.MustNewConstMetric( c.PacketsReceived, prometheus.CounterValue, float64(obj.PacketsReceivedPersec), + obj.Name, ) ch <- prometheus.MustNewConstMetric( c.PurgedMacAddresses, prometheus.CounterValue, float64(obj.PurgedMacAddresses), + obj.Name, ) } @@ -1007,36 +1030,42 @@ func (c *HyperVCollector) collectVmEthernet(ch chan<- prometheus.Metric) (*prome c.AdapterBytesDropped, prometheus.GaugeValue, float64(obj.BytesDropped), + obj.Name, ) ch <- prometheus.MustNewConstMetric( c.AdapterBytesReceived, prometheus.CounterValue, float64(obj.BytesReceivedPersec), + obj.Name, ) ch <- prometheus.MustNewConstMetric( c.AdapterBytesSent, prometheus.CounterValue, float64(obj.BytesSentPersec), + obj.Name, ) ch <- prometheus.MustNewConstMetric( c.AdapterFramesReceived, prometheus.CounterValue, float64(obj.FramesReceivedPersec), + obj.Name, ) ch <- prometheus.MustNewConstMetric( c.AdapterFramesDropped, prometheus.CounterValue, float64(obj.FramesDropped), + obj.Name, ) ch <- prometheus.MustNewConstMetric( c.AdapterFramesSent, prometheus.CounterValue, float64(obj.FramesSentPersec), + obj.Name, ) } From c241513d561f8b7fe8116da56fab58cce173b3a5 Mon Sep 17 00:00:00 2001 From: Calle Pettersson Date: Tue, 17 Apr 2018 18:25:22 +0200 Subject: [PATCH 6/8] Fix interface->vm labelling of VID class --- collector/hyperv.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/collector/hyperv.go b/collector/hyperv.go index 392b7c90..38aca410 100644 --- a/collector/hyperv.go +++ b/collector/hyperv.go @@ -110,19 +110,19 @@ func NewHyperVCollector() (Collector, error) { PhysicalPagesAllocated: prometheus.NewDesc( prometheus.BuildFQName(Namespace, buildSubsystemName("vid"), "physical_pages_allocated"), "The number of physical pages allocated", - []string{"interface"}, + []string{"vm"}, nil, ), PreferredNUMANodeIndex: prometheus.NewDesc( prometheus.BuildFQName(Namespace, buildSubsystemName("vid"), "preferred_numa_node_index"), "The preferred NUMA node index associated with this partition", - []string{"interface"}, + []string{"vm"}, nil, ), RemotePhysicalPages: prometheus.NewDesc( prometheus.BuildFQName(Namespace, buildSubsystemName("vid"), "remote_physical_pages"), "The number of physical pages not allocated from the preferred NUMA node", - []string{"interface"}, + []string{"vm"}, nil, ), From c3b227a4f2916b1229f12ef20eb576a509aad444 Mon Sep 17 00:00:00 2001 From: Calle Pettersson Date: Tue, 17 Apr 2018 20:31:14 +0200 Subject: [PATCH 7/8] Switch to common/log --- collector/hyperv.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/collector/hyperv.go b/collector/hyperv.go index 38aca410..f203eadc 100644 --- a/collector/hyperv.go +++ b/collector/hyperv.go @@ -1,11 +1,11 @@ package collector import ( - "log" "strings" "github.com/StackExchange/wmi" "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/common/log" ) func init() { @@ -470,37 +470,37 @@ func NewHyperVCollector() (Collector, error) { // to the provided prometheus Metric channel. func (c *HyperVCollector) Collect(ch chan<- prometheus.Metric) error { if desc, err := c.collectVmHealth(ch); err != nil { - log.Println("[ERROR] failed collecting hyperV health status metrics:", desc, err) + log.Error("failed collecting hyperV health status metrics:", desc, err) return err } if desc, err := c.collectVmVid(ch); err != nil { - log.Println("[ERROR] failed collecting hyperV pages metrics:", desc, err) + log.Error("failed collecting hyperV pages metrics:", desc, err) return err } if desc, err := c.collectVmHv(ch); err != nil { - log.Println("[ERROR] failed collecting hyperV hv status metrics:", desc, err) + log.Error("failed collecting hyperV hv status metrics:", desc, err) return err } if desc, err := c.collectVmProcessor(ch); err != nil { - log.Println("[ERROR] failed collecting hyperV processor metrics:", desc, err) + log.Error("failed collecting hyperV processor metrics:", desc, err) return err } if desc, err := c.collectVmRate(ch); err != nil { - log.Println("[ERROR] failed collecting hyperV rate metrics:", desc, err) + log.Error("failed collecting hyperV rate metrics:", desc, err) return err } if desc, err := c.collectVmSwitch(ch); err != nil { - log.Println("[ERROR] failed collecting hyperV switch metrics:", desc, err) + log.Error("failed collecting hyperV switch metrics:", desc, err) return err } if desc, err := c.collectVmEthernet(ch); err != nil { - log.Println("[ERROR] failed collecting hyperV ethernet metrics:", desc, err) + log.Error("failed collecting hyperV ethernet metrics:", desc, err) return err } return nil From ec79488478834f68d3fb7eb02bf24b96a6ce9236 Mon Sep 17 00:00:00 2001 From: Calle Pettersson Date: Tue, 17 Apr 2018 20:31:43 +0200 Subject: [PATCH 8/8] Fix CPU metrics --- collector/hyperv.go | 150 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 123 insertions(+), 27 deletions(-) diff --git a/collector/hyperv.go b/collector/hyperv.go index f203eadc..2a9627d5 100644 --- a/collector/hyperv.go +++ b/collector/hyperv.go @@ -50,11 +50,17 @@ type HyperVCollector struct { LogicalProcessors *prometheus.Desc VirtualProcessors *prometheus.Desc + // Win32_PerfRawData_HvStats_HyperVHypervisorRootVirtualProcessor + HostGuestRunTime *prometheus.Desc + HostHypervisorRunTime *prometheus.Desc + HostRemoteRunTime *prometheus.Desc + HostTotalRunTime *prometheus.Desc + // Win32_PerfRawData_HvStats_HyperVHypervisorVirtualProcessor - PercentGuestRunTime *prometheus.Desc - PercentHypervisorRunTime *prometheus.Desc - PercentRemoteRunTime *prometheus.Desc - PercentTotalRunTime *prometheus.Desc + VMGuestRunTime *prometheus.Desc + VMHypervisorRunTime *prometheus.Desc + VMRemoteRunTime *prometheus.Desc + VMTotalRunTime *prometheus.Desc // Win32_PerfRawData_NvspSwitchStats_HyperVVirtualSwitch BroadcastPacketsReceived *prometheus.Desc @@ -272,31 +278,58 @@ func NewHyperVCollector() (Collector, error) { // - PercentGuestRunTime: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, buildSubsystemName("vcpu"), "guest_run_time"), + HostGuestRunTime: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, buildSubsystemName("host_cpu"), "guest_run_time"), "The time spent by the virtual processor in guest code", []string{"core"}, nil, ), - PercentHypervisorRunTime: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, buildSubsystemName("vcpu"), "hypervisor_run_time"), + HostHypervisorRunTime: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, buildSubsystemName("host_cpu"), "hypervisor_run_time"), "The time spent by the virtual processor in hypervisor code", []string{"core"}, nil, ), - PercentRemoteRunTime: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, buildSubsystemName("vcpu"), "remote_run_time"), + HostRemoteRunTime: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, buildSubsystemName("host_cpu"), "remote_run_time"), "The time spent by the virtual processor running on a remote node", []string{"core"}, nil, ), - PercentTotalRunTime: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, buildSubsystemName("vcpu"), "total_run_time"), + HostTotalRunTime: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, buildSubsystemName("host_cpu"), "total_run_time"), "The time spent by the virtual processor in guest and hypervisor code", []string{"core"}, nil, ), + // + + VMGuestRunTime: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, buildSubsystemName("vm_cpu"), "guest_run_time"), + "The time spent by the virtual processor in guest code", + []string{"vm", "core"}, + nil, + ), + VMHypervisorRunTime: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, buildSubsystemName("vm_cpu"), "hypervisor_run_time"), + "The time spent by the virtual processor in hypervisor code", + []string{"vm", "core"}, + nil, + ), + VMRemoteRunTime: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, buildSubsystemName("vm_cpu"), "remote_run_time"), + "The time spent by the virtual processor running on a remote node", + []string{"vm", "core"}, + nil, + ), + VMTotalRunTime: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, buildSubsystemName("vm_cpu"), "total_run_time"), + "The time spent by the virtual processor in guest and hypervisor code", + []string{"vm", "core"}, + nil, + ), + // BroadcastPacketsReceived: prometheus.NewDesc( prometheus.BuildFQName(Namespace, buildSubsystemName("vswitch"), "broadcast_packets_received_total"), @@ -489,8 +522,13 @@ func (c *HyperVCollector) Collect(ch chan<- prometheus.Metric) error { return err } - if desc, err := c.collectVmRate(ch); err != nil { - log.Error("failed collecting hyperV rate metrics:", desc, err) + if desc, err := c.collectHostCpuUsage(ch); err != nil { + log.Error("failed collecting hyperV host CPU metrics:", desc, err) + return err + } + + if desc, err := c.collectVmCpuUsage(ch); err != nil { + log.Error("failed collecting hyperV VM CPU metrics:", desc, err) return err } @@ -778,7 +816,7 @@ type Win32_PerfRawData_HvStats_HyperVHypervisorRootVirtualProcessor struct { PercentTotalRunTime uint64 } -func (c *HyperVCollector) collectVmRate(ch chan<- prometheus.Metric) (*prometheus.Desc, error) { +func (c *HyperVCollector) collectHostCpuUsage(ch chan<- prometheus.Metric) (*prometheus.Desc, error) { var dst []Win32_PerfRawData_HvStats_HyperVHypervisorRootVirtualProcessor if err := wmi.Query(wmi.CreateQuery(&dst, ""), &dst); err != nil { return nil, err @@ -788,39 +826,97 @@ func (c *HyperVCollector) collectVmRate(ch chan<- prometheus.Metric) (*prometheu if strings.Contains(obj.Name, "_Total") { continue } - // Root VP 3 - names := strings.Split(obj.Name, " ") - if len(names) == 0 { + // The name format is Root VP + parts := strings.Split(obj.Name, " ") + if len(parts) != 3 { + log.Warnf("Unexpected format of Name in collectHostCpuUsage: %q", obj.Name) continue } - label := names[len(names)-1] + coreId := parts[2] ch <- prometheus.MustNewConstMetric( - c.PercentGuestRunTime, + c.HostGuestRunTime, prometheus.GaugeValue, float64(obj.PercentGuestRunTime), - label, + coreId, ) ch <- prometheus.MustNewConstMetric( - c.PercentHypervisorRunTime, + c.HostHypervisorRunTime, prometheus.GaugeValue, float64(obj.PercentHypervisorRunTime), - label, + coreId, ) ch <- prometheus.MustNewConstMetric( - c.PercentRemoteRunTime, + c.HostRemoteRunTime, prometheus.GaugeValue, float64(obj.PercentRemoteRunTime), - label, + coreId, ) ch <- prometheus.MustNewConstMetric( - c.PercentTotalRunTime, + c.HostTotalRunTime, prometheus.GaugeValue, float64(obj.PercentTotalRunTime), - label, + coreId, + ) + + } + + return nil, nil +} + +// Win32_PerfRawData_HvStats_HyperVHypervisorVirtualProcessor ... +type Win32_PerfRawData_HvStats_HyperVHypervisorVirtualProcessor struct { + Name string + PercentGuestRunTime uint64 + PercentHypervisorRunTime uint64 + PercentRemoteRunTime uint64 + PercentTotalRunTime uint64 +} + +func (c *HyperVCollector) collectVmCpuUsage(ch chan<- prometheus.Metric) (*prometheus.Desc, error) { + var dst []Win32_PerfRawData_HvStats_HyperVHypervisorVirtualProcessor + if err := wmi.Query(wmi.CreateQuery(&dst, ""), &dst); err != nil { + return nil, err + } + + for _, obj := range dst { + if strings.Contains(obj.Name, "_Total") { + continue + } + // The name format is :Hv VP + parts := strings.Split(obj.Name, ":") + vmName := parts[0] + coreId := strings.Split(parts[1], " ")[2] + + ch <- prometheus.MustNewConstMetric( + c.VMGuestRunTime, + prometheus.GaugeValue, + float64(obj.PercentGuestRunTime), + vmName, coreId, + ) + + ch <- prometheus.MustNewConstMetric( + c.VMHypervisorRunTime, + prometheus.GaugeValue, + float64(obj.PercentHypervisorRunTime), + vmName, coreId, + ) + + ch <- prometheus.MustNewConstMetric( + c.VMRemoteRunTime, + prometheus.GaugeValue, + float64(obj.PercentRemoteRunTime), + vmName, coreId, + ) + + ch <- prometheus.MustNewConstMetric( + c.VMTotalRunTime, + prometheus.GaugeValue, + float64(obj.PercentTotalRunTime), + vmName, coreId, ) }