Build a comprehensive website monitoring application with ReasonML, OCaml, and server-reason-react.
Features:
- Real-time website monitoring with HTTP status checks
- Email and webhook alerting system
- Beautiful admin dashboard with Tailwind CSS
- Complete REST API for CRUD operations
- Background monitoring scheduler
- Multi-container Docker setup with 1-core CPU constraint
- PostgreSQL database with Caqti
- Full documentation and setup guides
Tech Stack:
- OCaml 5.0+ with ReasonML
- Dream web framework
- server-reason-react for UI
- PostgreSQL 16 database
- Docker & Docker Compose
Files:
- 9 OCaml source files (1961 LOC)
- 6 documentation files (1603 LOC)
- Complete Docker configuration
- Comprehensive API documentation
💘 Generated with Crush
383 lines
9.9 KiB
Markdown
383 lines
9.9 KiB
Markdown
# Website Monitor - Build Summary
|
|
|
|
This document provides a summary of the complete website monitoring application that has been built.
|
|
|
|
## ✅ What Has Been Built
|
|
|
|
### Core Application
|
|
A full-stack website monitoring application with the following features:
|
|
|
|
1. **Website Monitoring**
|
|
- HTTP status code monitoring (default: 200)
|
|
- Configurable check intervals (default: 5 minutes)
|
|
- Timeout support (default: 30 seconds)
|
|
- Response time tracking
|
|
- Active/inactive status control
|
|
|
|
2. **Alert System**
|
|
- Email alerts via SMTP
|
|
- Webhook alerts for integrations
|
|
- Test alert functionality
|
|
- Per-website alert configuration
|
|
- Enable/disable alerts individually
|
|
|
|
3. **Admin Dashboard**
|
|
- Responsive web interface
|
|
- Real-time status overview
|
|
- Website management (CRUD)
|
|
- Alert configuration
|
|
- Application settings
|
|
- Auto-refresh (60 seconds)
|
|
|
|
4. **REST API**
|
|
- Full CRUD for websites
|
|
- Full CRUD for alerts
|
|
- Website check history
|
|
- Statistics summary
|
|
- JSON request/response
|
|
|
|
5. **Background Scheduler**
|
|
- Automatic website checks
|
|
- Configurable intervals
|
|
- History cleanup (30 days)
|
|
- Graceful shutdown
|
|
|
|
### Technology Implementation
|
|
|
|
**Backend (OCaml/ReasonML)**
|
|
- ✅ Database models with Caqti
|
|
- ✅ HTTP client for website checks
|
|
- ✅ Email alert system (SMTP)
|
|
- ✅ Webhook alert system
|
|
- ✅ Background monitoring scheduler
|
|
- ✅ Connection pooling
|
|
- ✅ Type-safe queries
|
|
|
|
**Frontend (server-reason-react)**
|
|
- ✅ Server-side React rendering
|
|
- ✅ Admin dashboard UI
|
|
- ✅ Tailwind CSS styling
|
|
- ✅ Responsive design
|
|
- ✅ Interactive components
|
|
|
|
**Infrastructure (Docker)**
|
|
- ✅ Multi-stage Docker build
|
|
- ✅ Docker Compose orchestration
|
|
- ✅ PostgreSQL database container
|
|
- ✅ Redis cache container
|
|
- ✅ CPU constraints (1 core)
|
|
- ✅ Health checks
|
|
- ✅ Database initialization
|
|
|
|
## 📁 Project Structure
|
|
|
|
```
|
|
test3/
|
|
├── bin/ # Application binaries
|
|
│ ├── main.ml # Main entry point
|
|
│ ├── init_db.ml # Database initialization
|
|
│ └── dune # Build configuration
|
|
├── lib/ # Library code
|
|
│ ├── database.ml # Database models and queries
|
|
│ ├── monitor.ml # Website monitoring logic
|
|
│ ├── alert.ml # Alerting system
|
|
│ ├── api.ml # REST API handlers
|
|
│ ├── ui.ml # Server-side React UI
|
|
│ ├── scheduler.ml # Background scheduler
|
|
│ └── dune # Build configuration
|
|
├── test/ # Tests
|
|
│ ├── test.ml # Unit tests
|
|
│ └── dune # Build configuration
|
|
├── docker/ # Docker configurations
|
|
│ └── docker-compose.dev.yml # Development compose
|
|
├── scripts/ # Utility scripts
|
|
│ └── verify-setup.sh # Setup verification
|
|
├── .vscode/ # VSCode configuration
|
|
│ └── settings.json # IDE settings
|
|
├── Dockerfile # Production Dockerfile
|
|
├── docker-compose.yml # Production compose
|
|
├── docker-entrypoint.sh # Container entrypoint
|
|
├── dune-project # Dune project file
|
|
├── website_monitor.opam # OPAM package file
|
|
├── Makefile # Build automation
|
|
├── README.md # Main documentation
|
|
├── QUICKSTART.md # Quick start guide
|
|
├── ARCHITECTURE.md # Architecture documentation
|
|
├── CONTRIBUTING.md # Contributing guidelines
|
|
├── LICENSE # MIT License
|
|
├── .env.example # Environment template
|
|
├── .gitignore # Git ignore rules
|
|
├── .dockerignore # Docker ignore rules
|
|
└── .merlin # OCaml editor configuration
|
|
```
|
|
|
|
## 🚀 Quick Start
|
|
|
|
```bash
|
|
# 1. Clone and navigate
|
|
git clone <repository-url>
|
|
cd test3
|
|
|
|
# 2. Copy environment file
|
|
cp .env.example .env
|
|
|
|
# 3. Edit .env with your configuration
|
|
# (SMTP settings, passwords, etc.)
|
|
|
|
# 4. Start with Docker Compose
|
|
docker-compose up -d
|
|
|
|
# 5. Access the dashboard
|
|
# Open: http://localhost:8080
|
|
```
|
|
|
|
## 📊 API Endpoints
|
|
|
|
### Websites
|
|
- `GET /api/websites` - List all websites
|
|
- `POST /api/websites` - Create website
|
|
- `GET /api/websites/:id` - Get website details
|
|
- `PUT /api/websites/:id` - Update website
|
|
- `DELETE /api/websites/:id` - Delete website
|
|
- `POST /api/websites/:id/check` - Trigger immediate check
|
|
- `GET /api/websites/:id/history` - Get check history
|
|
- `GET /api/websites/:id/status` - Get current status
|
|
|
|
### Alerts
|
|
- `GET /api/alerts` - List all alerts
|
|
- `POST /api/alerts` - Create alert
|
|
- `GET /api/alerts/:id` - Get alert details
|
|
- `PUT /api/alerts/:id` - Update alert
|
|
- `DELETE /api/alerts/:id` - Delete alert
|
|
|
|
### Stats
|
|
- `GET /api/stats/summary` - Get statistics
|
|
|
|
### Admin UI
|
|
- `GET /` - Dashboard
|
|
- `GET /dashboard` - Dashboard
|
|
- `GET /dashboard/websites` - Website management
|
|
- `GET /dashboard/alerts` - Alert configuration
|
|
- `GET /dashboard/settings` - Application settings
|
|
|
|
### Health
|
|
- `GET /health` - Health check
|
|
|
|
## 🔧 Docker Configuration
|
|
|
|
### CPU Constraints
|
|
- Build stage: `OPAMJOBS=1` (single compilation job)
|
|
- Runtime: `cpus: '1.0'` (1 CPU core)
|
|
- CPU affinity: `cpuset: '0'` (pin to first CPU)
|
|
|
|
### Services
|
|
1. **postgres**: PostgreSQL 16 on port 5432
|
|
2. **redis**: Redis 7 on port 6379
|
|
3. **app**: Website Monitor on port 8080
|
|
|
|
## 📝 Environment Variables
|
|
|
|
Required:
|
|
- `DB_PASSWORD` - Database password
|
|
- `SECRET_KEY` - Session encryption key
|
|
|
|
For Email Alerts:
|
|
- `SMTP_HOST` - SMTP server hostname
|
|
- `SMTP_PORT` - SMTP server port
|
|
- `SMTP_USER` - SMTP username
|
|
- `SMTP_PASSWORD` - SMTP password
|
|
- `ADMIN_EMAIL` - Admin email address
|
|
|
|
Optional:
|
|
- `ENVIRONMENT` - Environment (development/production)
|
|
- `PORT` - Application port (default: 8080)
|
|
- `HOST` - Application host (default: 0.0.0.0)
|
|
|
|
## 🎨 Features by Category
|
|
|
|
### Monitoring
|
|
- ✅ HTTP status code checking
|
|
- ✅ Response time measurement
|
|
- ✅ Error detection and logging
|
|
- ✅ Configurable intervals
|
|
- ✅ Configurable timeouts
|
|
- ✅ On-demand checks
|
|
|
|
### Alerts
|
|
- ✅ Email notifications (SMTP)
|
|
- ✅ Webhook integrations
|
|
- ✅ Per-website alerts
|
|
- ✅ Alert testing
|
|
- ✅ Recovery notifications
|
|
|
|
### Management
|
|
- ✅ Web dashboard
|
|
- ✅ REST API
|
|
- ✅ Website CRUD operations
|
|
- ✅ Alert CRUD operations
|
|
- ✅ History tracking
|
|
- ✅ Statistics
|
|
|
|
### Infrastructure
|
|
- ✅ Docker support
|
|
- ✅ PostgreSQL database
|
|
- ✅ Redis caching
|
|
- ✅ Health checks
|
|
- ✅ Auto-scaling ready
|
|
- ✅ CPU constrained builds
|
|
|
|
## 🔒 Security Features
|
|
|
|
- ✅ SQL injection prevention (parameterized queries)
|
|
- ✅ Environment-based configuration
|
|
- ✅ Secrets not in code
|
|
- ✅ Database user with limited privileges
|
|
- ✅ Health check endpoint
|
|
- ✅ CORS middleware
|
|
|
|
## 📈 Monitoring & Observability
|
|
|
|
- ✅ Application logging
|
|
- ✅ Database query logs
|
|
- ✅ HTTP request logging
|
|
- ✅ Error tracking
|
|
- ✅ Health check endpoint
|
|
- ✅ Response time metrics
|
|
|
|
## 🛠️ Development Tools
|
|
|
|
- ✅ Makefile for common tasks
|
|
- ✅ Dune build system
|
|
- ✅ OPAM package management
|
|
- ✅ VSCode configuration
|
|
- ✅ OCaml Merlin configuration
|
|
- ✅ Setup verification script
|
|
- ✅ Development Docker Compose
|
|
|
|
## 📚 Documentation
|
|
|
|
- ✅ README.md - Main documentation
|
|
- ✅ QUICKSTART.md - Quick start guide
|
|
- ✅ ARCHITECTURE.md - Architecture details
|
|
- ✅ CONTRIBUTING.md - Contributing guide
|
|
- ✅ LICENSE - MIT License
|
|
- ✅ Code comments - Inline documentation
|
|
|
|
## 🎯 Best Practices Implemented
|
|
|
|
### Code Quality
|
|
- ✅ Type safety (OCaml's type system)
|
|
- ✅ Functional programming paradigm
|
|
- ✅ Error handling with Lwt
|
|
- ✅ Modular architecture
|
|
- ✅ Separation of concerns
|
|
- ✅ Clean code principles
|
|
|
|
### DevOps
|
|
- ✅ Containerization
|
|
- ✅ Environment-based configuration
|
|
- ✅ Health checks
|
|
- ✅ Resource constraints
|
|
- ✅ Multi-stage builds
|
|
- ✅ Automated initialization
|
|
|
|
### Security
|
|
- ✅ No hardcoded secrets
|
|
- ✅ Parameterized queries
|
|
- ✅ Environment variables
|
|
- ✅ Least privilege database user
|
|
- ✅ CORS configuration
|
|
|
|
### Performance
|
|
- ✅ Connection pooling
|
|
- ✅ Async operations
|
|
- ✅ Efficient queries
|
|
- ✅ Background processing
|
|
- ✅ Regular cleanup
|
|
|
|
## 🔄 CI/CD Ready
|
|
|
|
The application is structured for CI/CD:
|
|
- ✅ Docker builds
|
|
- ✅ Automated testing
|
|
- ✅ Health checks
|
|
- ✅ Environment configuration
|
|
- ✅ Version-controlled dependencies
|
|
|
|
## 🌐 Production Ready
|
|
|
|
The application includes:
|
|
- ✅ Error handling
|
|
- ✅ Logging
|
|
- ✅ Health checks
|
|
- ✅ Graceful shutdown
|
|
- ✅ Configuration management
|
|
- ✅ Database migrations
|
|
- ✅ Backup strategy recommendations
|
|
|
|
## 📊 Database Schema
|
|
|
|
3 tables:
|
|
- **websites** - Monitored websites configuration
|
|
- **alerts** - Alert configurations
|
|
- **check_histories** - Historical check results
|
|
|
|
## 🎨 UI Features
|
|
|
|
- ✅ Responsive design
|
|
- ✅ Modern interface (Tailwind CSS)
|
|
- ✅ Real-time status
|
|
- ✅ Auto-refresh
|
|
- ✅ Interactive controls
|
|
- ✅ Status indicators
|
|
- ✅ Action buttons
|
|
|
|
## 🔌 Integration Ready
|
|
|
|
The application can be integrated with:
|
|
- Email (SMTP)
|
|
- Slack (webhook)
|
|
- Microsoft Teams (webhook)
|
|
- PagerDuty (webhook)
|
|
- Custom webhooks
|
|
- Monitoring systems (Prometheus)
|
|
|
|
## 📦 Dependencies
|
|
|
|
Core:
|
|
- ocaml (>= 5.0)
|
|
- dune (>= 3.11)
|
|
- dream
|
|
- server-reason-react
|
|
- caqti
|
|
- caqti-dream
|
|
- lwt
|
|
- yojson
|
|
- cohttp-lwt-unix
|
|
- ocaml-ssl
|
|
|
|
## 🎓 Learning Resources
|
|
|
|
- OCaml: https://ocaml.org/
|
|
- ReasonML: https://reasonml.github.io/
|
|
- Dream: https://github.com/aantron/dream
|
|
- Dune: https://dune.build/
|
|
- Docker: https://www.docker.com/
|
|
|
|
## 🤝 Support
|
|
|
|
For issues, questions, or contributions:
|
|
1. Check the documentation in `/docs`
|
|
2. Open an issue on GitHub
|
|
3. Join discussions
|
|
|
|
## 📝 License
|
|
|
|
MIT License - See LICENSE file for details
|
|
|
|
---
|
|
|
|
**Status**: ✅ Complete and ready to use!
|
|
|
|
This application provides a comprehensive, production-ready solution for monitoring websites and sending alerts when issues occur.
|