Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_monitor_status for all monitors #62

Open
kafisatz opened this issue Dec 13, 2023 · 2 comments
Open

get_monitor_status for all monitors #62

kafisatz opened this issue Dec 13, 2023 · 2 comments

Comments

@kafisatz
Copy link

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.

@Noschvie
Copy link

Noschvie commented Mar 1, 2024

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)

@kafisatz
Copy link
Author

kafisatz commented Mar 4, 2024

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants