Skip to content
This repository has been archived by the owner on Jul 23, 2018. It is now read-only.

vmware_dc_cluster_host_vm_info metric #36

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ pytz
pyvmomi>=6.5
twisted>=14.0.2
yamlconfig
pyasn1
service-identity
30 changes: 29 additions & 1 deletion vmware_exporter/vmware_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())


Expand Down Expand Up @@ -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))

Expand Down Expand Up @@ -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',
Expand Down