This Ping Monitor is a comprehensive network monitoring solution with both a Python backend and Flutter frontend. It provides continuous monitoring of websites and hosts with real-time data visualization, dynamic configuration management, PostgreSQL database storage, and multiple alert mechanisms.
The Ping Monitor system consists of:
- Resolving website URLs to their corresponding IP addresses
- Measuring precise latency values in repetitive intervals
- Alerting via email when specific ping threshold values are exceeded
- PostgreSQL database storage for scalable data management
- CSV file fallback for legacy compatibility (
ping_results.csv) - Triggering desktop notifications and sound alerts for critical thresholds
- FastAPI HTTP server for modern REST API integration
- Docker-based PostgreSQL for easy database deployment
- Real-time dashboard showing all monitored URLs
- Interactive configuration management
- Historical data visualization with charts
- Dynamic URL management (add/edit/delete targets)
- Detailed per-URL statistics and performance metrics
- Cross-platform support (Web, macOS, iOS, Android)
| Package | Purpose | Version |
|---|---|---|
python-dotenv |
Handling of environment settings | ~1.0.1 |
requests |
Handling HTTP requests | ~2.32.3 |
plyer |
Cross-platform notifications | ~2.1.0 |
pygame |
Playing audio notifications | ~2.6.1 |
pync |
macOS desktop notifications | ~2.0.3 |
notify2 (*Linux only*) |
Linux desktop notifications | ~0.3.1 |
win10toast (*Windows only*) |
Windows desktop notifications | ~0.9 |
asyncpg |
PostgreSQL async database driver | β₯0.30.0 |
pydantic |
Data validation and serialization | β₯2.10.0 |
fastapi |
Modern Python web framework | β₯0.115.2 |
uvicorn |
ASGI server for FastAPI | β₯0.27.1 |
| Package | Purpose | Version |
|---|---|---|
http |
HTTP client for API communication | ^1.4.0 |
path_provider |
File system access | ^2.1.2 |
csv |
CSV data parsing | ^6.0.0 |
fl_chart |
Charts and data visualization | ^0.68.0 |
Dependencies are managed through
requirements.txt(Python) andpubspec.yaml(Flutter).
The Ping Monitor system uses a modern four-tier architecture:
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β PING MONITOR SYSTEM β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β Flutter Web βββββΊβ FastAPI βββββΊβ Python Monitor βββββΊβ PostgreSQL β
β localhost:8080 β β localhost:8000 β βdatabase_ping_ β β localhost:5432 β
β β β β β monitor.py β β β
β β’ Dashboard β β β’ REST API β β β’ Multi-URL β β β’ ping_results β
β β’ Settings β β β’ CORS Enabled β β Monitoring β β β’ Indexed Data β
β β’ Analytics β β β’ PostgreSQL β β β’ DB Logging β β β’ Async Pool β
β β’ URL Manager β β β’ Data API β β β’ Alerts β β β’ Docker β
β β’ Charts β β β’ Type Safety β β β’ Notifications β β β’ Persistence β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β β β β
βΌ βΌ βΌ βΌ
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β User Layer β β Service Layer β β Monitor Layer β β Data Layer β
β β β β β β β β
β β’ Web Browser β β β’ fastapi_app.pyβ β β’ Ping Engine β β β’ PostgreSQL DB β
β β’ Mobile App β β β’ JSON API β β β’ Thread Mgmt β β β’ .env config β
β β’ Desktop App β β β’ DB Queries β β β’ Config Watch β β β’ CSV fallback β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
- Configuration: Flutter frontend reads/writes to
.envvia FastAPI - Monitoring: Python backend pings URLs and logs to PostgreSQL database
- Database: PostgreSQL stores ping results with indexing for fast queries
- API: FastAPI serves structured data from database to frontend
- Visualization: Flutter displays real-time charts and status with proper data types
- Alerts: Python triggers notifications (email, desktop, audio)
- Persistence: Data survives restarts and provides historical analytics
| Component | Protocol | Port | Purpose |
|---|---|---|---|
| Flutter Web | HTTP | 8080 | User interface |
| FastAPI Server | HTTP/REST | 8000 | Data & config API |
| PostgreSQL | TCP/IP | 5432 | Database storage |
| Python Monitor | AsyncPG | - | Database logging |
| Docker Compose | HTTP | - | Container orchestration |
| SMTP Alerts | SMTP | 587 | Email notifications |
- Frontend: Auto-refresh every 10 seconds
- Backend: Configurable ping intervals (default: 30s)
- API: On-demand data serving with filtering
- Configuration: Live updates without restart
Zero-Downtime URL Management:
- Add/remove target URLs via Flutter frontend
- Automatic
.envfile monitoring every 2 seconds - Dynamic thread management for new/removed URLs
- No restart required for configuration changes
How it works:
- Edit URLs in Flutter settings
- Configuration saved to
.envfile - Python monitor detects file changes
- Automatically starts monitoring new URLs
- Stops monitoring removed URLs
- All without interrupting existing monitoring
To set up and run your Ping Monitor project:
Prerequisites:
- Python 3.13+ installed (Python 3.8+ supported)
- Flutter SDK installed (for frontend)
- Docker and Docker Compose (for PostgreSQL)
- Git
Step-by-step:
-
Clone this repository:
git clone git@github.com:LlewAdamson-tengen/PingMonitor.git cd PingMonitor -
Set up the backend:
# Create .env file from sample make setup-env # Install Python dependencies make install
-
π One-command startup (recommended):
make start-all # Starts PostgreSQL + Monitor + FastAPI + FlutterOR manually (in separate terminals):
# Start PostgreSQL database make database # Start monitoring with database make run-db # Start FastAPI server (in another terminal) make fastapi-server # Run Flutter app (in another terminal) make flutter-web
make start-all # Complete system with PostgreSQL
make stop-all # Stop everythingmake start-csv # Original CSV-based system
make stop-all # Stop everything| Command | Description |
|---|---|
make start-all |
Start PostgreSQL + Monitor + FastAPI + Flutter |
make start-csv |
Start legacy CSV-based system s |
make stop-all |
Stop all running processes and containers |
make database |
Start and initialize PostgreSQL only |
make run-db |
Start database-enabled monitoring only |
make fastapi-server |
Start FastAPI server only |
make flutter-web |
Start Flutter web app only |
-
Start the database (Terminal 1):
make database
-
Start database monitoring (Terminal 2):
make run-db
-
Start the FastAPI server (Terminal 3):
make fastapi-server
-
Launch Flutter frontend (Terminal 4):
make flutter-web # For web app make flutter-macos # For macOS app
- Dashboard: Real-time monitoring overview with status cards for each URL
- Settings: Dynamic configuration management with live editing of:
- Target URLs (add/edit/delete)
- SMTP settings
- Ping thresholds and intervals
- Alert configurations
- URL Details: Per-URL analytics with:
- Latency charts
- Status distribution pie charts
- Recent ping history
- Uptime statistics
- PostgreSQL database storage with indexing
- Real-time structured data with proper types
- Persistent historical data across restarts
- FastAPI REST endpoints with automatic documentation
- Async database connections for high performance
- CSV file logging (
ping_results.csv) - Simple HTTP API server
- File-based data storage
During alert events, notifications (email, desktop pop-ups, audible alerts) are triggered for immediate issue awareness.
To clean and reset your entire environment:
make cleanThis command:
- Deletes your current Python virtual environment (
.venv) - Clears Python caches (
__pycache__) - Reinstalls all requirements and runs the monitor fresh
Ping records are stored in a structured PostgreSQL database:
Table: ping_results
COLUMN | TYPE | DESCRIPTION
-----------------|-----------|---------------------------
id | SERIAL | Unique record identifier
timestamp | TIMESTAMP | When the ping was performed
url | VARCHAR | Target URL being monitored
ip | INET | Resolved IP address
status | VARCHAR | Success/High Latency/Ping Failure
response_time_ms | DECIMAL | Response time in milliseconds
count | INTEGER | Consecutive ping counterBenefits:
- β Indexed queries for fast data retrieval
- β Proper data types for charts and analytics
- β Persistent storage across system restarts
- β Structured queries with filtering and aggregation
Ping records can also be logged to ping_results.csv:
2025-03-11 13:52:48,21.579,0
2025-03-11 13:58:26,3458.861,0
2025-03-11 14:10:26,5566.672,0
- warnings count consecutive pings above your defined threshold
- Actual timestamps provide clear records of ping performance and historical data
PingMonitor/
βββ Backend (Python)
β βββ .venv/ # Virtual environment
β βββ database_ping_monitor.py # Database-enabled monitor (recommended)
β βββ PingMonitor.py # Legacy CSV-based monitor
β βββ fastapi_app.py # FastAPI server (PostgreSQL)
β βββ csv_server.py # Legacy HTTP API server
β βββ db_connect.py # Database connection manager
β βββ requirements.txt # Python dependencies
β βββ docker-compose.yml # PostgreSQL container config
β βββ scripts/db_init.sql # Database schema
β βββ .env # Environment configuration
β βββ sample.env # Sample configuration
β βββ ping_results.csv # Generated CSV data (legacy)
β βββ alert.mp3 # Alert sound file
β
βββ Frontend (Flutter)
β βββ pingmonitorflutter/
β β βββ lib/
β β β βββ main.dart # App entry point
β β β βββ models/ # Data models (updated for PostgreSQL)
β β β βββ screens/ # UI screens
β β β βββ services/ # API services
β β β βββ widgets/ # Reusable components
β β βββ pubspec.yaml # Flutter dependencies
β β βββ web/ # Web platform files
β
βββ Makefile # Build automation (updated commands)
βββ README.md # This file
βββ LICENSE # MIT License
| Endpoint | Method | Description | Parameters |
|---|---|---|---|
/ |
GET | API information and version | None |
/health |
GET | Health check and database status | None |
/ping-results/ |
GET | Retrieve ping data from database | url, limit, offset |
/ping-data |
GET | Flutter-compatible ping data alias | url, limit, offset |
/latest-status/ |
GET | Latest status for each monitored URL | None |
/statistics/{url}/ |
GET | Detailed statistics for specific URL | hours (time range) |
/cleanup/ |
DELETE | Clean up old ping results | days_to_keep |
| Endpoint | Method | Description | Parameters |
|-----------------|--------|--------------------------------------|----------------|
| `/health` | GET | Health check and system status | None |
| `/ping-data` | GET | Retrieve ping data from CSV | `url`, `limit` |
| `/url-statuses` | GET | Aggregated status for all URLs | None |
| `/env-config` | GET | Current `.env` configuration | None |
| `/env-config` | POST | Update `.env` configuration | JSON body |```
**Example Usage (FastAPI):**
```bash
# Get health status and database connection
curl http://localhost:8000/health
# Get recent ping data for specific URL
curl "http://localhost:8000/ping-data?url=google.com&limit=10"
# Get latest status for all monitored URLs
curl http://localhost:8000/latest-status/
# Get detailed statistics for a URL
curl http://localhost:8000/statistics/google.com/?hours=24
# View API documentation (FastAPI auto-generated)
open http://localhost:8000/docsUpdated all dependencies to support Python 3.13:
pygameupgraded from 2.5.0 β 2.6.1asyncpgupgraded to β₯0.30.0 with proper wheel supportpydanticupgraded to β₯2.10.0 with Python 3.13 compatibility
- Added PostgreSQL database support with Docker
- Implemented FastAPI for modern REST API
- Fixed data serialization issues (IP addresses, response times)
- Added proper indexing for fast queries
- Replaced
timeoutcommand with macOS-compatible shell scripts - Fixed background process management in Makefile
- Resolved Docker Compose environment variable issues
- Fixed data type mismatches (
response_time_msstring β number) - Corrected IP address serialization (removed CIDR notation)
- Updated Flutter models to match new API response format
- Enhanced debugging and error handling
- Fixed
make start-allandmake stop-allcommands - Improved background process management
- Added comprehensive database connection pooling
- Enhanced error handling and logging
- π’ macOS (with Docker Desktop)
- π’ Linux (with Docker and notify2 library)
- π’ Windows (with Docker Desktop and win10toast library)
- π’ Web browsers (Chrome, Firefox, Safari, Edge)
- π’ macOS (native app)
- π’ iOS (with Xcode)
- π’ Android (with Android Studio)
- π’ Linux (with Flutter Linux support)
- π’ Windows (with Flutter Windows support)
- Open issues clearly, make pull requests, and provide any feedback!
- Contributions (feature requests, bug fixes, enhancements) are welcome.
- DO NOT commit sensitive
.envfiles to version control as they might contain password/private credentials. - Use secure application-specific passwords for SMTP email integration.
MIT License Β© 2025 Llew Adamson
π Thank you for using Ping Monitor! Please reach out if you have any questions, found any bugs, or have some features you'd like to see. Happy Monitoring.