Skip to content

Commit

Permalink
autopep8: Whitespace changes
Browse files Browse the repository at this point in the history
  • Loading branch information
fhemberger committed Sep 12, 2021
1 parent d97a80b commit ce138bb
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions mqtt_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,10 +349,10 @@ def _mqtt_init(mqtt_config, metrics):
def _export_to_prometheus(name, metric, labels):
"""Export metric and labels to prometheus."""
metric_wrappers = {'gauge': GaugeWrapper,
'counter': CounterWrapper,
'counter_absolute': CounterAbsoluteWrapper,
'summary': SummaryWrapper,
'histogram': HistogramWrapper}
'counter': CounterWrapper,
'counter_absolute': CounterAbsoluteWrapper,
'summary': SummaryWrapper,
'histogram': HistogramWrapper}
valid_types = metric_wrappers.keys()
if metric['type'] not in valid_types:
logging.error(
Expand All @@ -366,14 +366,14 @@ def _export_to_prometheus(name, metric, labels):
sorted_labels = _get_sorted_tuple_list(labels)
label_names, label_values = list(zip(*sorted_labels))


prometheus_metric = None
if not metric.get('prometheus_metric') or not metric['prometheus_metric'].get('parent'):
# parent metric not seen before, create metric
additional_parameters = metric.get('parameters', {})

metric_wrapper = metric_wrappers[metric['type']]
prometheus_metric = metric_wrapper(metric['name'], metric['help'], label_names, **additional_parameters)
metric_wrapper = metric_wrappers[metric['type']]
prometheus_metric = metric_wrapper(
metric['name'], metric['help'], label_names, **additional_parameters)
metric['prometheus_metric'] = {}
metric['prometheus_metric']['parent'] = prometheus_metric
else:
Expand All @@ -386,6 +386,7 @@ def _export_to_prometheus(name, metric, labels):
if logging.DEBUG >= logging.root.level: # log test data only in debugging mode
_log_test_data(metric, labels['topic'], value)


def _log_test_data(metric, topic, value):
try:
base_metric = metric['prometheus_metric']['parent'].metric.collect()
Expand Down Expand Up @@ -420,6 +421,7 @@ class GaugeWrapper():
"""
Wrapper to provide generic interface to Gauge metric
"""

def __init__(self, name, help_text, label_names, *args, **kwargs) -> None:
self.metric = prometheus.Gauge(
name, help_text, list(label_names)
Expand All @@ -430,10 +432,12 @@ def update(self, label_values, value):
child.set(value)
return child


class CounterWrapper():
"""
Wrapper to provide generic interface to Counter metric
"""

def __init__(self, name, help_text, label_names, *args, **kwargs) -> None:
self.metric = prometheus.Counter(
name, help_text, list(label_names)
Expand All @@ -444,6 +448,7 @@ def update(self, label_values, value):
child.inc(value)
return child


class CounterAbsoluteWrapper():
"""
Wrapper to provide generic interface to CounterAbsolute metric
Expand All @@ -459,6 +464,7 @@ def update(self, label_values, value):
child.set(value)
return child


class SummaryWrapper():
"""
Wrapper to provide generic interface to Summary metric
Expand All @@ -474,6 +480,7 @@ def update(self, label_values, value):
child.observe(value)
return child


class HistogramWrapper():
"""
Wrapper to provide generic interface to Summary metric
Expand Down

0 comments on commit ce138bb

Please sign in to comment.