Skip to content

Commit

Permalink
error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
richardtief committed Nov 2, 2020
1 parent d2383e1 commit a5314bd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
10 changes: 8 additions & 2 deletions BaseCollector.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def __init__(self):
time.sleep(1800)
self.target = os.environ['TARGET']
# If metrics in collector-config are divided into rubrics
self.rubricated = False
self.rubric = os.environ.get('RUBRIC', None)

@abstractmethod
Expand Down Expand Up @@ -131,7 +132,8 @@ def iterate():
'vrops-exporter', labels=labelnames),
'statkey': statkey_pair['statkey']
}
if rubric:

if self.rubricated:
for statkey_pair in statkey_yaml[calling_class][rubric]:
iterate()
else:
Expand Down Expand Up @@ -201,7 +203,11 @@ def describe(self):
collector = self.__class__.__name__
if 'Stats' in collector:
statkey_yaml = self.read_collector_config()['statkeys']
if self.rubric:
if self.rubricated:
if not self.rubric:
if os.environ['DEBUG'] >= '1':
print(collector, "cannot work. There is no rubric given.\nSet a rubric as start parameter")
return
for statkey_pair in statkey_yaml[collector][self.rubric]:
statkey_suffix = statkey_pair['metric_suffix']
yield GaugeMetricFamily('vrops_' + self.vrops_entity_name + '_' + statkey_suffix.lower(),
Expand Down
6 changes: 6 additions & 0 deletions collectors/VMStatsCollector.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,14 @@ def __init__(self):
self.vrops_entity_name = 'virtualmachine'
self.wait_for_inventory_data()
self.name = self.__class__.__name__
self.rubricated = True

def collect(self):
if self.rubricated and not self.rubric:
if os.environ['DEBUG'] >= '1':
print(self.name, "cannot work. There is no rubric given.\nSet a rubric as start parameter.")
return

gauges = self.generate_gauges('stats', self.name, self.vrops_entity_name,
[self.vrops_entity_name, 'vcenter', 'datacenter', 'vccluster', 'hostsystem',
'project'], rubric=self.rubric)
Expand Down

0 comments on commit a5314bd

Please sign in to comment.