From 3122fb62d4c58a6668e435e3b633e5ebd2b631de Mon Sep 17 00:00:00 2001 From: Danny Kulchinsky Date: Tue, 1 May 2018 11:39:10 -0400 Subject: [PATCH 1/3] Initial commit --- vmware_exporter/vmware_exporter.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/vmware_exporter/vmware_exporter.py b/vmware_exporter/vmware_exporter.py index c0ebcdd..7416fd0 100755 --- a/vmware_exporter/vmware_exporter.py +++ b/vmware_exporter/vmware_exporter.py @@ -172,6 +172,12 @@ def collect(self, target=None, section='default'): 'VMWare Host Memory Max availability in Mbytes', labels=['host_name']), } + metric_list['metadata'] = { + 'vmware_dc_cluster_host_vm_info': GaugeMetricFamily( + 'vmware_dc_cluster_host_vm_info', + 'VMWare datacenter, cluster, host and vm info', + labels=['dc_name', 'cluster_name', 'host_name', 'vm_name']), + } collect_subsystems = self._collect_subsystems(section, metric_list.keys()) @@ -215,6 +221,10 @@ def collect(self, target=None, section='default'): # Fill Hosts Informations if 'hosts' in collect_subsystems: self._vmware_get_hosts(content, metrics) + + # Collect cluster metadata + if 'metadata' in collect_subsystems: + self._vmware_get_metadata(content, metrics) print("[{0}] Stop collecting vcenter metrics for {1}".format(datetime.utcnow().replace(tzinfo=pytz.utc), target)) @@ -465,6 +475,25 @@ def _vmware_get_hosts(self, content, host_metrics): float(summary.hardware.memorySize) / 1024 / 1024) + def _vmware_get_metadata(self, content, metadata_metrics): + """ + Get Metadata (Datacenter, cluster) information for hosts and VMs + """ + + children = content.rootFolder.childEntity + for child in children: # Iterate though DataCenters + dc = child + clusters = dc.hostFolder.childEntity + for cluster in clusters: # Iterate through the clusters in the DC + hosts = cluster.host + for host in hosts: # Iterate through Hosts in the Cluster + host_name = host.summary.config.name + vms = host.vm + for vm in vms: # Iterate through each VM on the host + vm_name = vm.summary.config.name + metadata_metrics['vmware_dc_cluster_host_vm_info'].add_metric([dc.name, cluster.name, host_name, vm_name], 1) + + def main(): parser = argparse.ArgumentParser(description='VMWare metrics exporter for Prometheus') parser.add_argument('-c', '--config', dest='config_file', From dcddb4bf58d2821ac0d3bf3700e20262461972b3 Mon Sep 17 00:00:00 2001 From: Danny Kulchinsky Date: Tue, 1 May 2018 21:34:12 -0400 Subject: [PATCH 2/3] Cleanup --- requirements.txt | 1 + vmware_exporter/vmware_exporter.py | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index a5b7bd8..de93fc6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,4 +3,5 @@ pytz pyvmomi>=6.5 twisted>=14.0.2 yamlconfig +pyasn1 service-identity diff --git a/vmware_exporter/vmware_exporter.py b/vmware_exporter/vmware_exporter.py index 7416fd0..97264dc 100755 --- a/vmware_exporter/vmware_exporter.py +++ b/vmware_exporter/vmware_exporter.py @@ -175,7 +175,7 @@ def collect(self, target=None, section='default'): metric_list['metadata'] = { 'vmware_dc_cluster_host_vm_info': GaugeMetricFamily( 'vmware_dc_cluster_host_vm_info', - 'VMWare datacenter, cluster, host and vm info', + 'VMWare datacenter cluster host and vm info', labels=['dc_name', 'cluster_name', 'host_name', 'vm_name']), } collect_subsystems = self._collect_subsystems(section, metric_list.keys()) @@ -477,7 +477,7 @@ def _vmware_get_hosts(self, content, host_metrics): def _vmware_get_metadata(self, content, metadata_metrics): """ - Get Metadata (Datacenter, cluster) information for hosts and VMs + Get Metadata (datacenter, cluster) information for hosts and VMs """ children = content.rootFolder.childEntity From 65819d7cd35217a12799d3994dbd3f27a4fb6cc3 Mon Sep 17 00:00:00 2001 From: Danny Kulchinsky Date: Tue, 1 May 2018 21:38:16 -0400 Subject: [PATCH 3/3] fix indents --- vmware_exporter/vmware_exporter.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/vmware_exporter/vmware_exporter.py b/vmware_exporter/vmware_exporter.py index 97264dc..14c65db 100755 --- a/vmware_exporter/vmware_exporter.py +++ b/vmware_exporter/vmware_exporter.py @@ -222,10 +222,9 @@ def collect(self, target=None, section='default'): if 'hosts' in collect_subsystems: self._vmware_get_hosts(content, metrics) - # Collect cluster metadata - if 'metadata' in collect_subsystems: - self._vmware_get_metadata(content, metrics) - + # Collect cluster metadata + if 'metadata' in collect_subsystems: + self._vmware_get_metadata(content, metrics) print("[{0}] Stop collecting vcenter metrics for {1}".format(datetime.utcnow().replace(tzinfo=pytz.utc), target))