Lanbench -
@app.post("/api/v1/start_test") async def start_test(config: TestConfig, background_tasks: BackgroundTasks): """Start a network test""" test_id = generate_test_id() background_tasks.add_task(run_network_test, test_id, config) return {"test_id": test_id, "status": "started"}
def setup_layout(self): self.app.layout = html.Div([ html.H1("LANBench - Live Network Monitor"), html.Div([ dcc.Graph(id='live-latency'), dcc.Graph(id='live-throughput'), dcc.Graph(id='bandwidth-heatmap'), dcc.Interval(id='interval-update', interval=1000) ]) ])
def collect_system_metrics(self) -> Dict: """Collect real-time system metrics""" return { 'cpu_percent': psutil.cpu_percent(interval=1), 'memory_percent': psutil.virtual_memory().percent, 'network_io': psutil.net_io_counters(), 'connections': len(psutil.net_connections()) } LANBench
# Implement throughput measurement pass
def export_to_pdf(self, filename: str): """Generate PDF report""" c = canvas.Canvas(filename) c.drawString(100, 750, "LANBench Performance Report") # Add more report content c.save() # api.py from fastapi import FastAPI, WebSocket, BackgroundTasks from pydantic import BaseModel from typing import Optional import uvicorn app = FastAPI(title="LANBench API") config) return {"test_id": test_id
def create_latency_chart(self): return go.Figure( data=[go.Scatter(y=list(self.latency_data), mode='lines+markers')], layout=go.Layout(title="Network Latency Over Time") ) # distributed.py import redis import json from typing import List, Dict from multiprocessing import Pool import asyncio class DistributedTester: def init (self, redis_host='localhost', redis_port=6379): self.redis_client = redis.Redis(host=redis_host, port=redis_port) self.test_nodes = []
def generate_html_report(self) -> str: """Generate HTML report with charts""" template = Template(""" <html> <head><title>LANBench Test Report</title></head> <body> <h1>Network Performance Report</h1> <h2>Summary</h2> <table> <tr><th>Metric</th><th>Value</th></tr> <tr><td>Avg Throughput</td><td>{{ throughput }} Mbps</td></tr> <tr><td>Avg Latency</td><td>{{ latency }} ms</td></tr> <tr><td>Packet Loss</td><td>{{ packet_loss }}%</td></tr> </table> <img src="chart.png" alt="Performance Chart"> </body> </html> """) return template.render(**self.results) interval=1000) ]) ]) def collect_system_metrics(self) ->
def calculate_statistics(self, data: List[float]) -> Dict: """Calculate statistical metrics""" return { 'mean': np.mean(data), 'std': np.std(data), 'min': np.min(data), 'max': np.max(data), 'p95': np.percentile(data, 95), 'p99': np.percentile(data, 99) } # dashboard.py import dash from dash import dcc, html, Input, Output import plotly.graph_objs as go import plotly.express as px from collections import deque import threading class LiveDashboard: def init (self): self.app = dash.Dash( name ) self.latency_data = deque(maxlen=100) self.throughput_data = deque(maxlen=100) self.setup_layout() self.setup_callbacks()