# Python uptime monitor

An uptime monitor checks one or more URLs, records status and latency, and alerts only when a site changes between up and down. Tokay runs the Python script as a Scheduled Service and preserves its SQLite history.

Start with Google and Example Domain to see two healthy checks before pointing it at your own service. The script exits after each pass, which keeps its schedule and failures easy to inspect.

## Facts

- Runtime: Python
- Framework: None
- Service types: Scheduled Service
- Resources: SQLite
- Required secrets: None

## What it does

Each run prints a result for every configured URL with its HTTP status, response time, and current up or down state.

The first observation establishes a baseline. A later state change writes one `ALERT` line and can send the same message to Slack or Discord.

Unchanged outages stay quiet on later runs, while the SQLite row count continues to show that checks are still happening.

## Deploy it

Bring this folder to Tokay any way you like. Paste or upload it in the dashboard, push it with git, or hand it to your AI agent along with [our agent instructions](https://app.tokay.io/llms.txt). Tokay figures out the rest.

Working in Claude, ChatGPT, VS Code, or another MCP client? Connect the [Tokay MCP server](https://tokay.io/docs/platform-mcp) and ask your agent to deploy this example. It signs in through your browser, so there is no token to paste.

New to Tokay? The [getting started guide](https://tokay.io/getting-started) walks you through your first deploy.

## Try it

1. Choose **Run Now** twice and compare the accumulated row count in both results.
2. Open **Saved Files** and confirm that `uptime.sqlite3` is present.
3. Deploy again and run one more check. The count continues from the same database.

## Watch your own site

Open the Service's **Environment** page and find `MONITOR_URLS` under **From your code**. Choose **Set shared value** and enter one URL or a comma separated list. If you leave off the scheme, the monitor uses `https`.

The first check records the starting state. A later change writes an `ALERT` line, so healthy runs and an unchanged outage do not keep notifying you.

To send that alert to Slack or Discord, add an incoming webhook as `ALERT_WEBHOOK_URL`. The run log still records the alert if delivery fails.

## How it works

You get one alert per change because the script reads the last saved state before inserting the new result. It delivers a webhook only when those states differ, then exits normally.

Tokay starts the next pass on schedule and keeps its run output. The SQLite file survives deployments and restarts. Read [Files and persistent storage](https://tokay.io/docs/persistent-storage) for the storage details.

## Secrets

| Name | Required | Purpose |
| --- | --- | --- |
| `ALERT_WEBHOOK_URL` | No | Sends state changes to a Slack or Discord incoming webhook. |

## Grow from here

Try the [Playwright price watcher](/examples/python-playwright-price-watcher) when each check needs a real browser and screenshot.

## Source files

- [monitor.py](https://tokay.io/examples/src/python-uptime-monitor/monitor.py)

## Download and source

- [Download the complete project](https://tokay.io/examples/downloads/python-uptime-monitor.zip)
- Last updated: 2026-07-31
- Example revision: `52c7b7f`
- [View this revision on GitHub](https://github.com/tokayio/tokay-examples/tree/52c7b7ffd52e157375b08f1f11ff4fbe6c498642/python-uptime-monitor)
- [Run a Python script every day](https://tokay.io/use-cases/run-python-script-every-day)
