This repository has been archived by the owner on Jul 23, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 31
limit what data is collected via the config #33
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7f65594
limit what data is collected via the config
5b63746
Update vmware_exporter.py
Teriand a4531bd
Update vmware_exporter.py
Teriand b1fe881
Merge remote-tracking branch 'Teriand/master' into limit_subsystems
d43e38f
remove duplicate code (bad merge?)
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,12 @@ esx: | |
vmware_user: 'root' | ||
vmware_password: 'password' | ||
ignore_ssl: True | ||
|
||
limited: | ||
vmware_user: '[email protected]' | ||
vmware_password: 'password' | ||
ignore_ssl: True | ||
collect_only: | ||
# - vms | ||
- datastores | ||
- hosts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -97,7 +97,8 @@ def collect(self, target=None, section='default'): | |
if section not in self.config.keys(): | ||
print("{} is not a valid section, using default".format(section)) | ||
section='default' | ||
metrics = { | ||
metric_list ={} | ||
metric_list['vms'] = { | ||
'vmware_vm_power_state': GaugeMetricFamily( | ||
'vmware_vm_power_state', | ||
'VMWare VM Power state (On / Off)', | ||
|
@@ -117,7 +118,9 @@ def collect(self, target=None, section='default'): | |
'vmware_vm_num_cpu': GaugeMetricFamily( | ||
'vmware_vm_num_cpu', | ||
'VMWare Number of processors in the virtual machine', | ||
labels=['vm_name', 'host_name']), | ||
labels=['vm_name', 'host_name']) | ||
} | ||
metric_list['datastores'] = { | ||
'vmware_datastore_capacity_size': GaugeMetricFamily( | ||
'vmware_datastore_capacity_size', | ||
'VMWare Datasore capacity in bytes', | ||
|
@@ -141,7 +144,9 @@ def collect(self, target=None, section='default'): | |
'vmware_datastore_vms': GaugeMetricFamily( | ||
'vmware_datastore_vms', | ||
'VMWare Virtual Machines number using this datastore', | ||
labels=['ds_name']), | ||
labels=['ds_name']) | ||
} | ||
metric_list['hosts'] = { | ||
'vmware_host_power_state': GaugeMetricFamily( | ||
'vmware_host_power_state', | ||
'VMWare Host Power state (On / Off)', | ||
|
@@ -167,6 +172,19 @@ def collect(self, target=None, section='default'): | |
'VMWare Host Memory Max availability in Mbytes', | ||
labels=['host_name']), | ||
} | ||
collect_subsystems = self._collect_subsystems(section, metric_list.keys()) | ||
|
||
|
||
metrics = {} | ||
for s in collect_subsystems: | ||
metrics.update(metric_list[s]) | ||
|
||
|
||
collect_subsystems = self._collect_subsystems(section, metric_list.keys()) | ||
|
||
metrics = {} | ||
for s in collect_subsystems: | ||
metrics.update(metric_list[s]) | ||
|
||
print("[{0}] Start collecting vcenter metrics for {1}".format(datetime.utcnow().replace(tzinfo=pytz.utc), target)) | ||
|
||
|
@@ -177,28 +195,34 @@ def collect(self, target=None, section='default'): | |
|
||
content = self.si.RetrieveContent() | ||
|
||
# Get performance metrics counter information | ||
counter_info = self._vmware_perf_metrics(content) | ||
if 'vms' in collect_subsystems: | ||
# Get performance metrics counter information | ||
counter_info = self._vmware_perf_metrics(content) | ||
|
||
# Fill Snapshots (count and age) | ||
vm_counts, vm_ages = self._vmware_get_snapshots(content) | ||
for v in vm_counts: | ||
metrics['vmware_vm_snapshots'].add_metric([v['vm_name']], | ||
v['snapshot_count']) | ||
for vm_age in vm_ages: | ||
for v in vm_age: | ||
metrics['vmware_vm_snapshot_timestamp_seconds'].add_metric([v['vm_name'], | ||
v['vm_snapshot_name']], | ||
v['vm_snapshot_timestamp_seconds']) | ||
|
||
# Fill Datastore | ||
self._vmware_get_datastores(content, metrics) | ||
# Fill VM Informations | ||
self._vmware_get_vms(content, metrics, counter_info) | ||
|
||
# Fill VM Informations | ||
self._vmware_get_vms(content, metrics, counter_info) | ||
# Fill Snapshots (count and age) | ||
vm_counts, vm_ages = self._vmware_get_snapshots(content) | ||
for v in vm_counts: | ||
metrics['vmware_vm_snapshots'].add_metric([v['vm_name']], | ||
v['snapshot_count']) | ||
for vm_age in vm_ages: | ||
for v in vm_age: | ||
metrics['vmware_vm_snapshot_timestamp_seconds'].add_metric([v['vm_name'], | ||
v['vm_snapshot_name']], | ||
v['vm_snapshot_timestamp_seconds']) | ||
|
||
|
||
# Fill Datastore | ||
if 'datastores' in collect_subsystems: | ||
self._vmware_get_datastores(content, metrics) | ||
|
||
# Fill Hosts Informations | ||
self._vmware_get_hosts(content, metrics) | ||
if 'hosts' in collect_subsystems: | ||
self._vmware_get_hosts(content, metrics) | ||
|
||
|
||
print("[{0}] Stop collecting vcenter metrics for {1}".format(datetime.utcnow().replace(tzinfo=pytz.utc), target)) | ||
|
||
|
@@ -207,8 +231,50 @@ def collect(self, target=None, section='default'): | |
for metricname, metric in metrics.items(): | ||
yield metric | ||
|
||
def _collect_subsystems(self, section, valid_subsystems): | ||
""" | ||
Return the list of subsystems to collect - everything by default, a | ||
subset if the config section has collect_only specified | ||
""" | ||
collect_subsystems = [] | ||
|
||
if not self.config[section].get('collect_only'): | ||
collect_subsystems = valid_subsystems | ||
else: | ||
for subsystem in self.config[section].get('collect_only'): | ||
if subsystem in valid_subsystems: | ||
collect_subsystems.append(subsystem) | ||
else: | ||
print("invalid subsystem specified in collect_only: " + str(subsystem)) | ||
|
||
if not collect_subsystems: | ||
print("no valid subystems specified in collect_only, collecting everything") | ||
collect_subsystems = valid_subsystems | ||
|
||
return collect_subsystems | ||
|
||
|
||
def _collect_subsystems(self, section, valid_subsystems): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think there is a mistake here (duplicates) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. def _collect_subsystems There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably a bad merge by me, let me take a peek There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yikes, yeah, I'm gonna say bad merge; let me clean that up |
||
""" | ||
Return the list of subsystems to collect - everything by default, a | ||
subset if the config section has collect_only specified | ||
""" | ||
collect_subsystems = [] | ||
|
||
if not self.config[section].get('collect_only'): | ||
collect_subsystems = valid_subsystems | ||
else: | ||
for subsystem in self.config[section].get('collect_only'): | ||
if subsystem in valid_subsystems: | ||
collect_subsystems.append(subsystem) | ||
else: | ||
print("invalid subsystem specified in collect_only: " + str(subsystem)) | ||
|
||
if not collect_subsystems: | ||
print("no valid subystems specified in collect_only, collecting everything") | ||
collect_subsystems = valid_subsystems | ||
|
||
return collect_subsystems | ||
|
||
def _to_unix_timestamp(self, my_date): | ||
return ((my_date - datetime(1970,1,1,tzinfo=pytz.utc)).total_seconds()) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there is a mistake here (duplicates)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It thing mistake after merge.
In my fork another 183 line.