Code Monkey home page Code Monkey logo

memory_usage_alert's Introduction

Memory Usage Alert System

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.

Components:

  1. Memory Monitor Script (monitor.py): A Python script that continuously checks the system's memory usage using the psutil library. If the memory usage exceeds the set threshold, it sends an alert to the Flask API.

  2. 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.

  3. 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.

Setup and Running:

Prerequisites:

  • Docker and Docker Compose installed.
  • Python 3.x with pip for running the memory monitor script.

Steps:

  1. Clone the repository:

    git clone [repository_url] memory_usage_alert
    cd memory_usage_alert
  2. Build and Start the Containers:

    sudo docker-compose up --build
  3. Run the Memory Monitor Script: In a separate terminal:

    cd monitor
    pip install -r requirements.txt
    python monitor.py
  4. Testing: The Flask API provides a /value endpoint for CRUD operations with key-value pairs stored in the MongoDB database. You can use tools like curl or Postman to test these endpoints.

Configuration:

  • Memory Threshold: The memory usage threshold after which an alert is sent is defined in monitor.py as MEMORY_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.py as API_URL. It's set to http://localhost:8080/receive-alert by default.

Troubleshooting:

  1. 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.

  2. 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.

  3. Dependencies: Ensure that all Python dependencies are installed, both for the Flask API (in the Docker container) and the memory monitor script.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.