Skip to content

Commit

Permalink
prometheus module: add format_down config param
Browse files Browse the repository at this point in the history
  • Loading branch information
bbusse committed Jun 17, 2023
1 parent 5eb4248 commit 37be1e2
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions py3status/modules/prometheus.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
format: Formatting of query result. Can refer to all labels from the query
result. Query value placeholder __v.
(default "{__v:.0f}")
format_down: Output if prometheus is not available
(default 'n/a')
join: If query returned multiple rows, join them using this string.
If you want to show just one, update your query.
(default None)
Expand Down Expand Up @@ -53,6 +55,7 @@ class Py3status:
# available configuration parameters
color = None
format = "{__v:.0f}"
format_down = "n/a"
join = None
query = None
query_interval = 60
Expand All @@ -65,6 +68,12 @@ def prometheus(self):
rows = self._query(self.query)
res = []

if not rows:
return dict(
full_text=self.format_down,
cached_until=self.py3.time_in(self.query_interval),
)

for row in rows:
val = float(row["value"][1])
if self.units:
Expand Down

0 comments on commit 37be1e2

Please sign in to comment.