+ self.cred = vim_account["prometheus-config"]["prometheus_cred"]
+ self.map = vim_account["prometheus-config"]["prometheus_map"]
+ self.client = self._build_prometheus_client(vim_account)
+
+ def _build_prometheus_client(self, vim_account: dict) -> prometheus_client:
+ url = vim_account["prometheus-config"]["prometheus_url"]
+ return prometheus_client(url, disable_ssl = True)
+
+ def collect_metric(
+ self, metric_type: MetricType, metric_name: str, resource_id: str
+ ):
+ metric = self.query_metric(metric_name, resource_id)
+ return metric["value"][1] if metric else None
+
+ def map_metric(self, metric_name: str):
+ return self.map[metric_name]
+
+ def query_metric(self, metric_name, resource_id = None):
+ metrics = self.client.get_current_metric_value(metric_name = metric_name)
+ if resource_id:
+ metric = next(filter(lambda x: resource_id in x["metric"]["resource_id"], metrics))
+ return metric
+ return metrics