This project is a Docker Container Monitoring System that allows you to monitor the status of Docker containers by pinging their IP addresses and displaying the results in a web interface. The system consists of four main components:
- Backend Service: A RESTful API written in Go that handles database operations.
- Frontend Service: A React-based web application that displays the status of Docker containers.
- Pinger Service: A Go service that pings Docker containers and sends the results to the Backend API.
- PostgreSQL Database: Stores the status of Docker containers.
- Database migrations: For auto migrate tables
The system is containerized using Docker and orchestrated with Docker Compose. Nginx is used as a reverse proxy to route requests between the frontend and backend.
- Features
- Technologies Used
- Prerequisites
- Setup and Installation
- Running the Project
- Project Structure
- API Endpoints
- Troubleshooting
- Contributing
- License
- Real-time Monitoring: The Pinger service continuously pings Docker containers and updates the database.
- Web Interface: The Frontend service provides a user-friendly interface to view the status of Docker containers.
- RESTful API: The Backend service exposes endpoints to fetch and insert container status data.
- Containerized: All services are containerized using Docker for easy deployment and scalability.
- Backend: Go (Golang)
- Frontend: React (JavaScript)
- Database: PostgreSQL
- Pinger Service: Go (Golang)
- Containerization: Docker, Docker Compose
- Reverse Proxy: Nginx
- Migrations: SQL migrations
Before running the project, ensure you have the following installed:
- Docker: Install Docker
- Docker Compose: Install Docker Compose
- Node.js (for local frontend development): Install Node.js
- Go (for local backend development): Install Go
-
Clone the Repository:
git clone https://github.com/dostonshernazarov/docker_monitoring.git cd docker_monitoring -
Set Up Environment Variables:
- Create a
.envfile in the backend directory with the following content:POSTGRES_USER=postgres POSTGRES_PASSWORD=yourpassword POSTGRES_DB=docker_monitor
- Create a
-
Build and Run the Project:
docker-compose up --build
This will:
- Build Docker images for all services.
- Start the PostgreSQL database with migrations, Backend, Frontend, Pinger, and Nginx services.
-
Access the Application:
- Open your browser and navigate to
http://localhost:80. - You should see the frontend interface displaying the status of Docker containers.
- Open your browser and navigate to
To start all services, run:
docker-compose up --buildTo stop all services, run:
docker-compose down-
Backend:
- Navigate to the
backenddirectory:cd backend - Run the backend service:
go run main.go
- Navigate to the
-
Frontend:
- Navigate to the
frontenddirectory:cd frontend - Install dependencies and start the frontend:
npm install npm start
- Navigate to the
-
Pinger:
- Navigate to the
pingerdirectory:cd pinger - Run the pinger service:
go run main.go
- Navigate to the
docker-monitor/
├── backend/ # Backend service (Go)
│ ├── main.go # Backend entry point
│ ├── Dockerfile # Dockerfile for backend
| ├── .env # Environment variables
│ └── go.mod # Go dependencies
├── frontend/ # Frontend service (React)
│ ├── src/ # React source code
│ ├── Dockerfile # Dockerfile for frontend
│ └── package.json # Node.js dependencies
├── migrations/
| ├── 00...table.down.sql
| ├── 00...table.up.sql
├── pinger/ # Pinger service (Go)
│ ├── main.go # Pinger entry point
│ ├── Dockerfile # Dockerfile for pinger
│ └── go.mod # Go dependencies
├── nginx.conf # Nginx configuration
├── docker-compose.yml # Docker Compose configuration
└── README.md # Project documentation
-
GET
/status:- Fetches the status of all Docker containers.
- Example Response:
[ { "ip_address": "192.168.1.1", "ping_time": 100, "last_success": "2023-10-01T12:00:00Z" } ]
-
POST
/status:- Inserts a new container status into the database.
- Example Request Body:
{ "ip_address": "192.168.1.1", "ping_time": 100, "last_success": "2023-10-01T12:00:00Z" }
-
CORS Issues:
- Ensure the Backend service has CORS enabled (see
backend/main.go). - Use the proxy configuration in the Frontend (
frontend/package.json).
- Ensure the Backend service has CORS enabled (see
-
Database Connection Issues:
- Verify that the PostgreSQL service is running.
- Check the
.envfile for correct database credentials.
-
Pinger Service Not Sending Data:
- Check the logs of the Pinger service for errors.
- Ensure the Backend API is running and accessible.
Contributions are welcome! Please follow these steps:
- Fork the repository.
- Create a new branch for your feature or bugfix.
- Submit a pull request with a detailed description of your changes.
This project is licensed under the MIT License. See the LICENSE file for details.