Crawler Dashboard Overview
The dashboard will provide real-time monitoring and control over the high-throughput multi-domain web crawler. The backend will be built using FastAPI, a modern, fast (high-performance), web framework for building APIs.
Dashboard Requirements
Data to be Shown
- Crawler Task Overview
- Number of active tasks
- Number of pending tasks
- Number of completed tasks
- Number of failed tasks
- Crawler Performance Metrics
- Requests per second (RPS)
- Average response time
- Success rate (%)
- Domain-Specific Statistics
- Number of domains being crawled
- Number of pages crawled per domain
- Average response time per domain
- Task Queue Statistics
- Number of tasks in the queue
- Average wait time in the queue
- Error and Exception Statistics
- Number of errors encountered
- Types of errors encountered (e.g., HTTP errors, connection timeouts)
- Crawler Configuration and Controls
- Ability to start/stop crawler tasks
- Ability to adjust crawler configuration (e.g., RPS, timeouts)
Why this Data?
- Crawler task overview provides a high-level understanding of the crawler's workload and performance.
- Crawler performance metrics help identify bottlenecks and areas for optimization.
- Domain-specific statistics provide insights into the crawler's performance across different domains.
- Task queue statistics help identify potential issues with task scheduling and queuing.
- Error and exception statistics help identify and troubleshoot issues with the crawler.
FastAPI Backend Implementation
main.py
from fastapi import FastAPI, WebSocket
from fastapi.responses import JSONResponse
from pydantic import BaseModel
from typing import List
import asyncio
app = FastAPI()
# Crawler task data model
class CrawlerTask(BaseModel):
id: int
domain: str
status: str
# Crawler performance data model
class CrawlerPerformance(BaseModel):
rps: float
avg_response_time: float
success_rate: float
# Domain-specific statistics data model
class DomainStatistics(BaseModel):
domain: str
num_pages_crawled: int
avg_response_time: float
# Task queue statistics data model
class TaskQueueStatistics(BaseModel):
num_tasks_in_queue: int
avg_wait_time: float
# Error and exception statistics data model
class ErrorStatistics(BaseModel):
num_errors: int
error_types: List[str]
# Crawler configuration data model
class CrawlerConfig(BaseModel):
rps: float
timeouts: float
# In-memory data store for demonstration purposes
crawler_tasks = []
crawler_performance = CrawlerPerformance(rps=0, avg_response_time=0, success_rate=0)
domain_statistics = {}
task_queue_statistics = TaskQueueStatistics(num_tasks_in_queue=0, avg_wait_time=0)
error_statistics = ErrorStatistics(num_errors=0, error_types=[])
# WebSocket endpoint for live updates
@app.websocket("/ws")
async def websocket_endpoint(websocket: WebSocket):
await websocket.accept()
while True:
# Send live updates to the client
await websocket.send_json({
"crawler_tasks": crawler_tasks,
"crawler_performance": crawler_performance.dict(),
"domain_statistics": list(domain_statistics.values()),
"task_queue_statistics": task_queue_statistics.dict(),
"error_statistics": error_statistics.dict()
})
await asyncio.sleep(1)
# API endpoint to start a crawler task
@app.post("/start_task")
async def start_task(domain: str):
# Create a new crawler task
task = CrawlerTask(id=len(crawler_tasks), domain=domain, status="pending")
crawler_tasks.append(task.dict())
return JSONResponse(content={"message": "Task started successfully"}, status_code=200)
# API endpoint to stop a crawler task
@app.post("/stop_task")
async def stop_task(task_id: int):
# Find and update the crawler task
for task in crawler_tasks:
if task["id"] == task_id:
task["status"] = "stopped"
return JSONResponse(content={"message": "Task stopped successfully"}, status_code=200)
return JSONResponse(content={"message": "Task not found"}, status_code=404)
# API endpoint to update crawler configuration
@app.post("/update_config")
async def update_config(config: CrawlerConfig):
# Update the crawler configuration
# ...
return JSONResponse(content={"message": "Config updated successfully"}, status_code=200)
Frontend Implementation
The frontend can be built using a JavaScript framework like React or Angular, and can utilize WebSockets to receive live updates from the FastAPI backend.
// Establish a WebSocket connection to the FastAPI backend
const socket = new WebSocket('ws://localhost:8000/ws');
// Handle incoming messages from the WebSocket connection
socket.onmessage = (event) => {
const data = JSON.parse(event.data);
// Update the dashboard with the received data
updateDashboard(data);
};
// Update the dashboard with the received data
function updateDashboard(data) {
// Update the crawler task overview
document.getElementById('active-tasks').innerText = data.crawler_tasks.filter(task => task.status === 'active').length;
document.getElementById('pending-tasks').innerText = data.crawler_tasks.filter(task => task.status === 'pending').length;
// ...
// Update the crawler performance metrics
document.getElementById('rps').innerText = data.crawler_performance.rps;
document.getElementById('avg-response-time').innerText = data.crawler_performance.avg_response_time;
// ...
// Update the domain-specific statistics
const domainStatsHtml = data.domain_statistics.map(stats => {
return `<div>Domain: ${stats.domain}, Num Pages Crawled: ${stats.num_pages_crawled}, Avg Response Time: ${stats.avg_response_time}</div>`;
}).join('');
document.getElementById('domain-statistics').innerHTML = domainStatsHtml;
// ...
}
This implementation provides a basic structure for building a dashboard for a high-throughput multi-domain web crawler using FastAPI as the backend. The frontend can be customized to display the data in a more user-friendly and visually appealing way.