This project provides a way to monitor system memory usage and trigger an alert if memory usage exceeds a predefined threshold. The alert is sent as an HTTP request to a Flask API, which then processes and acknowledges the alert.
-
Memory Monitor Script (
monitor.py): A Python script that continuously checks the system's memory usage using thepsutillibrary. If the memory usage exceeds the set threshold, it sends an alert to the Flask API. -
Flask API (
app.py): A Flask-based REST API that listens for alerts from the monitor script. It provides an endpoint (/receive-alert) to receive and acknowledge memory usage alerts. -
Docker & Docker Compose: The project uses Docker to containerize the Flask API and a MongoDB database. Docker Compose is used to manage and orchestrate these containers.
- Docker and Docker Compose installed.
- Python 3.x with
pipfor running the memory monitor script.
-
Clone the repository:
git clone [repository_url] memory_usage_alert cd memory_usage_alert -
Build and Start the Containers:
sudo docker-compose up --build
-
Run the Memory Monitor Script: In a separate terminal:
cd monitor pip install -r requirements.txt python monitor.py -
Testing: The Flask API provides a
/valueendpoint for CRUD operations with key-value pairs stored in the MongoDB database. You can use tools likecurlor Postman to test these endpoints.
-
Memory Threshold: The memory usage threshold after which an alert is sent is defined in
monitor.pyasMEMORY_THRESHOLD. By default, it's set to 40%. -
API URL: The Flask API endpoint to which the monitor script sends alerts is defined in
monitor.pyasAPI_URL. It's set tohttp://localhost:8080/receive-alertby default.
-
Docker Issues: If you face issues with Docker or Docker Compose, ensure that the Docker daemon is running. Restarting the Docker service or rebooting the system can resolve many common issues.
-
Connection Issues: Ensure that the Flask API is running and accessible if the monitor script cannot send alerts. Check the Docker logs for any errors.
-
Dependencies: Ensure that all Python dependencies are installed, both for the Flask API (in the Docker container) and the memory monitor script.