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.
- 🧠 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
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
- Python 3.10+
- Docker
- Docker Compose
- Git
git clone https://github.com/savaseiv-create/docker-load-predictor.git
cd docker-load-predictorCreate a virtual environment:
python -m venv venvActivate it:
Windows:
venv\Scripts\activateLinux / macOS:
source venv/bin/activateInstall dependencies:
pip install -r requirements.txtuvicorn src.api.main:app --host 0.0.0.0 --port 8000The API will be available at:
http://localhost:8000
In another terminal:
streamlit run src/dashboard/app.py --server.port 8501The dashboard will be available at:
http://localhost:8501
The easiest way to start the application is with Docker Compose:
docker-compose up --buildServices:
| Service | URL |
|---|---|
| FastAPI | http://localhost:8000 |
| Streamlit | http://localhost:8501 |
To stop the application:
docker-compose downThe 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.
The model receives historical metrics such as:
- CPU usage
- Memory usage
- Network transmission
- Network reception
30 time steps
│
▼
LSTM(64)
│
▼
Dropout
│
▼
LSTM(32)
│
▼
Dense(16)
│
▼
Dense(4)
│
▼
CPU
Memory
Network TX
Network RX
The preprocessing script is:
src/preprocessing/prepare_data.py
Run:
python src/preprocessing/prepare_data.pyThe script:
- Loads the dataset.
- Cleans the data.
- Selects the required features.
- Normalizes the data.
- Creates sequences of 30 observations.
- Generates the input and output datasets.
- Saves the preprocessing scalers.
The training script is:
src/model/train_lstm.py
Run:
python src/model/train_lstm.pyThe trained model is saved in:
src/model/
The project provides a REST API using FastAPI.
Used to check whether the API is running.
Example response:
{
"status": "API is running",
"model_loaded": true
}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
}The Streamlit dashboard allows users to:
- Visualize container metrics
- Explore the processed data
- Inspect the input sequences
- Select a service
- Generate resource usage predictions
| 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 |
Create a local .env file from .env.example if required.
Example:
API_URL=http://127.0.0.1:8000/predict
STREAMLIT_PORT=8501
https://savaseiv-mon-projet-api.hf.space/
See the LICENSE file for the license and usage conditions.
Sava
A machine learning project focused on container resource monitoring and time-series forecasting.