class Metric: """ Metric class abstract away the complexity of dealing with Prometheus data types. """ def __init__(self, name, metric_type, description, buckets): self.name = name self.type = metric_type if metric_type == 'Counter': self._metric = Counter(name, description) elif metric_type == 'Gauge': self._metric = Gauge(name, description) elif metric_type == 'Histogram': self._metric = Histogram(name, description, buckets=buckets) elif metric_type == 'Summary': self._metric = Summary(name, description) def report(self, value): value = float(value) if self.type == 'Counter': self._metric.inc(value) elif self.type == 'Gauge': self._metric.set(value) elif self.type == 'Histogram' or self.type == 'Summary': self._metric.observe(value)