Build a bot-perceived performance dashboard: server-timing, TTFB, and render duration.
- User
Build a bot-perceived performance dashboard: server-timing, TTFB, and render duration.
Assistant
The user wants a "bot-perceived performance dashboard" that displays server-timing metrics, TTFB (Time to First Byte), and render duration. This is a developer/ops-focused performance monitoring tool.
Let me think about the design:
- Purpose: Performance metrics dashboard - needs to be technical, precise, data-focused
- Aesthetic: Should feel like a monitoring tool - maybe dark theme with accent colors for metrics, technical/monospace feel for numbers
- Data: I'll generate mock performance data for various endpoints/checks
- Interactions:
- Live refresh simulation
- Filter/sort metrics
- Hover states showing details
- Maybe a timeline view
- Collapse/expand sections
Let me design:
Color Scheme (Dark Technical Theme):
- Background: Very dark blue-gray (#0a0f1a)
- Cards: Slightly lighter (#111827)
- Accent: Cyan/teal for good (#00d4aa), Orange for warning (#f59e0b), Red for critical (#ef4444)
- Muted text: Gray (#6b7280)
- Primary text: Light gray/white (#e5e7eb)
Typography:
- Display: JetBrains Mono or Space Mono for that technical feel
- UI: Space Grotesk for labels
Layout:
- Header with system status
- Main metrics cards (TTFB, Server Timing, Render Duration) with sparkline trends
- Detailed table/list of endpoint metrics
- Timeline visualization
Interactions:
- Animated metrics update (simulated live data)
- Hover tooltips with detailed breakdown
- Click to expand endpoint details
- Sort/filter functionality
- Status indicator pulses
Let me build this:
Bot-Perceived Performance Dashboard
A dark, technical dashboard for monitoring server timing, TTFB, and render duration metrics with live updates and detailed breakdowns.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Bot Performance Dashboard</title> <script src="https://cdn.tailwindcss.com"></script> <link href="https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500;600;700&display=swap" rel="stylesheet"> <script> tailwind.config = { theme: { extend: { fontFamily: { display: ['JetBrains Mono', 'monospace'], ui: ['Space Grotesk', 'sans-serif'], }, }, }, } </script> <style> :root { --bg: #050810; --bg-elevated: #0c1220; --card: #111827; --card-hover: #1a2332; --border: #1f2937; --fg: #f3f4f6; --muted: #6b7280; --accent: #00d4aa; --accent-dim: rgba(0, 212, 170, 0.15); --warning: #f59e0b; --warning-dim: rgba(245, 158, 11, 0.15); --critical: #ef4444; --critical-dim: rgba(239, 68, 68, 0.15); --info: #3b82f6; --info-dim: rgba(59, 130, 246, 0.15); } * { box-sizing: border-box; } body { font-family: 'Space Grotesk', sans-serif; background: var(--bg); color: var(--fg); min-height: 100vh; } .font-mono { font-family: 'JetBrains Mono', monospace; } .bg-grid { background-image: linear-gradient(rgba(0, 212, 170, 0.03) 1px, transparent 1px), linear-gradient(90deg, rgba(0, 212, 170, 0.03) 1px, transparent 1px); background-size: 40px 40px; } .card { background: var(--card); border: 1px solid var(--border); border-radius: 12px; transition: all 0.2s ease; } .card:hover { background: var(--card-hover); border-color: rgba(0, 212, 170, 0.3); } .status-pulse { animation: pulse 2s infinite; } @keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } } .metric-value { font-variant-numeric: tabular-nums; } .sparkline-path { stroke-dasharray: 200; stroke-dashoffset: 200; animation: drawLine 1.5s ease forwards; } @keyframes drawLine { to { stroke-dashoffset: 0; } } .fade-in { animation: fadeIn 0.4s ease forwards; } @keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } } .stagger-1 { animation-delay: 0.05s; } .stagger-2 { animation-delay: 0.1s; } .stagger-3 { animation-delay: 0.15s; } .stagger-4 { animation-delay: 0.2s; } .progress-bar { transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1); } .endpoint-row { transition: all 0.15s ease; } .endpoint-row:hover { background: rgba(0, 212, 170, 0.05); } .status-badge { font-size: 10px; letter-spacing: 0.05em; text-transform: uppercase; } .tooltip { position: absolute; background: #1a2332; border: 1px solid var(--border); border-radius: 8px; padding: 12px; font-size: 12px; z-index: 100; pointer-events: none; opacity: 0; transform: translateY(5px); transition: all 0.2s ease; } .tooltip.visible { opacity: 1; transform: translateY(0); } .scrollbar-thin::-webkit-scrollbar { width: 6px; height: 6px; } .scrollbar-thin::-webkit-scrollbar-track { background: var(--bg); } .scrollbar-thin::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; } @media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; } } .filter-btn { transition: all 0.15s ease; } .filter-btn.active { background: var(--accent-dim); color: var(--accent); border-color: var(--accent); } .live-indicator { display: inline-flex; align-items: center; gap: 6px; } .live-dot { width: 8px; height: 8px; background: var(--accent); border-radius: 50%; animation: livePulse 1.5s infinite; } @keyframes livePulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(0, 212, 170, 0.4); } 50% { box-shadow: 0 0 0 8px rgba(0, 212, 170, 0); } } .waterfall-bar { height: 24px; border-radius: 4px; position: relative; overflow: hidden; } .waterfall-segment { height: 100%; float: left; transition: width 0.3s ease; } .detail-panel { max-height: 0; overflow: hidden; transition: max-height 0.3s ease; } .detail-panel.expanded { max-height: 500px; } </style> </head> <body class="bg-grid"> <!-- Header --> <header class="sticky top-0 z-50 border-b border-[var(--border)] bg-[var(--bg-elevated)] backdrop-blur-xl bg-opacity-90"> <div class="max-w-7xl mx-auto px-4 sm:px-6 py-4"> <div class="flex items-center justify-between"> <div class="flex items-center gap-4"> <div class="flex items-center gap-3"> <svg class="w-8 h-8 text-[var(--accent)]" viewBox="0 0 32 32" fill="none" stroke="currentColor" stroke-width="2"> <circle cx="16" cy="16" r="14" /> <path d="M16 6v10l7 4" stroke-linecap="round" /> <circle cx="16" cy="16" r="3" fill="currentColor" /> </svg> <div> <h1 class="font-mono font-bold text-lg tracking-tight">PERF::DASHBOARD</h1> <p class="text-xs text-[var(--muted)]">Bot-Perceived Metrics</p> </div> </div> </div> <div class="flex items-center gap-4"> <div class="live-indicator text-sm text-[var(--muted)]"> <span class="live-dot"></span> <span>Live</span> </div> <div class="h-6 w-px bg-[var(--border)]"></div> <span class="text-sm text-[var(--muted)] font-mono" id="lastUpdate">--:--:--</span> <button id="refreshBtn" class="flex items-center gap-2 px-3 py-1.5 rounded-lg border border-[var(--border)] text-sm hover:border-[var(--accent)] hover:text-[var(--accent)] transition-colors focus:outline-none focus:ring-2 focus:ring-[var(--accent)] focus:ring-offset-2 focus:ring-offset-[var(--bg)]" aria-label="Refresh data" > <svg class="w-4 h-4" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"> <path d="M21 12a9 9 0 11-9-9c2.52 0 4.93 1 6.74 2.74L21 8" /> <path d="M21 3v5h-5" /> </svg> Refresh </button> </div> </div> </div> </header> <main class="max-w-7xl mx-auto px-4 sm:px-6 py-8"> <!-- System Status Banner --> <div id="systemBanner" class="mb-8 p-4 rounded-xl border fade-in" style="background: var(--accent-dim); border-color: rgba(0, 212, 170, 0.3);"> <div class="flex items-center gap-3"> <svg class="w-5 h-5 text-[var(--accent)]" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"> <path d="M22 11.08V12a10 10 0 11-5.93-9.14" stroke-linecap="round"/> <polyline points="22 4 12 14.01 9 11.01" stroke-linecap="round" stroke-linejoin="round"/> </svg> <span class="text-sm">All systems operational · P95 latency within threshold</span> </div> </div> <!-- Primary Metrics --> <div class="grid grid-cols-1 md:grid-cols-3 gap-6 mb-8"> <!-- TTFB --> <div class="card p-6 fade-in stagger-1" data-metric="ttfb"> <div class="flex items-start justify-between mb-4"> <div> <p class="text-xs text-[var(--muted)] uppercase tracking-wider mb-1">Time to First Byte</p> <p class="font-mono text-4xl font-bold metric-value" id="ttfb-value">--</p> </div> <div class="p-2 rounded-lg" style="background: var(--accent-dim);"> <svg class="w-6 h-6 text-[var(--accent)]" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"> <path d="M5 12h14M12 5l7 7-7 7" stroke-linecap="round" stroke-linejoin="round"/> </svg> </div> </div> <div class="flex items-center gap-3 mb-4"> <span class="status-badge px-2 py-1 rounded" id="ttfb-status" style="background: var(--accent-dim); color: var(--accent);">Optimal</span> <span class="text-xs text-[var(--muted)]">Target: <200ms</span> </div> <svg class="w-full h-12" id="ttfb-sparkline" viewBox="0 0 200 48"></svg> <div class="mt-4 grid grid-cols-3 gap-2 text-center text-xs"> <div> <p class="text-[var(--muted)]">P50</p> <p class="font-mono font-semibold" id="ttfb-p50">--</p> </div> <div> <p class="text-[var(--muted)]">P95</p> <p class="font-mono font-semibold" id="ttfb-p95">--</p> </div> <div> <p class="text-[var(--muted)]">P99</p> <p class="font-mono font-semibold" id="ttfb-p99">--</p> </div> </div> </div> <!-- Server Timing --> <div class="card p-6 fade-in stagger-2" data-metric="server"> <div class="flex items-start justify-between mb-4"> <div> <p class="text-xs text-[var(--muted)] uppercase tracking-wider mb-1">Server Timing</p> <p class="font-mono text-4xl font-bold metric-value" id="server-value">--</p> </div> <div class="p-2 rounded-lg" style="background: var(--info-dim);"> <svg class="w-6 h-6 text-[var(--info)]" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"> <rect x="2" y="2" width="20" height="8" rx="2" /> <rect x="2" y="14" width="20" height="8" rx="2" /> <circle cx="6" cy="6" r="1" fill="currentColor"/> <circle cx="6" cy="18" r="1" fill="currentColor"/> </svg> </div> </div> <div class="flex items-center gap-3 mb-4"> <span class="status-badge px-2 py-1 rounded" id="server-status" style="background: var(--accent-dim); color: var(--accent);">Healthy</span> <span class="text-xs text-[var(--muted)]">Target: <300ms</span> </div> <svg class="w-full h-12" id="server-sparkline" viewBox="0 0 200 48"></svg> <div class="mt-4 grid grid-cols-3 gap-2 text-center text-xs"> <div> <p class="text-[var(--muted)]">P50</p> <p class="font-mono font-semibold" id="server-p50">--</p> </div> <div> <p class="text-[var(--muted)]">P95</p> <p class="font-mono font-semibold" id="server-p95">--</p> </div> <div> <p class="text-[var(--muted)]">P99</p> <p class="font-mono font-semibold" id="server-p99">--</p> </div> </div> </div> <!-- Render Duration --> <div class="card p-6 fade-in stagger-3" data-metric="render"> <div class="flex items-start justify-between mb-4"> <div> <p class="text-xs text-[var(--muted)] uppercase tracking-wider mb-1">Render Duration</p> <p class="font-mono text-4xl font-bold metric-value" id="render-value">--</p> </div> <div class="p-2 rounded-lg" style="background: var(--warning-dim);"> <svg class="w-6 h-6 text-[var(--warning)]" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"> <path d="M12 2v4M12 18v4M4.93 4.93l2.83 2.83M16.24 16.24l2.83 2.83M2 12h4M18 12h4M4.93 19.07l2.83-2.83M16.24 7.76l2.83-2.83" stroke-linecap="round"/> </svg> </div> </div> <div class="flex items-center gap-3 mb-4"> <span class="status-badge px-2 py-1 rounded" id="render-status" style="background: var(--warning-dim); color: var(--warning);">Elevated</span> <span class="text-xs text-[var(--muted)]">Target: <100ms</span> </div> <svg class="w-full h-12" id="render-sparkline" viewBox="0 0 200 48"></svg> <div class="mt-4 grid grid-cols-3 gap-2 text-center text-xs"> <div> <p class="text-[var(--muted)]">P50</p> <p class="font-mono font-semibold" id="render-p50">--</p> </div> <div> <p class="text-[var(--muted)]">P95</p> <p class="font-mono font-semibold" id="render-p95">--</p> </div> <div> <p class="text-[var(--muted)]">P99</p> <p class="font-mono font-semibold" id="render-p99">--</p> </div> </div> </div> </div> <!-- Server-Timing Breakdown --> <div class="card p-6 mb-8 fade-in stagger-4"> <div class="flex items-center justify-between mb-6"> <div> <h2 class="font-mono font-bold text-lg">Server-Timing Breakdown</h2> <p class="text-sm text-[var(--muted)]">Internal processing phases</p> </div> <div class="flex items-center gap-2"> <span class="text-xs text-[var(--muted)]">Total:</span> <span class="font-mono font-bold" id="timing-total">--</span> </div> </div> <div class="space-y-4" id="timingBreakdown"> <!-- Populated by JS --> </div> </div> <!-- Endpoint Metrics Table --> <div class="card overflow-hidden fade-in" style="animation-delay: 0.25s;"> <div class="p-6 border-b border-[var(--border)]"> <div class="flex flex-col sm:flex-row sm:items-center justify-between gap-4"> <div> <h2 class="font-mono font-bold text-lg">Endpoint Metrics</h2> <p class="text-sm text-[var(--muted)]">Per-route performance analysis</p> </div> <div class="flex items-center gap-2"> <button class="filter-btn active px-3 py-1.5 rounded-lg border border-[var(--border)] text-xs font-medium" data-filter="all">All</button> <button class="filter-btn px-3 py-1.5 rounded-lg border border-[var(--border)] text-xs font-medium" data-filter="api">API</button> <button class="filter-btn px-3 py-1.5 rounded-lg border border-[var(--border)] text-xs font-medium" data-filter="page">Pages</button> <button class="filter-btn px-3 py-1.5 rounded-lg border border-[var(--border)] text-xs font-medium" data-filter="static">Static</button> </div> </div> </div> <div class="overflow-x-auto scrollbar-thin"> <table class="w-full text-sm"> <thead class="bg-[var(--bg-elevated)]"> <tr class="text-left text-xs text-[var(--muted)] uppercase tracking-wider"> <th class="px-6 py-4 font-medium">Endpoint</th> <th class="px-6 py-4 font-medium">Method</th> <th class="px-6 py-4 font-medium text-right">TTFB</th> <th class="px-6 py-4 font-medium text-right">Server</th> <th class="px-6 py-4 font-medium text-right">Render</th> <th class="px-6 py-4 font-medium text-right">Total</th> <th class="px-6 py-4 font-medium text-center">Status</th> <th class="px-6 py-4 font-medium"></th> </tr> </thead> <tbody id="endpointTable" class="divide-y divide-[var(--border)]"> <!-- Populated by JS --> </tbody> </table> </div> </div> <!-- Waterfall View --> <div class="card mt-8 overflow-hidden fade-in" style="animation-delay: 0.3s;"> <div class="p-6 border-b border-[var(--border)]"> <div class="flex items-center justify-between"> <div> <h2 class="font-mono font-bold text-lg">Request Waterfall</h2> <p class="text-sm text-[var(--muted)]">Visual timing breakdown</p> </div> <div class="flex items-center gap-4 text-xs"> <div class="flex items-center gap-2"> <div class="w-3 h-3 rounded" style="background: var(--info);"></div> <span class="text-[var(--muted)]">DNS/Connect</span> </div> <div class="flex items-center gap-2"> <div class="w-3 h-3 rounded" style="background: var(--accent);"></div> <span class="text-[var(--muted)]">TTFB</span> </div> <div class="flex items-center gap-2"> <div class="w-3 h-3 rounded" style="background: var(--warning);"></div> <span class="text-[var(--muted)]">Processing</span> </div> <div class="flex items-center gap-2"> <div class="w-3 h-3 rounded" style="background: #8b5cf6;"></div> <span class="text-[var(--muted)]">Render</span> </div> </div> </div> </div> <div class="p-6"> <div class="space-y-3" id="waterfallView"> <!-- Populated by JS --> </div> </div> </div> </main> <!-- Tooltip --> <div id="tooltip" class="tooltip"></div> <script> // Initialize all data first before any function calls const historicalData = { ttfb: [145, 152, 138, 165, 148, 142, 158, 163, 147, 151, 149, 156], server: [245, 258, 232, 278, 248, 239, 265, 272, 251, 261, 255, 268], render: [89, 95, 78, 112, 92, 85, 103, 108, 88, 98, 94, 105] }; const timingMetrics = [ { name: 'db_query', label: 'Database Query', value: 45, color: '#3b82f6' }, { name: 'cache_check', label: 'Cache Lookup', value: 12, color: '#8b5cf6' }, { name: 'auth_verify', label: 'Auth Verification', value: 28, color: '#06b6d4' }, { name: 'data_transform', label: 'Data Transform', value: 35, color: '#10b981' }, { name: 'template_render', label: 'Template Render', value: 58, color: '#f59e0b' }, { name: 'serialization', label: 'Serialization', value: 22, color: '#ec4899' } ]; const endpoints = [ { path: '/api/users', method: 'GET', type: 'api', ttfb: 124, server: 187, render: 0, status: 'optimal', requests: 4521 }, { path: '/api/products', method: 'GET', type: 'api', ttfb: 156, server: 234, render: 0, status: 'optimal', requests: 3892 }, { path: '/api/orders', method: 'POST', type: 'api', ttfb: 198, server: 312, render: 0, status: 'warning', requests: 1247 }, { path: '/dashboard', method: 'GET', type: 'page', ttfb: 178, server: 265, render: 89, status: 'optimal', requests: 2341 }, { path: '/products/list', method: 'GET', type: 'page', ttfb: 234, server: 298, render: 112, status: 'warning', requests: 1876 }, { path: '/checkout', method: 'GET', type: 'page', ttfb: 312, server: 387, render: 156, status: 'critical', requests: 892 }, { path: '/static/main.js', method: 'GET', type: 'static', ttfb: 45, server: 52, render: 0, status: 'optimal', requests: 12453 }, { path: '/static/styles.css', method: 'GET', type: 'static', ttfb: 38, server: 41, render: 0, status: 'optimal', requests: 11234 } ]; const waterfallRequests = [ { name: '/api/auth/verify', start: 0, dns: 15, ttfb: 45, processing: 12, render: 0 }, { name: '/api/users/profile', start: 60, dns: 8, ttfb: 78, processing: 34, render: 0 }, { name: '/api/products/featured', start: 85, dns: 5, ttfb: 92, processing: 28, render: 0 }, { name: '/dashboard', start: 180, dns: 12, ttfb: 156, processing: 45, render: 67 }, { name: '/static/main.js', start: 450, dns: 3, ttfb: 28, processing: 0, render: 0 } ]; // DOM Elements - initialize after data const elements = { ttfbValue: document.getElementById('ttfb-value'), ttfbStatus: document.getElementById('ttfb-status'), ttfbP50: document.getElementById('ttfb-p50'), ttfbP95: document.getElementById('ttfb-p95'), ttfbP99: document.getElementById('ttfb-p99'), serverValue: document.getElementById('server-value'), serverStatus: document.getElementById('server-status'), serverP50: document.getElementById('server-p50'), serverP95: document.getElementById('server-p95'), serverP99: document.getElementById('server-p99'), renderValue: document.getElementById('render-value'), renderStatus: document.getElementById('render-status'), renderP50: document.getElementById('render-p50'), renderP95: document.getElementById('render-p95'), renderP99: document.getElementById('render-p99'), timingBreakdown: document.getElementById('timingBreakdown'), timingTotal: document.getElementById('timing-total'), endpointTable: document.getElementById('endpointTable'), waterfallView: document.getElementById('waterfallView'), lastUpdate: document.getElementById('lastUpdate'), refreshBtn: document.getElementById('refreshBtn'), tooltip: document.getElementById('tooltip') }; // Utility functions function clamp(value, min, max) { return Math.max(min, Math.min(max, value)); } function formatMs(value) { return `${Math.round(value)}ms`; } function getStatusInfo(value, targets) { if (value <= targets.optimal) { return { label: 'Optimal', class: 'accent', bg: 'var(--accent-dim)', color: 'var(--accent)' }; } else if (value <= targets.warning) { return { label: 'Warning', class: 'warning', bg: 'var(--warning-dim)', color: 'var(--warning)' }; } return { label: 'Critical', class: 'critical', bg: 'var(--critical-dim)', color: 'var(--critical)' }; } function calculatePercentile(arr, percentile) { const sorted = [...arr].sort((a, b) => a - b); const index = Math.ceil((percentile / 100) * sorted.length) - 1; return sorted[clamp(index, 0, sorted.length - 1)]; } function generateSparklinePath(data, width, height) { const maxVal = Math.max(...data); const minVal = Math.min(...data); const range = maxVal - minVal || 1; const padding = 8; const usableHeight = height - padding * 2; const usableWidth = width - 10; const points = data.map((val, i) => { const x = 5 + (i / (data.length - 1)) * usableWidth; const y = padding + (1 - (val - minVal) / range) * usableHeight; return `${clamp(x, 0, width)},${clamp(y, 0, height)}`; }); return `M${points.join(' L')}`; } function renderSparkline(elementId, data, color) { const svg = document.getElementById(elementId); if (!svg) return; const path = generateSparklinePath(data, 200, 48); const minVal = Math.min(...data); const maxVal = Math.max(...data); svg.innerHTML = ` <defs> <linearGradient id="grad-${elementId}" x1="0%" y1="0%" x2="0%" y2="100%"> <stop offset="0%" style="stop-color:${color};stop-opacity:0.3" /> <stop offset="100%" style="stop-color:${color};stop-opacity:0" /> </linearGradient> </defs> <path d="${path} L195,48 L5,48 Z" fill="url(#grad-${elementId})" /> <path class="sparkline-path" d="${path}" fill="none" stroke="${color}" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" /> <circle cx="195" cy="${clamp(8 + (1 - (data[data.length - 1] - minVal) / (maxVal - minVal || 1)) * 32, 0, 48)}" r="4" fill="${color}" /> `; } function updateMetricCard(type, value, data, targets) { const status = getStatusInfo(value, targets); elements[`${type}Value`].textContent = formatMs(value); elements[`${type}Status`].textContent = status.label; elements[`${type}Status`].style.background = status.bg; elements[`${type}Status`].style.color = status.color; elements[`${type}P50`].textContent = formatMs(calculatePercentile(data, 50)); elements[`${type}P95`].textContent = formatMs(calculatePercentile(data, 95)); elements[`${type}P99`].textContent = formatMs(calculatePercentile(data, 99)); const colors = { ttfb: '#00d4aa', server: '#3b82f6', render: '#f59e0b' }; renderSparkline(`${type}-sparkline`, data, colors[type]); } function renderTimingBreakdown() { const total = timingMetrics.reduce((sum, m) => sum + m.value, 0); elements.timingTotal.textContent = formatMs(total); elements.timingBreakdown.innerHTML = timingMetrics.map(metric => { const percentage = clamp((metric.value / total) * 100, 0, 100); return ` <div class="group cursor-pointer" data-timing="${metric.name}"> <div class="flex items-center justify-between mb-2"> <div class="flex items-center gap-3"> <div class="w-3 h-3 rounded" style="background: ${metric.color};"></div> <span class="text-sm font-medium">${metric.label}</span> </div> <span class="font-mono text-sm">${formatMs(metric.value)}</span> </div> <div class="h-2 rounded-full overflow-hidden" style="background: var(--bg-elevated);"> <div class="progress-bar h-full rounded-full" style="width: ${percentage}%; background: ${metric.color};"></div> </div> </div> `; }).join(''); } function renderEndpointTable(filter = 'all') { const filtered = filter === 'all' ? endpoints : endpoints.filter(e => e.type === filter); elements.endpointTable.innerHTML = filtered.map((endpoint, index) => { const total = endpoint.ttfb + endpoint.server + endpoint.render; const statusInfo = getStatusInfo(total, { optimal: 300, warning: 500 }); const methodColors = { GET: '#10b981', POST: '#3b82f6', PUT: '#f59e0b', DELETE: '#ef4444' }; return ` <tr class="endpoint-row cursor-pointer" data-endpoint="${endpoint.path}"> <td class="px-6 py-4"> <div class="flex items-center gap-2"> <span class="font-mono text-sm">${endpoint.path}</span> </div> </td> <td class="px-6 py-4"> <span class="px-2 py-1 rounded text-xs font-mono font-medium" style="background: ${methodColors[endpoint.method]}22; color: ${methodColors[endpoint.method]};"> ${endpoint.method} </span> </td> <td class="px-6 py-4 text-right font-mono">${formatMs(endpoint.ttfb)}</td> <td class="px-6 py-4 text-right font-mono">${formatMs(endpoint.server)}</td> <td class="px-6 py-4 text-right font-mono">${endpoint.render > 0 ? formatMs(endpoint.render) : '-'}</td> <td class="px-6 py-4 text-right font-mono font-semibold">${formatMs(total)}</td> <td class="px-6 py-4 text-center"> <span class="status-badge px-2 py-1 rounded" style="background: ${statusInfo.bg}; color: ${statusInfo.color};"> ${statusInfo.label} </span> </td> <td class="px-6 py-4 text-right"> <span class="text-xs text-[var(--muted)]">${endpoint.requests.toLocaleString()} req</span> </td> </tr> `; }).join(''); } function renderWaterfall() { const maxTime = Math.max(...waterfallRequests.map(r => r.start + r.dns + r.ttfb + r.processing + r.render)); elements.waterfallView.innerHTML = waterfallRequests.map(req => { const scale = 100 / maxTime; const dnsStart = req.start * scale; const dnsWidth = Math.max(1, req.dns * scale); const ttfbWidth = Math.max(1, req.ttfb * scale); const procWidth = Math.max(1, req.processing * scale); const renderWidth = Math.max(1, req.render * scale); const totalWidth = dnsStart + dnsWidth + ttfbWidth + procWidth + renderWidth; return ` <div class="flex items-center gap-4"> <div class="w-40 flex-shrink-0"> <p class="font-mono text-xs truncate" title="${req.name}">${req.name}</p> </div> <div class="flex-1 relative"> <div class="waterfall-bar" style="margin-left: ${clamp(dnsStart, 0, 100)}%; width: ${clamp(totalWidth - dnsStart, 1, 100)}%;"> ${req.dns > 0 ? `<div class="waterfall-segment" style="width: ${clamp(dnsWidth / (totalWidth - dnsStart) * 100, 0, 100)}%; background: var(--info);"></div>` : ''} <div class="waterfall-segment" style="width: ${clamp(ttfbWidth / (totalWidth - dnsStart) * 100, 0, 100)}%; background: var(--accent);"></div> ${req.processing > 0 ? `<div class="waterfall-segment" style="width: ${clamp(procWidth / (totalWidth - dnsStart) * 100, 0, 100)}%; background: var(--warning);"></div>` : ''} ${req.render > 0 ? `<div class="waterfall-segment" style="width: ${clamp(renderWidth / (totalWidth - dnsStart) * 100, 0, 100)}%; background: #8b5cf6;"></div>` : ''} </div> </div> <div class="w-16 text-right"> <span class="font-mono text-xs text-[var(--muted)]">${req.start + req.dns + req.ttfb + req.processing + req.render}ms</span> </div> </div> `; }).join(''); } function updateTimestamp() { const now = new Date(); elements.lastUpdate.textContent = now.toLocaleTimeString('en-US', { hour12: false }); } function simulateDataUpdate() { // Add new data points with small variations historicalData.ttfb.shift(); historicalData.ttfb.push(clamp(historicalData.ttfb[historicalData.ttfb.length - 1] + (Math.random() - 0.5) * 20, 100, 300)); historicalData.server.shift(); historicalData.server.push(clamp(historicalData.server[historicalData.server.length - 1] + (Math.random() - 0.5) * 30, 180, 400)); historicalData.render.shift(); historicalData.render.push(clamp(historicalData.render[historicalData.render.length - 1] + (Math.random() - 0.5) * 15, 50, 150)); // Update displays const latestTtfb = historicalData.ttfb[historicalData.ttfb.length - 1]; const latestServer = historicalData.server[historicalData.server.length - 1]; const latestRender = historicalData.render[historicalData.render.length - 1]; updateMetricCard('ttfb', latestTtfb, historicalData.ttfb, { optimal: 200, warning: 350 }); updateMetricCard('server', latestServer, historicalData.server, { optimal: 300, warning: 450 }); updateMetricCard('render', latestRender, historicalData.render, { optimal: 100, warning: 150 }); updateTimestamp(); } // Event Listeners elements.refreshBtn.addEventListener('click', () => { elements.refreshBtn.classList.add('animate-spin'); setTimeout(() => { simulateDataUpdate(); elements.refreshBtn.classList.remove('animate-spin'); }, 500); }); // Filter buttons document.querySelectorAll('.filter-btn').forEach(btn => { btn.addEventListener('click', () => { document.querySelectorAll('.filter-btn').forEach(b => b.classList.remove('active')); btn.classList.add('active'); renderEndpointTable(btn.dataset.filter); }); }); // Keyboard accessibility for filters document.querySelectorAll('.filter-btn').forEach(btn => { btn.setAttribute('role', 'button'); btn.setAttribute('tabindex', '0'); btn.addEventListener('keydown', (e) => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); btn.click(); } }); }); // Tooltip functionality document.addEventListener('mouseover', (e) => { const timingEl = e.target.closest('[data-timing]'); const endpointEl = e.target.closest('[data-endpoint]'); if (timingEl) { const metric = timingMetrics.find(m => m.name === timingEl.dataset.timing); if (metric) { showTooltip(e, ` <div class="space-y-2"> <p class="font-semibold">${metric.label}</p> <p class="text-[var(--muted)]">Duration: <span class="font-mono text-[var(--fg)]">${formatMs(metric.value)}</span></p> <p class="text-[var(--muted)]">Metric ID: <span class="font-mono text-[var(--fg)]">${metric.name}</span></p> </div> `); } } else if (endpointEl) { const endpoint = endpoints.find(ep => ep.path === endpointEl.dataset.endpoint); if (endpoint) { const total = endpoint.ttfb + endpoint.server + endpoint.render; showTooltip(e, ` <div class="space-y-2"> <p class="font-semibold">${endpoint.path}</p> <div class="grid grid-cols-2 gap-x-4 gap-y-1 text-xs"> <span class="text-[var(--muted)]">TTFB:</span><span class="font-mono">${formatMs(endpoint.ttfb)}</span> <span class="text-[var(--muted)]">Server:</span><span class="font-mono">${formatMs(endpoint.server)}</span> <span class="text-[var(--muted)]">Render:</span><span class="font-mono">${endpoint.render > 0 ? formatMs(endpoint.render) : '-'}</span> <span class="text-[var(--muted)]">Total:</span><span class="font-mono font-bold">${formatMs(total)}</span> </div> <p class="text-xs text-[var(--muted)]">${endpoint.requests.toLocaleString()} requests today</p> </div> `); } } }); document.addEventListener('mouseout', (e) => { if (e.target.closest('[data-timing]') || e.target.closest('[data-endpoint]')) { hideTooltip(); } }); function showTooltip(e, content) { const tooltip = elements.tooltip; tooltip.innerHTML = content; tooltip.classList.add('visible'); const rect = e.target.getBoundingClientRect(); const tooltipRect = tooltip.getBoundingClientRect(); let left = rect.left + rect.width / 2 - tooltipRect.width / 2; let top = rect.bottom + 10; // Keep tooltip in viewport left = clamp(left, 10, window.innerWidth - tooltipRect.width - 10); top = clamp(top, 10, window.innerHeight - tooltipRect.height - 10); tooltip.style.left = `${left}px`; tooltip.style.top = `${top}px`; } function hideTooltip() { elements.tooltip.classList.remove('visible'); } // Initialize function init() { simulateDataUpdate(); renderTimingBreakdown(); renderEndpointTable(); renderWaterfall(); // Auto-refresh every 5 seconds setInterval(simulateDataUpdate, 5000); } // Run initialization after DOM is ready if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', init); } else { init(); } </script> </body> </html>Key Features
Metrics Dashboard
- TTFB (Time to First Byte): Tracks server response initiation with P50/P95/P99 percentiles
- Server Timing: Full breakdown of internal processing phases (DB queries, cache, auth, etc.)
- Render Duration: Client-side rendering metrics for page routes
Visual Elements
- Live sparkline charts showing historical trends
- Waterfall visualization for request timing breakdown
- Color-coded status indicators (optimal/warning/critical)
- Progress bars for server-timing phases
Interactions
- Live data refresh - Auto-updates every 5 seconds with manual refresh button
- Endpoint filtering - Filter by API/Pages/Static routes
- Hover tooltips - Detailed breakdown on timing metrics and endpoints
- Keyboard accessible - All controls work with keyboard navigation
Technical Considerations
- All numeric values are clamped before rendering
- Respects
prefers-reduced-motion - Uses CSS custom properties for consistent theming
- Monospace font for numeric precision
- Mobile-responsive layout