Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions pythonkuma/uptimekuma.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def __init__(

self.version = UptimeKumaVersion()

async def metrics(self) -> dict[str, UptimeKumaMonitor]:
async def metrics(self) -> dict[str | int, UptimeKumaMonitor]:
"""Retrieve metrics from Uptime Kuma.

Fetches and parses Prometheus-style metrics from the Uptime Kuma API endpoint,
Expand All @@ -70,7 +70,7 @@ async def metrics(self) -> dict[str, UptimeKumaMonitor]:
If there is a connection error, timeout, or other client error during the
request.
"""
monitors: dict[str, dict[str, Any]] = {}
monitors: dict[str | int, dict[str, Any]] = {}
url = self._base_url / "metrics"

try:
Expand All @@ -96,10 +96,13 @@ async def metrics(self) -> dict[str, UptimeKumaMonitor]:
if not metric.name.startswith("monitor"):
continue
for sample in metric.samples:
if not (monitor_name := sample.labels.get("monitor_name")):
continue
key = (
int(monitor_id)
if (monitor_id := sample.labels.get("monitor_id"))
else sample.labels["monitor_name"]
)

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

Expand Down
Loading