Skip to content

Commit

Permalink
fix(vm_cpu_usage): add vm max cpu usage metric and test (#147)
Browse files Browse the repository at this point in the history
* add vm max cpu usage metric and test

* fix test issue
  • Loading branch information
alecorps authored and pryorda committed Oct 10, 2019
1 parent acfb94b commit a5e0b57
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tests/unit/test_vmware_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def test_collect_vms():
'runtime.powerState': 'poweredOn',
'summary.config.numCpu': 1,
'summary.config.memorySizeMB': 1024,
'runtime.maxCpuUsage': 2400,
'summary.config.template': False,
'runtime.bootTime': boot_time,
'snapshot': snapshot,
Expand Down Expand Up @@ -160,6 +161,7 @@ def test_collect_vms():
'runtime.powerState': 'poweredOn',
'summary.config.numCpu': 1,
'summary.config.memorySizeMB': 1024,
'runtime.maxCpuUsage': 2400,
'summary.config.template': False,
'runtime.bootTime': boot_time,
'snapshot': snapshot,
Expand All @@ -173,6 +175,7 @@ def test_collect_vms():
'runtime.powerState': 'poweredOff',
'summary.config.numCpu': 1,
'summary.config.memorySizeMB': 1024,
'runtime.maxCpuUsage': 2400,
'summary.config.template': False,
'runtime.bootTime': boot_time,
'snapshot': snapshot,
Expand All @@ -187,6 +190,7 @@ def test_collect_vms():
'runtime.powerState': 'poweredOff',
'summary.config.numCpu': 1,
'summary.config.memorySizeMB': 1024,
'runtime.maxCpuUsage': 2400,
'summary.config.template': False,
'runtime.bootTime': boot_time,
'snapshot': snapshot,
Expand Down Expand Up @@ -303,6 +307,14 @@ def test_collect_vms():
}
assert metrics['vmware_vm_memory_max'].samples[0][2] == 1024

# Max Cpu
assert metrics['vmware_vm_max_cpu_usage'].samples[0][1] == {
'vm_name': 'vm-1',
'host_name': 'host-1',
'cluster_name': 'cluster-1',
'dc_name': 'dc',
}
assert metrics['vmware_vm_max_cpu_usage'].samples[0][2] == 2400
assert metrics['vmware_vm_template'].samples[0][2] == 0.0


Expand Down Expand Up @@ -341,6 +353,7 @@ def test_metrics_without_hostaccess():
'runtime.powerState': 'poweredOn',
'summary.config.numCpu': 1,
'summary.config.memorySizeMB': 1024,
'runtime.maxCpuUsage': 2400,
'summary.config.template': False,
'runtime.bootTime': boot_time,
'guest.disk': [disk],
Expand Down
8 changes: 8 additions & 0 deletions vmware_exporter/vmware_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ def _create_metric_containers(self):
'vmware_vm_memory_max',
'VMWare VM Memory Max availability in Mbytes',
labels=['vm_name', 'host_name', 'dc_name', 'cluster_name']),
'vmware_vm_max_cpu_usage': GaugeMetricFamily(
'vmware_vm_max_cpu_usage',
'VMWare VM Cpu Max availability in hz',
labels=['vm_name', 'host_name', 'dc_name', 'cluster_name']),
'vmware_vm_template': GaugeMetricFamily(
'vmware_vm_template',
'VMWare VM Template (true / false)',
Expand Down Expand Up @@ -354,6 +358,7 @@ def vm_inventory(self):
'runtime.bootTime',
'summary.config.numCpu',
'summary.config.memorySizeMB',
'runtime.maxCpuUsage',
'summary.config.template',
])

Expand Down Expand Up @@ -765,6 +770,9 @@ def _vmware_get_vms(self, metrics):
if 'summary.config.memorySizeMB' in row:
metrics['vmware_vm_memory_max'].add_metric(labels, row['summary.config.memorySizeMB'])

if 'runtime.maxCpuUsage' in row:
metrics['vmware_vm_max_cpu_usage'].add_metric(labels, row['runtime.maxCpuUsage'])

if 'summary.config.template' in row:
metrics['vmware_vm_template'].add_metric(labels, row['summary.config.template'])

Expand Down

0 comments on commit a5e0b57

Please sign in to comment.