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

Commit 4ee394a

Browse files
authored
Merge pull request #33 from britcey/limit_subsystems
limit what data is collected via the config
2 parents 88e2854 + d43e38f commit 4ee394a

File tree

3 files changed

+79
-20
lines changed

3 files changed

+79
-20
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,20 @@ Get VMWare VCenter information:
1616

1717
Alternatively, if you don't wish to install the package, run using `$ vmware_exporter/vmware_exporter.py`
1818

19+
### Limiting data collection
20+
21+
Large installations may have trouble collecting all of the data in a timely fashion,
22+
so you can limit which subsystems are collected by adding a
23+
`collect_only` argument the config section, e.g. under `default`:
24+
25+
collect_only:
26+
# - vms
27+
- datastores
28+
- hosts
29+
30+
would skip collecting information on the VMs. If there is no `collect_only`
31+
argument, everything will be collected as normal.
32+
1933
### Prometheus configuration
2034

2135
You can use the following parameters in prometheus configuration file. The `params` section is used to manage multiple login/passwords.

config.yml.sample

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,12 @@ esx:
77
vmware_user: 'root'
88
vmware_password: 'password'
99
ignore_ssl: True
10+
11+
limited:
12+
vmware_user: 'administrator@vsphere.local'
13+
vmware_password: 'password'
14+
ignore_ssl: True
15+
collect_only:
16+
# - vms
17+
- datastores
18+
- hosts

vmware_exporter/vmware_exporter.py

Lines changed: 56 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ def collect(self, target=None, section='default'):
9797
if section not in self.config.keys():
9898
print("{} is not a valid section, using default".format(section))
9999
section='default'
100-
metrics = {
100+
metric_list ={}
101+
metric_list['vms'] = {
101102
'vmware_vm_power_state': GaugeMetricFamily(
102103
'vmware_vm_power_state',
103104
'VMWare VM Power state (On / Off)',
@@ -117,7 +118,9 @@ def collect(self, target=None, section='default'):
117118
'vmware_vm_num_cpu': GaugeMetricFamily(
118119
'vmware_vm_num_cpu',
119120
'VMWare Number of processors in the virtual machine',
120-
labels=['vm_name', 'host_name']),
121+
labels=['vm_name', 'host_name'])
122+
}
123+
metric_list['datastores'] = {
121124
'vmware_datastore_capacity_size': GaugeMetricFamily(
122125
'vmware_datastore_capacity_size',
123126
'VMWare Datasore capacity in bytes',
@@ -141,7 +144,9 @@ def collect(self, target=None, section='default'):
141144
'vmware_datastore_vms': GaugeMetricFamily(
142145
'vmware_datastore_vms',
143146
'VMWare Virtual Machines number using this datastore',
144-
labels=['ds_name']),
147+
labels=['ds_name'])
148+
}
149+
metric_list['hosts'] = {
145150
'vmware_host_power_state': GaugeMetricFamily(
146151
'vmware_host_power_state',
147152
'VMWare Host Power state (On / Off)',
@@ -167,6 +172,12 @@ def collect(self, target=None, section='default'):
167172
'VMWare Host Memory Max availability in Mbytes',
168173
labels=['host_name']),
169174
}
175+
collect_subsystems = self._collect_subsystems(section, metric_list.keys())
176+
177+
178+
metrics = {}
179+
for s in collect_subsystems:
180+
metrics.update(metric_list[s])
170181

171182
print("[{0}] Start collecting vcenter metrics for {1}".format(datetime.utcnow().replace(tzinfo=pytz.utc), target))
172183

@@ -177,28 +188,34 @@ def collect(self, target=None, section='default'):
177188

178189
content = self.si.RetrieveContent()
179190

180-
# Get performance metrics counter information
181-
counter_info = self._vmware_perf_metrics(content)
191+
if 'vms' in collect_subsystems:
192+
# Get performance metrics counter information
193+
counter_info = self._vmware_perf_metrics(content)
182194

183-
# Fill Snapshots (count and age)
184-
vm_counts, vm_ages = self._vmware_get_snapshots(content)
185-
for v in vm_counts:
186-
metrics['vmware_vm_snapshots'].add_metric([v['vm_name']],
187-
v['snapshot_count'])
188-
for vm_age in vm_ages:
189-
for v in vm_age:
190-
metrics['vmware_vm_snapshot_timestamp_seconds'].add_metric([v['vm_name'],
191-
v['vm_snapshot_name']],
192-
v['vm_snapshot_timestamp_seconds'])
193195

194-
# Fill Datastore
195-
self._vmware_get_datastores(content, metrics)
196+
# Fill VM Informations
197+
self._vmware_get_vms(content, metrics, counter_info)
196198

197-
# Fill VM Informations
198-
self._vmware_get_vms(content, metrics, counter_info)
199+
# Fill Snapshots (count and age)
200+
vm_counts, vm_ages = self._vmware_get_snapshots(content)
201+
for v in vm_counts:
202+
metrics['vmware_vm_snapshots'].add_metric([v['vm_name']],
203+
v['snapshot_count'])
204+
for vm_age in vm_ages:
205+
for v in vm_age:
206+
metrics['vmware_vm_snapshot_timestamp_seconds'].add_metric([v['vm_name'],
207+
v['vm_snapshot_name']],
208+
v['vm_snapshot_timestamp_seconds'])
209+
210+
211+
# Fill Datastore
212+
if 'datastores' in collect_subsystems:
213+
self._vmware_get_datastores(content, metrics)
199214

200215
# Fill Hosts Informations
201-
self._vmware_get_hosts(content, metrics)
216+
if 'hosts' in collect_subsystems:
217+
self._vmware_get_hosts(content, metrics)
218+
202219

203220
print("[{0}] Stop collecting vcenter metrics for {1}".format(datetime.utcnow().replace(tzinfo=pytz.utc), target))
204221

@@ -207,8 +224,27 @@ def collect(self, target=None, section='default'):
207224
for metricname, metric in metrics.items():
208225
yield metric
209226

227+
def _collect_subsystems(self, section, valid_subsystems):
228+
"""
229+
Return the list of subsystems to collect - everything by default, a
230+
subset if the config section has collect_only specified
231+
"""
232+
collect_subsystems = []
233+
234+
if not self.config[section].get('collect_only'):
235+
collect_subsystems = valid_subsystems
236+
else:
237+
for subsystem in self.config[section].get('collect_only'):
238+
if subsystem in valid_subsystems:
239+
collect_subsystems.append(subsystem)
240+
else:
241+
print("invalid subsystem specified in collect_only: " + str(subsystem))
210242

243+
if not collect_subsystems:
244+
print("no valid subystems specified in collect_only, collecting everything")
245+
collect_subsystems = valid_subsystems
211246

247+
return collect_subsystems
212248

213249
def _to_unix_timestamp(self, my_date):
214250
return ((my_date - datetime(1970,1,1,tzinfo=pytz.utc)).total_seconds())

0 commit comments

Comments
 (0)