Skip to content

Commit

Permalink
using os.join for metrics file path
Browse files Browse the repository at this point in the history
  • Loading branch information
NajmudheenCT committed Jun 18, 2021
1 parent 8771404 commit 3e00bf7
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions delfin/exporter/prometheus/prometheus.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
]
cfg.CONF.register_opts(prometheus_opts, group=grp)


""""
The metrics received from driver is should be in this format
storage_metrics = [Metric(name='response_time',
Expand Down Expand Up @@ -89,8 +88,10 @@ def _write_to_prometheus_format(self, f, metric,
def push_to_prometheus(self, storage_metrics):
self.timestamp_offset_ms = self.set_timestamp_offset_from_utc_ms()
time_stamp = str(datetime.datetime.now().timestamp())
temp_file_name = self.metrics_dir + '/' + time_stamp + ".prom.temp"
actual_file_name = self.metrics_dir + '/' + time_stamp + ".prom"
temp_file_name = os.path.join(self.metrics_dir,
time_stamp + ".prom.temp")
actual_file_name = os.path.join(self.metrics_dir,
time_stamp + ".prom")
# make a temp file with current timestamp
with open(temp_file_name, "w") as f:
for metric in storage_metrics:
Expand All @@ -103,19 +104,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')
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,
'RAW', 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,
type, unit, value_type))
name = labels.get('resource_type') + '_' + name
self._write_to_prometheus_format(f, name, labels, prom_labels,
values)
Expand Down

0 comments on commit 3e00bf7

Please sign in to comment.