Skip to content

Commit f9a6a51

Browse files
NouemanKHALclaude
andauthored
[nutanix] Fix vm.disk_capacity_bytes to source from VM config (DataDog#23583)
* fix(nutanix): emit vm.disk_capacity_bytes from VM config The metric was previously mapped from `diskCapacityBytes` in VM_STATS_METRICS, but the Nutanix v4 stats endpoint never returns that field, so the metric was effectively never emitted (and was parked in VM_STATS_METRICS_OPTIONAL, which silently let it slip). Source it from the VM config instead: sum vm.disks[].backingInfo.disk SizeBytes, the same approach memory.allocated_bytes uses for memorySizeBytes. Move the metric from VM_STATS_METRICS_OPTIONAL into VM_CAPACITY_METRICS so the test framework now enforces emission. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * docs(nutanix): add changelog fragment for vm.disk_capacity_bytes fix Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * docs(nutanix): trim disk_capacity_bytes changelog to one line Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent e93b772 commit f9a6a51

5 files changed

Lines changed: 16 additions & 3 deletions

File tree

nutanix/changelog.d/23583.fixed

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix `nutanix.vm.disk_capacity_bytes` to report allocated disk capacity per VM.

nutanix/datadog_checks/nutanix/infrastructure_monitor.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,14 @@ def _extract_vm_capacity(self, vm: dict) -> tuple[int, int, int, int, int]:
230230
memory_bytes = int(vm.get("memorySizeBytes") or 0)
231231
return num_sockets, num_cores_per_socket, num_threads_per_core, num_sockets * num_cores_per_socket, memory_bytes
232232

233+
def _extract_vm_disk_capacity_bytes(self, vm: dict) -> int:
234+
"""Sum allocated disk capacity across the VM's attached disks (config-sourced)."""
235+
return sum(
236+
int(get_nested(d, "backingInfo/diskSizeBytes") or 0) for d in vm.get("disks") or [] if isinstance(d, dict)
237+
)
238+
233239
def _report_vm_capacity_metrics(self, vm: dict, hostname: str, vm_tags: list[str]) -> None:
234-
"""Report VM capacity metrics (CPU and memory allocation)."""
240+
"""Report VM capacity metrics (CPU, memory, and disk allocation)."""
235241
num_sockets, num_cores_per_socket, num_threads_per_core, vcpus_allocated, memory_bytes = (
236242
self._extract_vm_capacity(vm)
237243
)
@@ -241,6 +247,9 @@ def _report_vm_capacity_metrics(self, vm: dict, hostname: str, vm_tags: list[str
241247
self.check.gauge("vm.cpu.threads_per_core", num_threads_per_core, hostname=hostname, tags=vm_tags)
242248
self.check.gauge("vm.cpu.vcpus_allocated", vcpus_allocated, hostname=hostname, tags=vm_tags)
243249
self.check.gauge("vm.memory.allocated_bytes", memory_bytes, hostname=hostname, tags=vm_tags)
250+
self.check.gauge(
251+
"vm.disk_capacity_bytes", self._extract_vm_disk_capacity_bytes(vm), hostname=hostname, tags=vm_tags
252+
)
244253

245254
def _report_cluster_basic_metrics(self, cluster: dict, cluster_tags: list[str]) -> None:
246255
"""Report basic cluster metrics (counts)."""

nutanix/datadog_checks/nutanix/metrics.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@
103103
"controllerWss3600SecondReadMb": "vm.controller.wss3600second_read_mb",
104104
"controllerWss3600SecondUnionMb": "vm.controller.wss3600second_union_mb",
105105
"controllerWss3600SecondWriteMb": "vm.controller.wss3600second_write_mb",
106-
"diskCapacityBytes": "vm.disk_capacity_bytes",
107106
"diskUsagePpm": "vm.disk_usage_ppm",
108107
"frameBufferUsagePpm": "vm.frame_buffer_usage_ppm",
109108
"gpuUsagePpm": "vm.gpu_usage_ppm",

nutanix/tests/metrics.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@
144144
"nutanix.vm.hypervisor.swap_in_rate_kbps",
145145
"nutanix.vm.hypervisor.swap_out_rate_kbps",
146146
"nutanix.vm.memory_usage_bytes",
147-
"nutanix.vm.disk_capacity_bytes",
148147
"nutanix.vm.disk_usage_ppm",
149148
"nutanix.vm.hypervisor.vm_running_time_usecs",
150149
]
@@ -190,6 +189,7 @@
190189
"nutanix.vm.cpu.threads_per_core",
191190
"nutanix.vm.cpu.vcpus_allocated",
192191
"nutanix.vm.memory.allocated_bytes",
192+
"nutanix.vm.disk_capacity_bytes",
193193
]
194194

195195
ALL_METRICS = (

nutanix/tests/test_capacity_metrics.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ def test_vm_capacity_metrics(dd_run_check, aggregator, mock_instance, mock_http_
4949
aggregator.assert_metric("nutanix.vm.memory.allocated_bytes", value=8589934592, tags=UBUNTU_VM_TAGS)
5050
aggregator.assert_metric("nutanix.vm.memory.allocated_bytes", value=8589934592, tags=RANDOM_VM_TAGS)
5151

52+
aggregator.assert_metric("nutanix.vm.disk_capacity_bytes", value=1118240243712, tags=PCVM_TAGS)
53+
aggregator.assert_metric("nutanix.vm.disk_capacity_bytes", value=21474836480, tags=UBUNTU_VM_TAGS)
54+
aggregator.assert_metric("nutanix.vm.disk_capacity_bytes", value=21474836480, tags=RANDOM_VM_TAGS)
55+
5256

5357
def test_host_capacity_metrics(dd_run_check, aggregator, mock_instance, mock_http_get):
5458
check = NutanixCheck('nutanix', {}, [mock_instance])

0 commit comments

Comments
 (0)