Skip to content

Commit

Permalink
vmguests collect only option (pryorda#28)
Browse files Browse the repository at this point in the history
* adding a vmguests collect_only option
* Bump version

Precommit-Verified: 0cceb00c4d9b07d3a49346855a659db3b7c878992f5c8170c93afbd85e81d77a
  • Loading branch information
Danny Kulchinsky authored and pryorda committed Oct 15, 2018
1 parent d33d432 commit e6598e9
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ FROM python:2.7-alpine

LABEL MAINTAINER="Daniel Pryor <daniel@pryorda.net>"
LABEL NAME=vmware_exporter
LABEL VERSION=0.2.4
LABEL VERSION=0.2.5

WORKDIR /opt/vmware_exporter/

Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ If you want to limit the scope of the metrics gather you can update the subsyste

collect_only:
vms: False
vmguests: True
datastores: True
hosts: True
snapshots: True
Expand All @@ -50,6 +51,7 @@ default:
ignore_ssl: False
collect_only:
vms: True
vmguests: True
datastores: True
hosts: True
snapshots: True
Expand All @@ -61,6 +63,7 @@ esx:
ignore_ssl: True
collect_only:
vms: False
vmguests: True
datastores: False
hosts: True
snapshots: True
Expand All @@ -72,6 +75,7 @@ limited:
ignore_ssl: True
collect_only:
vms: False
vmguests: False
datastores: True
hosts: False
snapshots: False
Expand All @@ -89,6 +93,7 @@ limited:
| `VSPHERE_COLLECT_HOSTS` | config, env | True | Set to false to disable collection of host metrics |
| `VSPHERE_COLLECT_DATASTORES` | config, env | True | Set to false to disable collection of datastore metrics |
| `VSPHERE_COLLECT_VMS` | config, env | True | Set to false to disable collection of virtual machine metrics |
| `VSPHERE_COLLECT_VMGUESTS` | config, env | True | Set to false to disable collection of virtual machine guest metrics |
| `VSPHERE_COLLECT_SNAPSHOTS` | config, env | True | Set to false to disable collection of snapshot metrics |

### Prometheus configuration
Expand Down
76 changes: 54 additions & 22 deletions vmware_exporter/vmware_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def configure(self, args):
ignore_ssl: {3}
collect_only:
vms: True
vmguests: True
datastores: True
hosts: True
snapshots: True
Expand All @@ -76,6 +77,7 @@ def configure(self, args):
self.config['default']['collect_only']['hosts'] = os.environ.get('VSPHERE_COLLECT_HOSTS', True)
self.config['default']['collect_only']['datastores'] = os.environ.get('VSPHERE_COLLECT_DATASTORES', True)
self.config['default']['collect_only']['vms'] = os.environ.get('VSPHERE_COLLECT_VMS', True)
self.config['default']['collect_only']['vmguests'] = os.environ.get('VSPHERE_COLLECT_VMGUESTS', True)
self.config['default']['collect_only']['snapshots'] = os.environ.get('VSPHERE_COLLECT_SNAPSHOTS', True)

def render_GET(self, request):
Expand Down Expand Up @@ -166,6 +168,8 @@ def collect(self, vsphere_host, section='default'):
'vmware_vm_num_cpu',
'VMWare Number of processors in the virtual machine',
labels=['vm_name', 'host_name', 'dc_name', 'cluster_name']),
}
metric_list['vmguests'] = {
'vmware_vm_guest_disk_free': GaugeMetricFamily(
'vmware_vm_guest_disk_free',
'Disk metric per partition',
Expand Down Expand Up @@ -284,6 +288,12 @@ def collect(self, vsphere_host, section='default'):
self._vmware_get_vms(content, metrics, counter_info, host_inventory)
log("Finished VM performance metrics collection")

# Collect VMs metrics
if self.config[section]['collect_only']['vmguests'] is True:
log("Starting VM Guests metrics collection")
self._vmware_get_vmguests(content, metrics, host_inventory)
log("Finished VM Guests metrics collection")

# Collect Snapshots (count and age)
if self.config[section]['collect_only']['snapshots'] is True:
log("Starting VM snapshot metric collection")
Expand Down Expand Up @@ -517,18 +527,7 @@ def _vmware_get_vm_perf_metrics(self, content, counter_info, perf_list, virtual_
summary)
vm_metadata = [vm_name, vm_host_name, vm_dc_name, vm_cluster_name]

# We gather disk metrics
if len(virtual_machine.guest.disk) > 0:
[vm_metrics['vmware_vm_guest_disk_free'].add_metric(
[vm_name, vm_host_name, vm_dc_name, vm_cluster_name, disk.diskPath], disk.freeSpace)
for disk in virtual_machine.guest.disk]

[vm_metrics['vmware_vm_guest_disk_capacity'].add_metric(
[vm_name, vm_host_name, vm_dc_name, vm_cluster_name, disk.diskPath], disk.capacity)
for disk in virtual_machine.guest.disk]

vm_metrics['vmware_vm_power_state'].add_metric([vm_name, vm_host_name,
vm_dc_name, vm_cluster_name],
vm_metrics['vmware_vm_power_state'].add_metric(vm_metadata,
vm_power_state)
vm_metrics['vmware_vm_num_cpu'].add_metric(vm_metadata,
vm_num_cpu)
Expand Down Expand Up @@ -574,6 +573,35 @@ def _vmware_get_vm_perf_metric(self, content, counter_info, perf_metric,
log("Error, cannot get vm metric {0} for {1}".format(perf_metric_name,
vm_metadata))

def _vmware_get_vmguests(self, content, vmguest_metrics, inventory):
"""
Get VM Guest information
"""

virtual_machines = self._vmware_get_obj(content, [vim.VirtualMachine])
log("Total Virtual Machines: {0}".format(len(virtual_machines)))
for virtual_machine in virtual_machines:
self.threader.thread_it(self._vmware_get_vmguests_metrics,
[content, virtual_machine, vmguest_metrics, inventory])

def _vmware_get_vmguests_metrics(self, content, virtual_machine, vmguest_metrics, inventory):
"""
Get VM Guest Metrics
"""

summary = virtual_machine.summary

vm_name, vm_host_name, vm_dc_name, vm_cluster_name = self._vmware_vm_metadata(inventory, virtual_machine,
summary)

# gather disk metrics
if len(virtual_machine.guest.disk) > 0:
for disk in virtual_machine.guest.disk:
vmguest_metrics['vmware_vm_guest_disk_free'].add_metric(
[vm_name, vm_host_name, vm_dc_name, vm_cluster_name, disk.diskPath], disk.freeSpace)
vmguest_metrics['vmware_vm_guest_disk_capacity'].add_metric(
[vm_name, vm_host_name, vm_dc_name, vm_cluster_name, disk.diskPath], disk.capacity)

def _vmware_get_hosts(self, content, host_metrics, inventory):
"""
Get Host (ESXi) information
Expand All @@ -582,10 +610,11 @@ def _vmware_get_hosts(self, content, host_metrics, inventory):
for host in hosts:
summary = host.summary
host_name, host_dc_name, host_cluster_name = self._vmware_host_metadata(inventory, host)
host_metadata = [host_name, host_dc_name, host_cluster_name]

# Power state
power_state = 1 if summary.runtime.powerState == 'poweredOn' else 0
host_metrics['vmware_host_power_state'].add_metric([host_name, host_dc_name, host_cluster_name],
host_metrics['vmware_host_power_state'].add_metric(host_metadata,
power_state)

if power_state:
Expand All @@ -596,34 +625,37 @@ def _vmware_get_host_metrics(self, host_name, host_dc_name, host_cluster_name, h
"""
Get Host Metrics
"""

labels = [host_name, host_dc_name, host_cluster_name]

if summary.runtime.bootTime:
# Host uptime
host_metrics['vmware_host_boot_timestamp_seconds'].add_metric([host_name, host_dc_name, host_cluster_name],
host_metrics['vmware_host_boot_timestamp_seconds'].add_metric(labels,
self._to_epoch(
summary.runtime.bootTime)
)

# Host connection state (connected, disconnected, notResponding)
host_metrics['vmware_host_connection_state'].add_metric([host_name, host_dc_name, host_cluster_name,
summary.runtime.connectionState],
1)
metric_labels = labels
metric_labels.append(summary.runtime.connectionState)
host_metrics['vmware_host_connection_state'].add_metric(metric_labels, 1)

# Host in maintenance mode?
host_metrics['vmware_host_maintenance_mode'].add_metric([host_name, host_dc_name, host_cluster_name],
host_metrics['vmware_host_maintenance_mode'].add_metric(labels,
summary.runtime.inMaintenanceMode*1)

# CPU Usage (in Mhz)
host_metrics['vmware_host_cpu_usage'].add_metric([host_name, host_dc_name, host_cluster_name],
host_metrics['vmware_host_cpu_usage'].add_metric(labels,
summary.quickStats.overallCpuUsage)
cpu_core_num = summary.hardware.numCpuCores
cpu_total = summary.hardware.cpuMhz * cpu_core_num
host_metrics['vmware_host_cpu_max'].add_metric([host_name, host_dc_name, host_cluster_name],
host_metrics['vmware_host_cpu_max'].add_metric(labels,
cpu_total)

# Memory Usage (in MB)
host_metrics['vmware_host_memory_usage'].add_metric([host_name, host_dc_name, host_cluster_name],
host_metrics['vmware_host_memory_usage'].add_metric(labels,
summary.quickStats.overallMemoryUsage)
host_metrics['vmware_host_memory_max'].add_metric([host_name, host_dc_name, host_cluster_name],
host_metrics['vmware_host_memory_max'].add_metric(labels,
float(summary.hardware.memorySize) / 1024 / 1024)

def _vmware_get_inventory(self, content):
Expand Down

0 comments on commit e6598e9

Please sign in to comment.