From 6a9bbbab04f3e118c546e925b183c685a766e483 Mon Sep 17 00:00:00 2001 From: Najmudheen Date: Fri, 18 Jun 2021 18:43:25 +0530 Subject: [PATCH] Adding code to check metrics dir exists --- delfin/exporter/prometheus/prometheus.py | 29 +++++++++++++----------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/delfin/exporter/prometheus/prometheus.py b/delfin/exporter/prometheus/prometheus.py index 1b155d2a8..95ca7406a 100644 --- a/delfin/exporter/prometheus/prometheus.py +++ b/delfin/exporter/prometheus/prometheus.py @@ -14,6 +14,7 @@ import datetime import os import pytz +import six from oslo_config import cfg from oslo_log import log @@ -63,7 +64,9 @@ def check_metrics_dir_exists(self, directory): os.makedirs(directory) return True except Exception as e: - LOG.error('Error while creating metrics directory') + msg = six.text_type(e) + LOG.error("Error while creating metrics directory. Reason: %s", + msg) return False def set_timestamp_offset_from_utc_ms(self): @@ -115,20 +118,20 @@ def push_to_prometheus(self, storage_metrics): resource_type = labels.get('resource_type') resource_id = labels.get('resource_id') unit = labels.get('unit') - type = labels.get('type', 'RAW') + m_type = labels.get('type', 'RAW') value_type = labels.get('value_type', 'gauge') prom_labels = ( - "storage_id=\"%s\"," - "storage_name=\"%s\"," - "storage_sn=\"%s\"," - "resource_type=\"%s\"," - "resource_id=\"%s\"," - "type=\"%s\"," - "unit=\"%s\"," - "value_type=\"%s\"" % - (storage_id, storage_name, storage_sn, resource_type, - resource_id, - type, unit, value_type)) + "storage_id=\"%s\"," + "storage_name=\"%s\"," + "storage_sn=\"%s\"," + "resource_type=\"%s\"," + "resource_id=\"%s\"," + "type=\"%s\"," + "unit=\"%s\"," + "value_type=\"%s\"" % + (storage_id, storage_name, storage_sn, resource_type, + resource_id, + m_type, unit, value_type)) name = labels.get('resource_type') + '_' + name self._write_to_prometheus_format(f, name, labels, prom_labels, values)