Skip to content

Commit 3bf2153

Browse files
committed
Use monitor_id as key if exists
1 parent 83f5b70 commit 3bf2153

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

pythonkuma/uptimekuma.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ async def metrics(self) -> dict[str, UptimeKumaMonitor]:
7070
If there is a connection error, timeout, or other client error during the
7171
request.
7272
"""
73-
monitors: dict[str, dict[str, Any]] = {}
73+
monitors: dict[str, dict[str | int, Any]] = {}
7474
url = self._base_url / "metrics"
7575

7676
try:
@@ -96,7 +96,11 @@ async def metrics(self) -> dict[str, UptimeKumaMonitor]:
9696
if not metric.name.startswith("monitor"):
9797
continue
9898
for sample in metric.samples:
99-
key = sample.labels.get("monitor_id", sample.labels["monitor_name"])
99+
key = (
100+
int(monitor_id)
101+
if (monitor_id := sample.labels.get("monitor_id"))
102+
else sample.labels["monitor_name"]
103+
)
100104

101105
monitors.setdefault(key, sample.labels).update(
102106
{sample.name: sample.value}

0 commit comments

Comments
 (0)