Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions pythonkuma/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ class UptimeKumaMonitor(UptimeKumaBaseModel):
monitor_response_time_seconds_30d: float | None = None
monitor_response_time_seconds_365d: float | None = None

monitor_tags: list[str]


@dataclass
class UptimeKumaVersion(UptimeKumaBaseModel):
Expand Down
19 changes: 18 additions & 1 deletion pythonkuma/uptimekuma.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@
)
from .models import UptimeKumaMonitor, UptimeKumaVersion

COMMON_LABELS = (
"monitor_id",
"monitor_name",
"monitor_type",
"monitor_url",
"monitor_hostname",
"monitor_port",
"window",
)


class UptimeKuma:
"""Uptime Kuma client."""
Expand Down Expand Up @@ -111,13 +121,20 @@ async def metrics(self) -> dict[str | int, UptimeKumaMonitor]:
else sample.labels["monitor_name"]
)

tags = [
f"{k}:{v}" if v else k
for k, v in sample.labels.items()
if k not in COMMON_LABELS
]
name = (
f"{sample.name}_{window}"
if (window := sample.labels.get("window"))
else sample.name
)

monitors.setdefault(key, sample.labels).update({name: sample.value})
monitors.setdefault(
key, {**sample.labels, "monitor_tags": tags}
).update({name: sample.value})

return {
key: UptimeKumaMonitor.from_dict(value) for key, value in monitors.items()
Expand Down
Loading