Skip to content

Repository files navigation

🐳 Docker Load Predictor

A machine learning application that predicts the future resource usage of Docker and Kubernetes containers using an LSTM (Long Short-Term Memory) neural network.

The system analyzes historical container metrics such as CPU, memory, and network usage and predicts the expected values for the next time step.


✨ Features

  • 🧠 LSTM model for time-series forecasting
  • 📊 CPU, memory, and network usage prediction
  • 🔄 Sliding-window data processing
  • 🚀 FastAPI REST API
  • 📈 Interactive Streamlit dashboard
  • 🌐 Simple HTML/CSS/JavaScript frontend
  • 🐳 Docker and Docker Compose support
  • 🔧 Separate data preprocessing and model training scripts

🏗️ Project Structure

docker-load-predictor/
│
├── src/
│   ├── api/
│   │   └── main.py
│   │
│   ├── dashboard/
│   │   └── app.py
│   │
│   ├── frontend/
│   │   ├── index.html
│   │   ├── predict.html
│   │   ├── script.js
│   │   └── styles.css
│   │
│   ├── model/
│   │   ├── train_lstm.py
│   │   ├── test.py
│   │   ├── lstm_model.keras
│   │   ├── lstm_weights.h5
│   │   ├── scaler_X.pkl
│   │   └── scaler_y.pkl
│   │
│   └── preprocessing/
│       └── prepare_data.py
│
├── data/
│   └── container_metrics.csv
│
├── notebooks/
│   └── preprocessing.ipynb
│
├── Dockerfile
├── Dockerfile.api
├── Dockerfile.dashboard
├── Dockerfile.ui
├── docker-compose.yml
├── start.sh
├── requirements.txt
├── .env.example
├── .gitignore
└── README.md

🚀 Installation

Requirements

  • Python 3.10+
  • Docker
  • Docker Compose
  • Git

Clone the repository

git clone https://github.com/savaseiv-create/docker-load-predictor.git
cd docker-load-predictor

Install Python dependencies

Create a virtual environment:

python -m venv venv

Activate it:

Windows:

venv\Scripts\activate

Linux / macOS:

source venv/bin/activate

Install dependencies:

pip install -r requirements.txt

▶️ Run Locally

Start the API

uvicorn src.api.main:app --host 0.0.0.0 --port 8000

The API will be available at:

http://localhost:8000

Start the dashboard

In another terminal:

streamlit run src/dashboard/app.py --server.port 8501

The dashboard will be available at:

http://localhost:8501

🐳 Run with Docker

The easiest way to start the application is with Docker Compose:

docker-compose up --build

Services:

Service URL
FastAPI http://localhost:8000
Streamlit http://localhost:8501

To stop the application:

docker-compose down

🧠 Machine Learning

The project uses an LSTM neural network to forecast container resource usage.

The model uses a sequence of the previous 30 observations to predict the next time step.

Input

The model receives historical metrics such as:

  • CPU usage
  • Memory usage
  • Network transmission
  • Network reception

Model Architecture

30 time steps
      │
      ▼
LSTM(64)
      │
      ▼
Dropout
      │
      ▼
LSTM(32)
      │
      ▼
Dense(16)
      │
      ▼
Dense(4)
      │
      ▼
CPU
Memory
Network TX
Network RX

🔄 Data Preprocessing

The preprocessing script is:

src/preprocessing/prepare_data.py

Run:

python src/preprocessing/prepare_data.py

The script:

  1. Loads the dataset.
  2. Cleans the data.
  3. Selects the required features.
  4. Normalizes the data.
  5. Creates sequences of 30 observations.
  6. Generates the input and output datasets.
  7. Saves the preprocessing scalers.

🏋️ Model Training

The training script is:

src/model/train_lstm.py

Run:

python src/model/train_lstm.py

The trained model is saved in:

src/model/

📡 API

The project provides a REST API using FastAPI.

GET /

Used to check whether the API is running.

Example response:

{
  "status": "API is running",
  "model_loaded": true
}

POST /predict

Receives the latest 30 observations and returns the predicted resource usage.

Example response:

{
  "cpu": 0.00312,
  "memory": 52428800,
  "network_tx": 1024.5,
  "network_rx": 2048.0
}

📊 Dashboard

The Streamlit dashboard allows users to:

  • Visualize container metrics
  • Explore the processed data
  • Inspect the input sequences
  • Select a service
  • Generate resource usage predictions

🛠️ Technologies

Category Technology
Machine Learning TensorFlow / Keras
Model LSTM
API FastAPI
Server Uvicorn
Dashboard Streamlit
Visualization Plotly
Data Processing pandas / NumPy
Data Scaling scikit-learn
Frontend HTML / CSS / JavaScript
Containerization Docker
Orchestration Docker Compose
Container Metrics cAdvisor / Kubernetes

🔐 Environment Variables

Create a local .env file from .env.example if required.

Example:

API_URL=http://127.0.0.1:8000/predict
STREAMLIT_PORT=8501

Screenshots

image image image image image

LINK OF THE WEBSITE :

https://savaseiv-mon-projet-api.hf.space/

📄 License

See the LICENSE file for the license and usage conditions.


👩‍💻 Author

Sava

A machine learning project focused on container resource monitoring and time-series forecasting.

About

LSTM-based Docker container load predictor — FastAPI + Streamlit

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages