summaryrefslogtreecommitdiffstats
path: root/src/go/collectors/go.d.plugin/modules/windows/collect_hyperv.go
blob: c37285acb6c6ecedc89c0ef7441e7dbfc43335b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
// SPDX-License-Identifier: GPL-3.0-or-later

package windows

import (
	"strings"

	"github.com/netdata/netdata/go/go.d.plugin/pkg/prometheus"
)

const (
	metricHypervHealthCritical = "windows_hyperv_health_critical"
	metricHypervHealthOK       = "windows_hyperv_health_ok"

	metricHypervHypervisorLogicalProcessors = "windows_hyperv_hypervisor_logical_processors"
	metricHypervHypervisorVirtualProcessors = "windows_hyperv_hypervisor_virtual_processors"

	metricHypervHostCPUGuestRunTime            = "windows_hyperv_host_cpu_guest_run_time"
	metricHypervHostCPUHypervisorRunTime       = "windows_hyperv_host_cpu_hypervisor_run_time"
	metricHypervHostCPURemoteRunTime           = "windows_hyperv_host_cpu_remote_run_time"
	metricHypervHostCPUTotalRunTime            = "windows_hyperv_host_cpu_total_run_time"
	metricHypervHostLPGuestRunTimePercent      = "windows_hyperv_host_lp_guest_run_time_percent"
	metricHypervHostLPHypervisorRunTimePercent = "windows_hyperv_host_lp_hypervisor_run_time_percent"
	metricHypervHostLPTotalRunTimePercent      = "windows_hyperv_host_lp_total_run_time_percent"

	metricHypervRootPartition4KGPAPages                    = "windows_hyperv_root_partition_4K_gpa_pages"
	metricHypervRootPartition2MGPAPages                    = "windows_hyperv_root_partition_2M_gpa_pages"
	metricHypervRootPartition1GGPAPages                    = "windows_hyperv_root_partition_1G_gpa_pages"
	metricHypervRootPartition4KDevicePages                 = "windows_hyperv_root_partition_4K_device_pages"
	metricHypervRootPartition2MDevicePages                 = "windows_hyperv_root_partition_2M_device_pages"
	metricHypervRootPartition1GDevicePages                 = "windows_hyperv_root_partition_1G_device_pages"
	metricHypervRootPartitionGPASpaceModifications         = "windows_hyperv_root_partition_gpa_space_modifications"
	metricHypervRootPartitionAttachedDevices               = "windows_hyperv_root_partition_attached_devices"
	metricHypervRootPartitionDepositedPages                = "windows_hyperv_root_partition_deposited_pages"
	metricHypervRootPartitionPhysicalPagesAllocated        = "windows_hyperv_root_partition_physical_pages_allocated" // SkippedTimerTicks
	metricHypervRootPartitionDeviceDMAErrors               = "windows_hyperv_root_partition_device_dma_errors"
	metricHypervRootPartitionDeviceInterruptErrors         = "windows_hyperv_root_partition_device_interrupt_errors"
	metricHypervRootPartitionDeviceInterruptThrottleEvents = "windows_hyperv_root_partition_device_interrupt_throttle_events"
	metricHypervRootPartitionIOTLBFlush                    = "windows_hyperv_root_partition_io_tlb_flush"
	metricHypervRootPartitionAddressSpace                  = "windows_hyperv_root_partition_address_spaces"
	metricHypervRootPartitionVirtualTLBPages               = "windows_hyperv_root_partition_virtual_tlb_pages"
	metricHypervRootPartitionVirtualTLBFlushEntries        = "windows_hyperv_root_partition_virtual_tlb_flush_entires"

	metricsHypervVMCPUGuestRunTime      = "windows_hyperv_vm_cpu_guest_run_time"
	metricsHypervVMCPUHypervisorRunTime = "windows_hyperv_vm_cpu_hypervisor_run_time"
	metricsHypervVMCPURemoteRunTime     = "windows_hyperv_vm_cpu_remote_run_time"
	metricsHypervVMCPUTotalRunTime      = "windows_hyperv_vm_cpu_total_run_time"

	metricHypervVMMemoryPhysical             = "windows_hyperv_vm_memory_physical"
	metricHypervVMMemoryPhysicalGuestVisible = "windows_hyperv_vm_memory_physical_guest_visible"
	metricHypervVMMemoryPressureCurrent      = "windows_hyperv_vm_memory_pressure_current"
	metricHyperVVIDPhysicalPagesAllocated    = "windows_hyperv_vid_physical_pages_allocated"
	metricHyperVVIDRemotePhysicalPages       = "windows_hyperv_vid_remote_physical_pages"

	metricHypervVMDeviceBytesRead         = "windows_hyperv_vm_device_bytes_read"
	metricHypervVMDeviceBytesWritten      = "windows_hyperv_vm_device_bytes_written"
	metricHypervVMDeviceOperationsRead    = "windows_hyperv_vm_device_operations_read"
	metricHypervVMDeviceOperationsWritten = "windows_hyperv_vm_device_operations_written"
	metricHypervVMDeviceErrorCount        = "windows_hyperv_vm_device_error_count"

	metricHypervVMInterfaceBytesReceived          = "windows_hyperv_vm_interface_bytes_received"
	metricHypervVMInterfaceBytesSent              = "windows_hyperv_vm_interface_bytes_sent"
	metricHypervVMInterfacePacketsIncomingDropped = "windows_hyperv_vm_interface_packets_incoming_dropped"
	metricHypervVMInterfacePacketsOutgoingDropped = "windows_hyperv_vm_interface_packets_outgoing_dropped"
	metricHypervVMInterfacePacketsReceived        = "windows_hyperv_vm_interface_packets_received"
	metricHypervVMInterfacePacketsSent            = "windows_hyperv_vm_interface_packets_sent"

	metricHypervVSwitchBroadcastPacketsReceivedTotal         = "windows_hyperv_vswitch_broadcast_packets_received_total"
	metricHypervVSwitchBroadcastPacketsSentTotal             = "windows_hyperv_vswitch_broadcast_packets_sent_total"
	metricHypervVSwitchBytesReceivedTotal                    = "windows_hyperv_vswitch_bytes_received_total"
	metricHypervVSwitchBytesSentTotal                        = "windows_hyperv_vswitch_bytes_sent_total"
	metricHypervVSwitchPacketsReceivedTotal                  = "windows_hyperv_vswitch_packets_received_total"
	metricHypervVSwitchPacketsSentTotal                      = "windows_hyperv_vswitch_packets_sent_total"
	metricHypervVSwitchDirectedPacketsReceivedTotal          = "windows_hyperv_vswitch_directed_packets_received_total"
	metricHypervVSwitchDirectedPacketsSendTotal              = "windows_hyperv_vswitch_directed_packets_send_total"
	metricHypervVSwitchDroppedPacketsIncomingTotal           = "windows_hyperv_vswitch_dropped_packets_incoming_total"
	metricHypervVSwitchDroppedPacketsOutcomingTotal          = "windows_hyperv_vswitch_dropped_packets_outcoming_total"
	metricHypervVSwitchExtensionDroppedAttacksIncomingTotal  = "windows_hyperv_vswitch_extensions_dropped_packets_incoming_total"
	metricHypervVSwitchExtensionDroppedPacketsOutcomingTotal = "windows_hyperv_vswitch_extensions_dropped_packets_outcoming_total"
	metricHypervVSwitchLearnedMACAddressTotal                = "windows_hyperv_vswitch_learned_mac_addresses_total"
	metricHypervVSwitchMulticastPacketsReceivedTotal         = "windows_hyperv_vswitch_multicast_packets_received_total"
	metricHypervVSwitchMulticastPacketsSentTotal             = "windows_hyperv_vswitch_multicast_packets_sent_total"
	metricHypervVSwitchNumberOfSendChannelMovesTotal         = "windows_hyperv_vswitch_number_of_send_channel_moves_total"
	metricHypervVSwitchNumberOfVMQMovesTotal                 = "windows_hyperv_vswitch_number_of_vmq_moves_total"
	metricHypervVSwitchPacketsFloodedTotal                   = "windows_hyperv_vswitch_packets_flooded_total"
	metricHypervVSwitchPurgedMACAddresses                    = "windows_hyperv_vswitch_purged_mac_addresses_total"
)

func (w *Windows) collectHyperv(mx map[string]int64, pms prometheus.Series) {
	if !w.cache.collection[collectorHyperv] {
		w.cache.collection[collectorHyperv] = true
		w.addHypervCharts()
	}

	for _, v := range []string{
		metricHypervHealthOK,
		metricHypervHealthCritical,
		metricHypervRootPartition4KGPAPages,
		metricHypervRootPartition2MGPAPages,
		metricHypervRootPartition1GGPAPages,
		metricHypervRootPartition4KDevicePages,
		metricHypervRootPartition2MDevicePages,
		metricHypervRootPartition1GDevicePages,
		metricHypervRootPartitionGPASpaceModifications,
		metricHypervRootPartitionAddressSpace,
		metricHypervRootPartitionAttachedDevices,
		metricHypervRootPartitionDepositedPages,
		metricHypervRootPartitionPhysicalPagesAllocated,
		metricHypervRootPartitionDeviceDMAErrors,
		metricHypervRootPartitionDeviceInterruptErrors,
		metricHypervRootPartitionDeviceInterruptThrottleEvents,
		metricHypervRootPartitionIOTLBFlush,
		metricHypervRootPartitionVirtualTLBPages,
		metricHypervRootPartitionVirtualTLBFlushEntries,
	} {
		for _, pm := range pms.FindByName(v) {
			name := strings.TrimPrefix(pm.Name(), "windows_")
			mx[name] = int64(pm.Value)
		}
	}

	w.collectHypervVM(mx, pms)
	w.collectHypervVMDevices(mx, pms)
	w.collectHypervVMInterface(mx, pms)
	w.collectHypervVSwitch(mx, pms)
}

func (w *Windows) collectHypervVM(mx map[string]int64, pms prometheus.Series) {
	seen := make(map[string]bool)
	px := "hyperv_vm_"

	for _, v := range []string{
		metricHypervVMMemoryPhysical,
		metricHypervVMMemoryPhysicalGuestVisible,
		metricHypervVMMemoryPressureCurrent,
		metricsHypervVMCPUGuestRunTime,
		metricsHypervVMCPUHypervisorRunTime,
		metricsHypervVMCPURemoteRunTime,
	} {
		for _, pm := range pms.FindByName(v) {
			if vm := pm.Labels.Get("vm"); vm != "" {
				name := strings.TrimPrefix(pm.Name(), "windows_hyperv_vm")
				seen[vm] = true
				mx[px+hypervCleanName(vm)+name] += int64(pm.Value)
			}
		}
	}

	px = "hyperv_vid_"
	for _, v := range []string{
		metricHyperVVIDPhysicalPagesAllocated,
		metricHyperVVIDRemotePhysicalPages,
	} {
		for _, pm := range pms.FindByName(v) {
			if vm := pm.Labels.Get("vm"); vm != "" {
				name := strings.TrimPrefix(pm.Name(), "windows_hyperv_vid")
				seen[vm] = true
				mx[px+hypervCleanName(vm)+name] = int64(pm.Value)
			}
		}
	}

	for v := range seen {
		if !w.cache.hypervVMMem[v] {
			w.cache.hypervVMMem[v] = true
			w.addHypervVMCharts(v)
		}
	}
	for v := range w.cache.hypervVMMem {
		if !seen[v] {
			delete(w.cache.hypervVMMem, v)
			w.removeHypervVMCharts(v)
		}
	}
}

func (w *Windows) collectHypervVMDevices(mx map[string]int64, pms prometheus.Series) {
	seen := make(map[string]bool)
	px := "hyperv_vm_device_"

	for _, v := range []string{
		metricHypervVMDeviceBytesRead,
		metricHypervVMDeviceBytesWritten,
		metricHypervVMDeviceOperationsRead,
		metricHypervVMDeviceOperationsWritten,
		metricHypervVMDeviceErrorCount,
	} {
		for _, pm := range pms.FindByName(v) {
			if device := pm.Labels.Get("vm_device"); device != "" {
				name := strings.TrimPrefix(pm.Name(), "windows_hyperv_vm_device")
				seen[device] = true
				mx[px+hypervCleanName(device)+name] = int64(pm.Value)
			}
		}
	}

	for v := range seen {
		if !w.cache.hypervVMDevices[v] {
			w.cache.hypervVMDevices[v] = true
			w.addHypervVMDeviceCharts(v)
		}
	}
	for v := range w.cache.hypervVMDevices {
		if !seen[v] {
			delete(w.cache.hypervVMDevices, v)
			w.removeHypervVMDeviceCharts(v)
		}
	}
}

func (w *Windows) collectHypervVMInterface(mx map[string]int64, pms prometheus.Series) {
	seen :=