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 c0ebcdd..14c65db 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,7 +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 +474,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',