From 41381ac52780978cf4395dc427923f920bcadf27 Mon Sep 17 00:00:00 2001 From: Namudheen CT Date: Tue, 8 Dec 2020 14:43:20 +0530 Subject: [PATCH] Adding more labels to array leval metrics --- delfin/exporter/prometheus.py | 8 ++++++-- delfin/task_manager/tasks/resources.py | 12 ++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/delfin/exporter/prometheus.py b/delfin/exporter/prometheus.py index f17fdd2f6..46240cacf 100644 --- a/delfin/exporter/prometheus.py +++ b/delfin/exporter/prometheus.py @@ -56,13 +56,17 @@ def push_to_prometheus(self, storage_metrics): labels = metric.labels values = metric.values storage_id = labels.get('storage_id') + storage_name = labels.get('name') + storage_sn = labels.get('serial_number') resource_type = labels.get('resource_type') unit = unit_of_metric.get(name) value_type = labels.get('value_type', 'gauge') storage_labels = ( - "storage_id=\"%s\",resource_type=\"%s\"," + "storage_id=\"%s\",storage_name=\"%s\",storage_sn=\"%s\"," + "resource_type=\"%s\", " "type=\"%s\",unit=\"%s\",value_type=\"%s\"" % - (storage_id, resource_type, 'RAW', unit, value_type)) + (storage_id, storage_name, storage_sn, resource_type, + 'RAW', unit, value_type)) self._write_to_prometheus_format(f, name, storage_labels, values) diff --git a/delfin/task_manager/tasks/resources.py b/delfin/task_manager/tasks/resources.py index 3c9f55920..d1cecf7f0 100644 --- a/delfin/task_manager/tasks/resources.py +++ b/delfin/task_manager/tasks/resources.py @@ -272,6 +272,18 @@ def collect(self): array_metrics = self.driver_api.collect_array_metrics( self.context, self.storage_id, self.interval, self.is_historic) + # fill extra labels to metric by fetching metadata from resource DB + try: + array_details = db.storage_get(self.context, storage_id=self + .storage_id) + for m in array_metrics: + m.labels["name"] = array_details.name + m.labels["serial_number"] = array_details.serial_number + + except Exception as e: + msg = _('Failed to add extra labels to array performance ' + 'metrics: {0}'.format(e)) + LOG.error(msg) self.perf_exporter.dispatch(self.context, array_metrics)