Skip to content

Commit

Permalink
Merge pull request #211 from phibos/fix_typo
Browse files Browse the repository at this point in the history
Fix typo and rename decription to documentation
  • Loading branch information
akpw authored Dec 24, 2024
2 parents 2aa6a63 + 6dbf0f5 commit 9fdae8f
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions mktxp/collector/base_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,50 +17,49 @@


class BaseCollector:
''' Base Collector methods
""" Base Collector methods
For use by custom collector
'''
"""
@staticmethod
def info_collector(name, decription, router_records, metric_labels=None):
def info_collector(name: str, documentation: str, router_records, metric_labels=None):
metric_labels = metric_labels or []
router_records = router_records or []

BaseCollector._add_id_labels(metric_labels)
collector = InfoMetricFamily(f'mktxp_{name}', decription)
collector = InfoMetricFamily(f'mktxp_{name}', documentation=documentation)

for router_record in router_records:
label_values = {label: router_record.get(label) if router_record.get(label) else '' for label in metric_labels}
collector.add_metric(metric_labels, label_values)
return collector

@staticmethod
def counter_collector(name, decription, router_records, metric_key, metric_labels=None):
def counter_collector(name: str, documentation: str, router_records, metric_key, metric_labels=None):
metric_labels = metric_labels or []
router_records = router_records or []

BaseCollector._add_id_labels(metric_labels)
collector = CounterMetricFamily(f'mktxp_{name}', decription, labels=metric_labels)
collector = CounterMetricFamily(f'mktxp_{name}', documentation=documentation, labels=metric_labels)

for router_record in router_records:
label_values = [router_record.get(label) if router_record.get(label) else '' for label in metric_labels]
collector.add_metric(label_values, router_record.get(metric_key, 0))
return collector

@staticmethod
def gauge_collector(name, decription, router_records, metric_key, metric_labels = None, add_id_labels = True):
def gauge_collector(name: str, documentation: str, router_records, metric_key, metric_labels = None, add_id_labels = True):
metric_labels = metric_labels or []
router_records = router_records or []

if add_id_labels:
BaseCollector._add_id_labels(metric_labels)
collector = GaugeMetricFamily(f'mktxp_{name}', decription, labels=metric_labels)
collector = GaugeMetricFamily(f'mktxp_{name}', documentation=documentation, labels=metric_labels)

for router_record in router_records:
label_values = [router_record.get(label) if router_record.get(label) else '' for label in metric_labels]
collector.add_metric(label_values, router_record.get(metric_key, 0))
return collector


# Helpers
@staticmethod
def _add_id_labels(metric_labels):
Expand Down

0 comments on commit 9fdae8f

Please sign in to comment.