This is a backend API built with FastAPI that monitors and manages worker processes. The API provides endpoints for registering workers, tracking their health, creating and ending processes, and updating task statuses. Additionally, it offers real-time dashboards to visualize workers, processes, and tasks.
Key Features
API Version
Requirements
Installation
Running the Application
API Endpoints
Authentication
Error Handling
Contributing
License
create a file: docker-compose.yaml
version: "3.9"
services:
monitor_backend:
image: wisrovi/wpipe_api:v1.0
ports:
- "8418:8000"
environment:
- MYSQL_USER=process_monitor
- MYSQL_PASSWORD=process_monitor
- MYSQL_DATABASE=process_monitor
- SERVER=db:3306
- TOKEN=mysecrettoken
command: gunicorn -w 4 -k uvicorn.workers.UvicornWorker --bind 0.0.0.0:8000 api:app
# command: tail -f /dev/null
restart: always
monitor_frontend:
image: wisrovi/wpipe_api_dashboard:v1.0
ports:
- "8050:8050"
environment:
- BACKEND=monitor_backend:8000
depends_on:
- "monitor_backend"
command: python demo_dashboard_base.py
restart: always
db:
image: mariadb
restart: always
labels:
"autoheal": "true"
Author: "https://www.linkedin.com/in/wisrovi-rodriguez/"
environment:
- MYSQL_RANDOM_ROOT_PASSWORD=yes
- MYSQL_USER=process_monitor
- MYSQL_PASSWORD=process_monitor
- MYSQL_DATABASE=process_monitor
volumes:
- backup_db:/var/lib/mysql
healthcheck:
test: ["CMD", "mysqladmin", "ping", "--silent"]
interval: 10s
timeout: 10s
retries: 5
ports:
- 3306:3306
volumes:
backup_db:
so, execute:
docker-compose up -d
git clone [email protected]:wisrovi/wpipe-api.git
cd wpipe-api
docker-compose build
docker-compose up -d
This will start 3 services:
8418,80503306.This will spin up both the FastAPI backend and the Dash frontend.
The Dash app will be available at http://localhost:8050 and the FastAPI backend at http://localhost:8000.
GET /version
{
"version": "v1.1"
}
POST /matricula
Registers a new worker process and returns the worker ID.
{
"name": "worker_name",
"version": "v1.0",
"tasks": [
{"name": "task1", "version": "1.0"},
{"name": "task2", "version": "2.0"}
]
}
{
"id": "123e4567-e89b-12d3-a456-426614174000"
}
POST /healthchecker
Checks the health status of a worker.
{
"id": "123e4567-e89b-12d3-a456-426614174000"
}
{
"health": 1
}
POST /newprocess
Starts a new process for a worker.
{
"id": "worker_id"
}
{
"father": "worker_id",
"sons": [...]
}
POST /endprocess
Ends a process and provides details.
{
"id": "process_id",
"details": "Details about the end of the process"
}
{
"status": true
}
POST /actualizar_task
Updates the status of a task.
{
"task_id": "task_id",
"status": "completed",
"details": "Task completed successfully"
}
{
"status": "ok"
}
GET /dashboard_tasks/{id}
Fetches the dashboard for tasks related to a specific worker.
[
{
"id": "task_id",
"name": "task_name",
"state": "in_progress",
"received": "2024-09-13T12:34:56",
...
}
]
GET /dashboard_workers
Fetches the overall worker dashboard.
All API endpoints (except /version and /dashboard_workers) require a Bearer Token for authentication. Include it in the header:
Authorization: Bearer mysecrettoken
If the token is invalid, the API will respond with:
{
"detail": "Unauthorized"
}
The API raises HTTP exceptions with appropriate status codes:
This project is a process monitoring application that uses a FastAPI backend to manage workers' processes and tasks, and a Dash frontend to visualize the status of workers, processes, and tasks in real-time.
The application has a main dashboard that displays three tables that automatically update every 15 seconds:
The dashboard communicates with a FastAPI backend, which exposes the following relevant endpoints:
/dashboard_workers: Returns the status of all workers./dashboard_process/{id}: Returns the list of processes associated with a worker./dashboard_tasks/{id}: Returns the list of tasks associated with a process.Ensure that the backend is running properly and accessible for the dashboard to work as expected.
This project is licensed under the MIT License. See the LICENSE file for more details.
Content type
Image
Digest
sha256:890e21b54…
Size
143.5 MB
Last updated
about 2 years ago
docker pull wisrovi/wpipe_api:v1.0