Skip to main content

🖥️ Clockwerk (Uptime Monitor)

License: MIT Python Version PyPI - 0.1.0


Clockwerk is a Python application designed to monitor the availability and performance (latency or status) of various API Endpoints (URLs). It tracks the health of the monitored endpoint and stores the results in a database for future analysis and reporting. The application uses SQLalchemy's ORM-based database interaction to store results, and Asyncio's async sessions for asynchronous operations.

🚀 Key Features

  • 🔍 Monitors multiple endpoints
  • ⏱️ Tracks endpoint health and status with real-time status updates
  • 📊 Logs the latency and status code for each request
  • 🗃️ Stores monitoring results in a database of your own choice
  • ⚡ Supports asynchronous database operations to ensure high performance
  • 🚨 Sends alert message to report endpoint failure or latency
  • 🧩 Supports MySQL, PostgreSQL and SQLite

📦 Installation

pip install clockwerk 
poetry add clockwerk

🌎 Code Usage

Start by creating the necessary config models MonitorConfig, EmailConfig, DatabaseConfig.

# Import the necessary config-models and scheduling loop
from clockwerk.scheduler import scheduling_loop
from clockwerk.config import MonitorConfig, EmailConfig, DatabaseConfig
from clockwerk.models import Endpoint

# Create an instance of the MonitorConfig to specify monitored endpoints.
monitor_config = MonitorConfig(
    endpoints = [
        Endpoint(url: "https://test-exmaple.com", timeout=2, alert_threshold=3),
        Endpoint(url: "https://api_testpoint.org", timeout=3, alert_threshold=2)
    ], 
    check_interval = 60,        # Checks the specified endpoints every 60 seconds.
    latency_threshold = 1.5     # Raises an alert if the endpoint latency exceeds the specified number (seconds)
)

# Model for e-mail configuration used to raise and send alert messages.
email_config = EmailConfig(
    smtp_host="smtp.mailtrap.io",               # SMTP Host
    smtp_port=587,                              # Port to run your email alerts from
    email_from="randommail@yourdomain.com",     # Email address sending the alerts
    email_to="alerts@yourdomain.com"            # Email address receiving the alerts.
)

# Database configuration model (MySQL, PostgreSQL, SQLite)
db_config = DatabaseConfig(
    db_activation=True,             # Writes results to DB if True.
    db_driver="sqlite",             # Specify the desired DB platform.
    db_name="clockwerk.db",         # Identifying name for DB.
    db_user="root",                 # Identifying user for DB.
    db_password="SuperSecret123",   # Individual password for DB access.
    db_host="localhost",            # Host associated with current DB.
    db_port=1200                    # Available port to run DB connection on.
)

Utilise the config models to create an instance of scheduling_loop to run. As Clockwerk's monitor is an async function it can be run with either asyncio.run() or await.

# Import the necessary config-models and scheduling loop
import asyncio
from clockwerk.scheduler import scheduling_loop
from clockwerk.config import MonitorConfig, EmailConfig, DatabaseConfig
from clockwerk.models import Endpoint

# Run the scheduling loop (if running the loop from a synchronous context)
asyncio.run(scheduling_loop(
    monitor_config=monitor_config,
    email_config=email_config,
    db_config=db_config
))

# Run the scheduling loop (if running the loop from an asynchronous context)
await scheduling_loop(
    monitor_config=monitor_config,
    email_config=email_config,
    db_config=db_config
)

📋 Monitor & Endpoints

In order to properly configure the main scheduling_loop, Clockwerk requires a list of specified endpoints (URLs) scheduled for monitoring. These endpoints are passed in to the main configuration object (MonitorConfig), along with specifications detailing the interval between checks and maximum latency allowed: check_interval, latency_threshold.

Parameters Description
endpoints A list of endpoint-objects to monitor.
check_interval Time in seconds between each health check (Default: 60)
latency_threshold Max latency in seconds before triggering an alert (Default: 1.0)

✉️ E-mail Alerts

Additionally, Clockwerk supports asynchronous email alerts (aiohttp) sent to individual e-mails if monitored Endpoints fail their respective health check.

Parameters Description
smtp_host SMTP server for sending email alerts.
smtp_port SMTP port (Default: 587)
email_from Sender's e-mail address.
email_to Recipient's e-mail address.

♾️ Database Setup

Clockwerk supports asynchronous database operations, allowing users to dynamically store results in one of three currently supported database platforms: MySQL, PostgreSQL, SQLite Built on SQLalchemy's asynchronous sessions and ORM framework, allowing for quick and seamless database connection and storage. If the individual user does not require results stored in a database, simply set the DatabaseConfig's activation variable to False, db_activation=False. This disables any form of database connection used by the scheduling loop.

# To initialise database connectivity use a DatabaseConfig object to specify desired parameters.
from clockwerk.config import DatabaseConfig
Parameter Description
db_activation Enable/Disable database connection and storage (Default: False)
db_driver One of available drivers MySQL, PostgreSQL, SQLite
db_host Database host (e.g. localhost)
db_name Identifying name of the target database
db_user Username for database connection
db_password Password for database access
db_port Port used to connect to database

📈 Future Roadmap

Roadmap over future improvements and application extensions.

  • Slack / Webhook integration for alerts.
  • Docker support for deployment
  • Dashboard with data analysis and visualisation (Prometheus)

🤝 Contributing

Contributions to the application's future improvements are more than welcome. Feel free to open an issue or submit a pull request.

  1. Fork the repo
  2. Create a new branch (git checkout -b feature-name)
  3. Commit your changes (git commit -am "Add new feature")
  4. Push to the branch (git push origin feature-name)
  5. Open a Pull request

📝 Licensing

This project is licensed under MIT License.

Metadata

Release files for clockwerk 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for clockwerk 0.1.2
File Size Uploaded Provenance
clockwerk-0.1.2.tar.gz 18.9 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for clockwerk 0.1.2
File Interpreter ABI Platform
clockwerk-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 37.5 kB

Release files / clockwerk-0.1.2.tar.gz

Download URL clockwerk-0.1.2.tar.gz
Size 18.9 kB
Tags Source
SHA-256 checksum
How to use checksums
1bd14cdd8efbf9cfb75cf8e8117d7276b5f503a3b06870e80d0386430c2f45a3
BLAKE2b-256 checksum
How to use checksums
e498da12049ce935ca0f57eaca2e571ae3d62717b1c7fdeaa8d2b50263acc34a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.2

Release files / clockwerk-0.1.2-py3-none-any.whl

Download URL clockwerk-0.1.2-py3-none-any.whl
Size 18.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c2f7cd4897512cdaa59b3e12768c37a69688e6a71bf6da2871d52d2efbd9464c
BLAKE2b-256 checksum
How to use checksums
aced9d131cdab15501086d0bd9e11dcef2aeb94e7aefe21b9f91a9f28fa6169b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.2

Security for clockwerk 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page