You are a senior full-stack engineer specializing in Python backend systems and DevOps tooling. Build a production-ready monitoring system in Python using **FastAPI** that covers five core monitoring domains:
1. **Website/Uptime Monitoring** — HTTP checks, response time measurement, status code validation, and downtime detection.
2. **Database Storage Monitoring** — Track disk usage, collection/table sizes, document/row counts, and storage growth trends; alert when thresholds are exceeded.
3. **Database Outage Detection** — Probe database connectivity and query health; detect and report connection failures, timeouts, and replication issues.
4. **Server Monitoring & Utilization** — Collect CPU, memory, disk I/O, and network metrics via `psutil`; alert when utilization exceeds defined thresholds.
## Target Databases
The system must support monitoring for all of the following databases:
- **MongoDB** — use `motor` (async) for connectivity checks, storage metrics, collection sizes, document counts, and replica set health.
- **PostgreSQL** — use `asyncpg` for connectivity checks, table sizes, row counts, and replication lag.
- **MySQL / MariaDB** — use `aiomysql` for connectivity checks, table sizes, and query health.
- **Redis** — use `aioredis` for connectivity checks, memory usage, key counts, and eviction metrics.
Each database monitor must be implemented as a standalone module so new database types can be added without modifying existing monitors.
## Technical Stack & Requirements
- **Framework:** FastAPI (Python)
- **Persistence:** Store all check results, historical metrics, and alert logs in MongoDB — design schemas to support trend queries over time
- **Scheduler:** Use `APScheduler` or `asyncio`-based polling for interval-driven checks; all checks must run asynchronously and never block each other
- **Error isolation:** Failures in one monitor must never crash the system — implement per-monitor error handling, graceful retries, and structured logging
- **Configuration:** Externalize all settings (URLs, connection strings, thresholds, polling intervals) into a `.env` file and `config.py` using `pydantic-settings`
## System Components
Build the following as distinct, cleanly separated modules:
- **`monitors/`** — Individual monitor implementations (`website`, `mongodb`, `postgresql`, `mysql`, `redis`, `server`)
- **`scheduler/`** — Orchestrates all polling intervals and dispatches monitor runs
- **`storage/`** — Data access layer for persisting and querying check results and metrics
- **`alerting/`** — Threshold evaluation and notification dispatch (log-based + webhook stub)
- **`api/`** — FastAPI routers exposing endpoints to: register monitors, retrieve current status, fetch historical metrics, and acknowledge alerts
- **`dashboard/`** — A simple HTML/JS status dashboard served by FastAPI showing live monitor states
## Code Quality Standards
- Production-level error handling and structured logging throughout (`loguru` or Python `logging`)
- Clear docstrings and inline comments explaining each module's responsibility
- Pydantic models for all request/response schemas and internal data structures
- Basic unit tests for monitor logic using `pytest` and `pytest-asyncio`
## Deliverables
Provide the complete project structure, all source files with full working code, a `requirements.txt`, a `.env.example` config file, and setup/run instructions. The system must be runnable locally with `uvicorn`, a running MongoDB instance, and optionally connected target databases.
Login
Comments (0)
No comments yet. Be the first!
Sign in to leave a comment
Alerts
14
Monitor and acknowledge critical system events in real time.
🔴
+2 vs yesterday
7
Critical
Needs immediate action
⚠️
-3 vs yesterday
14
Warning
Monitor closely
✅
+11 vs yesterday
38
Resolved
Last 24 hours
📊
No change
59
Total Alerts
Across all monitors
Status
Type
Date Range
PostgreSQL: Connection Timeout on db-prod-01
db-prod-01Database3 minutes ago
Critical
Website Down: api.wise-monitoring.io returned 503
api.wise-monitoring.ioWebsite11 minutes ago
Critical
Server CPU Usage Exceeds 85% Threshold
app-server-02Server18 minutes ago
Warning
MongoDB: Replication Lag Detected on mongo-replica-01
mongo-replica-01Database34 minutes ago
Critical
Disk Usage at 91% on /dev/sda1
db-server-03Server52 minutes ago
Warning
Redis: High Memory Usage — 94% of maxmemory
redis-cache-01Database1 hour ago
Acknowledged
Website Response Time > 3s: dashboard.wise-monitoring.io
dashboard.wise-monitoring.ioWebsite1 hour ago
Warning
MySQL: Query Failure on analytics-db resolved
analytics-dbDatabase2 hours ago
Resolved
Server Memory Spike Resolved on app-server-01
app-server-01Server3 hours ago
Resolved
PostgreSQL: Disk Storage Critical — 98% Full on db-prod-02
db-prod-02Database4 hours ago
Critical
Network Throughput Anomaly Detected on edge-router-01
No comments yet. Be the first!