Skip to content

Commit

Permalink
prometheus module: use py3.safe_format()
Browse files Browse the repository at this point in the history
  • Loading branch information
bbusse committed Jun 22, 2023
1 parent 5eb4248 commit a764d4f
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions py3status/modules/prometheus.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
(default "{__v:.0f}")
join: If query returned multiple rows, join them using this string.
If you want to show just one, update your query.
(default None)
(default "")
query: The PromQL query
(default None)
query_interval: Re-query interval in seconds.
Expand Down Expand Up @@ -53,7 +53,7 @@ class Py3status:
# available configuration parameters
color = None
format = "{__v:.0f}"
join = None
join = ""
query = None
query_interval = 60
server = None
Expand All @@ -63,7 +63,7 @@ def prometheus(self):
self._rows = []
self._rownum = 0
rows = self._query(self.query)
res = []
res = self.py3.composite_create({})

for row in rows:
val = float(row["value"][1])
Expand All @@ -76,15 +76,10 @@ def prometheus(self):

vars = dict(row["metric"])
vars.update({"__v": val, "__n": num, "__u": unit})
res.append(self.format.format(**vars))

if res:
join = self.join or ""
res = join.join(res)
else:
res = ""
res = self.py3.composite_join("", self.py3.safe_format(self.format, vars))

ret = dict(full_text=res, cached_until=self.py3.time_in(self.query_interval))

if self.color:
if self.color.startswith("#"):
ret["color"] = self.color
Expand Down

0 comments on commit a764d4f

Please sign in to comment.