prometheus: do not set empty list as string as name (#62964)

This commit is contained in:
Frédéric Péters 2022-03-20 13:20:22 +01:00
parent 5a0dd085e9
commit e24269f671
1 changed files with 7 additions and 2 deletions

View File

@ -230,8 +230,13 @@ def units(ctn):
manager = dbus.Interface(s, "org.freedesktop.systemd1.Manager")
units = manager.ListUnits()
n = len([u for u in units if u[3] == "failed" and not u[0].startswith("user@")])
name = [u[0].replace('dbus.String', '') for u in units if u[3] == "failed" and not u[0].startswith("user@")]
eo_units.labels(ctn, name, "failed").set(n)
name = [
u[0].replace('dbus.String', '') for u in units if u[3] == "failed" and not u[0].startswith("user@")
]
if name:
eo_units.labels(ctn, name, "failed").set(n)
else:
eo_units.labels(ctn, "failed").set(n)
def run_in_machines(ctn):