Skip to content

Commit

Permalink
feat(vmguests): adding vm tools related metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
Danny Kulchinsky committed Jan 28, 2019
1 parent a71b193 commit 4c5322f
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
31 changes: 31 additions & 0 deletions tests/unit/test_vmware_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ def test_collect_vms():
'runtime.bootTime': boot_time,
'snapshot': snapshot,
'guest.disk': [disk],
'guest.toolsStatus': 'toolsOk',
'guest.toolsVersion': '10336',
'guest.toolsVersionStatus2': 'guestToolsUnmanaged',
}
})
yield collector._vmware_get_vms(metrics)
Expand Down Expand Up @@ -116,6 +119,34 @@ def test_collect_vms():
}
assert metrics['vmware_vm_guest_disk_capacity'].samples[0][2] == 100

# VM tools info (vmguest)
assert metrics['vmware_vm_guest_tools_running_status'].samples[0][1] == {
'vm_name': 'vm-1',
'host_name': 'host-1',
'cluster_name': 'cluster-1',
'dc_name': 'dc',
'tools_status': 'toolsOk',
}
assert metrics['vmware_vm_guest_tools_running_status'].samples[0][2] == 1.0

assert metrics['vmware_vm_guest_tools_version'].samples[0][1] == {
'vm_name': 'vm-1',
'host_name': 'host-1',
'cluster_name': 'cluster-1',
'dc_name': 'dc',
'tools_version': '10336',
}
assert metrics['vmware_vm_guest_tools_version'].samples[0][2] == 1.0

assert metrics['vmware_vm_guest_tools_version_status'].samples[0][1] == {
'vm_name': 'vm-1',
'host_name': 'host-1',
'cluster_name': 'cluster-1',
'dc_name': 'dc',
'tools_version_status': 'guestToolsUnmanaged',
}
assert metrics['vmware_vm_guest_tools_version_status'].samples[0][2] == 1.0

# Snapshots
assert metrics['vmware_vm_snapshots'].samples[0][1] == {
'vm_name': 'vm-1',
Expand Down
34 changes: 33 additions & 1 deletion vmware_exporter/vmware_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,18 @@ def _create_metric_containers(self):
'vmware_vm_guest_disk_capacity',
'Disk capacity metric per partition',
labels=['vm_name', 'host_name', 'dc_name', 'cluster_name', 'partition', ]),
'vmware_vm_guest_tools_running_status': GaugeMetricFamily(
'vmware_vm_guest_tools_running_status',
'VM tools running status',
labels=['vm_name', 'host_name', 'dc_name', 'cluster_name', 'tools_status', ]),
'vmware_vm_guest_tools_version': GaugeMetricFamily(
'vmware_vm_guest_tools_version',
'VM tools version',
labels=['vm_name', 'host_name', 'dc_name', 'cluster_name', 'tools_version', ]),
'vmware_vm_guest_tools_version_status': GaugeMetricFamily(
'vmware_vm_guest_tools_version_status',
'VM tools version status',
labels=['vm_name', 'host_name', 'dc_name', 'cluster_name', 'tools_version_status', ]),
}
metric_list['snapshots'] = {
'vmware_vm_snapshots': GaugeMetricFamily(
Expand Down Expand Up @@ -326,7 +338,12 @@ def vm_inventory(self):
])

if self.collect_only['vmguests'] is True:
properties.append('guest.disk')
properties.extend([
'guest.disk',
'guest.toolsStatus',
'guest.toolsVersion',
'guest.toolsVersionStatus2',
])

if self.collect_only['snapshots'] is True:
properties.append('snapshot')
Expand Down Expand Up @@ -604,6 +621,21 @@ def _vmware_get_vms(self, metrics):
labels + [disk.diskPath], disk.capacity
)

if 'guest.toolsStatus' in row:
metrics['vmware_vm_guest_tools_running_status'].add_metric(
labels + [row['guest.toolsStatus']], 1
)

if 'guest.toolsVersion' in row:
metrics['vmware_vm_guest_tools_version'].add_metric(
labels + [row['guest.toolsVersion']], 1
)

if 'guest.toolsVersionStatus2' in row:
metrics['vmware_vm_guest_tools_version_status'].add_metric(
labels + [row['guest.toolsVersionStatus2']], 1
)

if 'snapshot' in row:
snapshots = self._vmware_full_snapshots_list(row['snapshot'].rootSnapshotList)

Expand Down

0 comments on commit 4c5322f

Please sign in to comment.