uptime-kuma-api icon indicating copy to clipboard operation
uptime-kuma-api copied to clipboard

get_monitor_status for all monitors

Open kafisatz opened this issue 2 years ago • 2 comments

Great project, thanks! I would like to get the status of all monitors (number of up, down, pending, ....) I am not using any status pages right now.

The uptime kuma main webpage shows 'quick stats'. This is exactly what I want to get via API.

the snippet below takes about 15 seconds for 50 monitors, which is a bit inefficient.

    id = monitor["id"]
    st = api.get_monitor_status(id)

is there a better way to get all stati? I am only interested in the number of monitors that are up. I don't need the IDs.

kafisatz avatar Dec 13 '23 09:12 kafisatz

Hello same here, want to get the "Quick Stats" overview too.

Maybe using the /metrics end point of uptime-kuma is a workaround. Passing metrics to other platforms

Find all lines starting with "monitor_status" and have a look to the latest character of the line. # HELP monitor_status Monitor Status (1 = UP, 0= DOWN, 2= PENDING, 3= MAINTENANCE)

Noschvie avatar Mar 01 '24 17:03 Noschvie

FYI, I am now using a small python snippet to achieve this:

consider pip install playwright followed by playwright install

UPK_PW = "abcd"
UPK_USER = "uptimekuma"
UPK_URL = "https://uptimekuma.myurl.ch"

from time import sleep
import traceback
from playwright.sync_api import sync_playwright

def py_playwright_get_summary(UPK_PW,UPK_URL,UPK_USER):
    txt = "Up0Down999Maintenance0Unknown0Pause0"
    with sync_playwright() as p:
        browser_type = p.chromium
        browser = browser_type.launch()
        page = browser.new_page()
        page.goto(UPK_URL)
        
        page.get_by_label("Username").fill(UPK_USER)
        page.get_by_label("Password").fill(UPK_PW)
        page.get_by_role("button" ).click()
        sleep(3)
                
        txt = page.locator("#app > div > main > div > div > div.col-12.col-md-7.col-xl-8.mb-3 > div > div.shadow-box.big-padding.text-center.mb-4 > div").text_content()
        
        browser.close()
    return txt

abc = py_playwright_get_summary(UPK_PW,UPK_URL,UPK_USER)
print(abc)

kafisatz avatar Mar 04 '24 08:03 kafisatz