@@ -49,7 +49,7 @@ def __init__(
4949
5050 self .version = UptimeKumaVersion ()
5151
52- async def metrics (self ) -> dict [str , UptimeKumaMonitor ]:
52+ async def metrics (self ) -> dict [str | int , UptimeKumaMonitor ]:
5353 """Retrieve metrics from Uptime Kuma.
5454
5555 Fetches and parses Prometheus-style metrics from the Uptime Kuma API endpoint,
@@ -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 | int , dict [str , Any ]] = {}
7474 url = self ._base_url / "metrics"
7575
7676 try :
@@ -96,10 +96,13 @@ async def metrics(self) -> dict[str, UptimeKumaMonitor]:
9696 if not metric .name .startswith ("monitor" ):
9797 continue
9898 for sample in metric .samples :
99- if not (monitor_name := sample .labels .get ("monitor_name" )):
100- continue
99+ key = (
100+ int (monitor_id )
101+ if (monitor_id := sample .labels .get ("monitor_id" ))
102+ else sample .labels ["monitor_name" ]
103+ )
101104
102- monitors .setdefault (monitor_name , sample .labels ).update (
105+ monitors .setdefault (key , sample .labels ).update (
103106 {sample .name : sample .value }
104107 )
105108
0 commit comments