Server : Apache System : Linux iad1-shared-b8-43 6.6.49-grsec-jammy+ #10 SMP Thu Sep 12 23:23:08 UTC 2024 x86_64 User : dh_edsupp ( 6597262) PHP Version : 8.2.26 Disable Function : NONE Directory : /opt/prometheus-monitoring-scripts/lib/python3.10/site-packages/custom_exporters/ |
Upload File : |
import sys from prometheus_client import CollectorRegistry, generate_latest class BaseExporter(): def __init__(self, args=[]): self.args = args def run(self): self.metrics = JobMetric(self.metric_config()) return self.generate() def metric_config(self): return {} class JobMetric(): def __init__(self, stores={}): self._registry = CollectorRegistry() self.stores = stores self.metric_cache = {} def get(self, metric): if metric in self.metric_cache: return self.metric_cache[metric] else: try: store = self.stores[metric] mm = getattr( sys.modules['prometheus_client'], store['type'] ) mm_obj = mm( metric, '', store['labels'], registry=self._registry ) self.metric_cache[metric] = mm_obj return mm_obj except Exception: raise Exception("failed to create metric %s" % self.stores[metric]) def dump(self): return generate_latest(self._registry).decode('utf-8')