Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:Sgl project Sglang Dashboard Server

From Leeroopedia


Knowledge Sources
Domains Performance Monitoring, Web Server
Last Updated 2026-02-10 00:00 GMT

Overview

Development HTTP server for the SGLang performance dashboard with live metrics API and thread-safe caching.

Description

server.py extends Python's http.server.SimpleHTTPRequestHandler to serve static dashboard files and provide two API endpoints: /api/metrics and /api/refresh. It implements thread-safe caching with a 5-minute TTL (CACHE_TTL = 300) and background asynchronous updates via threading. The DashboardHandler class fetches metrics from the GitHub Actions API, filtering for scheduled nightly runs only, downloads and extracts zip artifacts, and serves aggregated JSON data. The server includes directory traversal protection by checking for ".." and "//" in request paths.

The fetch_metrics_from_github() function handles the complete data pipeline: authenticating with GitHub, querying workflow runs, downloading artifact zips, and extracting JSON metrics. The update_cache_async() function performs cache updates in a background thread with a cache_lock to ensure thread safety during concurrent requests.

Usage

Use this server during development to view the SGLang performance dashboard with live metrics data. It bridges the dashboard frontend with GitHub Actions benchmark data and supports automatic cache refresh.

Code Reference

Source Location

Signature

def get_github_token(): ...
def fetch_metrics_from_github(days=30): ...
def update_cache_async(): ...

class DashboardHandler(http.server.SimpleHTTPRequestHandler):
    def __init__(self, *args, directory=None, **kwargs): ...
    def do_GET(self): ...
    def handle_metrics_api(self, parsed): ...
    def handle_refresh_api(self): ...
    def log_message(self, format, *args): ...

def main(): ...

Import

import argparse
import http.server
import io
import json
import os
import socketserver
import threading
import time
import zipfile
from datetime import datetime, timedelta, timezone
from pathlib import Path
from urllib.parse import urlparse

import requests

I/O Contract

Inputs

Name Type Required Description
--port int No (default: 8000) Port to serve on
--host str No (default: "127.0.0.1") Host to bind to (use 0.0.0.0 for external access)
--fetch-on-start flag No Fetch metrics on startup before serving
GITHUB_TOKEN env var No GitHub personal access token for API authentication

Outputs

Name Type Description
/api/metrics JSON response Array of metric records with run_id, run_date, commit_sha, branch, and results
/api/refresh JSON response Status message indicating cache refresh initiated
Static files HTML/JS/CSS Dashboard frontend files served from the dashboard directory

Usage Examples

# Start server on default port 8000
python server.py

# Start on custom port
python server.py --port 8080

# Allow external access
python server.py --host 0.0.0.0

# Fetch metrics immediately on startup
python server.py --fetch-on-start

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment