Complete API documentation for the real-time performance monitoring endpoints integrated with Bun v1.3.1 optimizations.
http://localhost:3655/api/performance
- No authentication required (local development)
- All endpoints return JSON responses
- CORS enabled for dashboard integration
Returns real-time performance metrics including FPS, memory usage, uptime, and system load.
{
"timestamp": 1642857600000,
"fps": 144,
"memory": {
"used": 17,
"total": 64,
"external": 2,
"heapUsed": 17,
"heapTotal": 32
},
"uptime": 3600,
"systemLoad": [1.5, 1.2, 1.0],
"version": "Bun v1.3.1-enhanced",
"status": "excellent"
}cURL:
curl -X GET "http://localhost:3655/api/performance/metrics" \
-H "Accept: application/json"JavaScript:
const response = await fetch('/api/performance/metrics');
const metrics = await response.json();
console.log(`FPS: ${metrics.fps}, Memory: ${metrics.memory.used}MB`);Response Fields:
fps: Current frames per second (based on requestAnimationFrame)memory.used: Heap memory used in MBmemory.total: Total heap size in MBuptime: Process uptime in secondssystemLoad: System load averages (1min, 5min, 15min) - Unix onlystatus: Performance status (excellent,good,fair,poor)
Returns historical performance data for trend analysis and charting.
metric(string):memory,fps, oruptime(default:memory)duration(number): Duration in seconds (default: 60)
{
"metric": "memory",
"duration": 60,
"dataPoints": 61,
"history": [
{
"timestamp": 1642857600000,
"value": 17.5,
"metric": "memory"
}
]
}Memory Usage History:
curl "http://localhost:3655/api/performance/history?metric=memory&duration=300"FPS History (Last 2 minutes):
curl "http://localhost:3655/api/performance/history?metric=fps&duration=120"JavaScript Integration:
// Get memory history for the last 5 minutes
const response = await fetch('/api/performance/history?metric=memory&duration=300');
const data = await response.json();
// Use for charting
data.history.forEach(point => {
chart.addPoint(point.timestamp, point.value);
});Returns active performance alerts and warnings based on current metrics.
{
"total": 1,
"alerts": [
{
"id": "performance-excellent",
"type": "info",
"title": "Excellent Performance",
"message": "System is running optimally with 17MB memory usage",
"timestamp": 1642857600000,
"metric": "performance",
"value": "excellent",
"threshold": "good"
}
],
"timestamp": 1642857600000
}critical: Immediate action required (memory > 200MB)warning: Elevated usage (memory > 100MB)info: Positive performance indicators
Check for Alerts:
curl "http://localhost:3655/api/performance/alerts"Dashboard Integration:
const alerts = await fetch('/api/performance/alerts').then(r => r.json());
// Display alerts in UI
alerts.alerts.forEach(alert => {
showNotification(alert.title, alert.message, alert.type);
});Returns system benchmarks and Bun v1.3.1 optimization details.
{
"timestamp": 1642857600000,
"system": {
"platform": "darwin",
"arch": "x64",
"nodeVersion": "v18.0.0",
"bunVersion": "1.3.1"
},
"metrics": {
"fps": 144,
"memoryUsage": 17,
"uptime": 3600,
"status": "excellent"
},
"benchmarks": {
"Bun v1.3.1 Optimizations": {
"Build Performance": "2x faster isolated linker",
"Memory Efficiency": "17 MB baseline usage",
"FPS Performance": "144 FPS sustained",
"Test Execution": "--only-failures --pass-with-no-tests",
"Registry Auth": "Native email forwarding"
}
}
}Returns aggregated dashboard data for comprehensive monitoring views.
{
"timestamp": 1642857600000,
"summary": {
"status": "excellent",
"uptime": 3600,
"memoryUsage": 17,
"fps": 144,
"activeAlerts": 0,
"lastUpdate": "2023-01-22T10:00:00.000Z"
},
"charts": {
"fps": {
"current": 144,
"average": 142,
"min": 120,
"max": 144,
"trend": "stable"
},
"memory": {
"current": 17,
"average": 16,
"min": 12,
"max": 25,
"trend": "stable"
}
},
"alerts": [],
"recommendations": [
{
"type": "optimization",
"title": "Bun v1.3.1 Performance",
"message": "Your system is running optimally with Bun v1.3.1 enhancements",
"priority": "low"
}
]
}# Run comprehensive API tests
bun run scripts/test-performance-api.ts# Test metrics endpoint
curl "http://localhost:3655/api/performance/metrics"
# Test history with different metrics
curl "http://localhost:3655/api/performance/history?metric=fps&duration=30"
curl "http://localhost:3655/api/performance/history?metric=memory&duration=60"
# Test alerts
curl "http://localhost:3655/api/performance/alerts"
# Test benchmarks
curl "http://localhost:3655/api/performance/benchmarks"
# Test dashboard data
curl "http://localhost:3655/api/performance/dashboard"import { useEffect, useState } from 'react';
function usePerformanceMetrics() {
const [metrics, setMetrics] = useState(null);
useEffect(() => {
const fetchMetrics = async () => {
const response = await fetch('/api/performance/metrics');
const data = await response.json();
setMetrics(data);
};
fetchMetrics();
const interval = setInterval(fetchMetrics, 2000);
return () => clearInterval(interval);
}, []);
return metrics;
}
// Usage
function PerformanceDashboard() {
const metrics = usePerformanceMetrics();
if (!metrics) return <div>Loading...</div>;
return (
<div>
<h2>FPS: {metrics.fps}</h2>
<h2>Memory: {metrics.memory.used}MB</h2>
<h2>Status: {metrics.status}</h2>
</div>
);
}import Chart from 'chart.js';
async function createPerformanceChart() {
const response = await fetch('/api/performance/history?metric=memory&duration=300');
const data = await response.json();
new Chart(document.getElementById('performance-chart'), {
type: 'line',
data: {
labels: data.history.map(point => new Date(point.timestamp).toLocaleTimeString()),
datasets: [{
label: 'Memory Usage (MB)',
data: data.history.map(point => point.value),
borderColor: 'rgb(75, 192, 192)',
tension: 0.1
}]
}
});
}// WebSocket or Server-Sent Events for real-time updates
const eventSource = new EventSource('/api/performance/stream');
eventSource.onmessage = (event) => {
const metrics = JSON.parse(event.data);
updateDashboard(metrics);
};// Poll for alerts every 30 seconds
setInterval(async () => {
const response = await fetch('/api/performance/alerts');
const data = await response.json();
data.alerts.forEach(alert => {
showNotification(alert.title, alert.message, alert.type);
});
}, 30000);- All endpoints are open for local development
- No authentication required on
localhost:3655 - CORS enabled for dashboard integration
- Consider adding API key authentication
- Rate limiting for monitoring endpoints
- HTTPS enforcement
- IP whitelisting for sensitive metrics
- Metrics: < 10ms (local system calls)
- History: < 50ms (data generation)
- Alerts: < 20ms (threshold checking)
- Benchmarks: < 5ms (static data)
- Dashboard: < 30ms (aggregation)
- Base API: ~2MB additional memory
- History Storage: ~1MB for 60-second buffers
- Concurrent Connections: Minimal impact (< 100KB per connection)
- Concurrent Requests: Handles 1000+ RPS
- Data Retention: 60-second rolling history
- Real-time Updates: 2-second intervals
- System Load: Low CPU overhead (< 1%)
-
Start the Server:
bun run src/server.ts
-
Test API Endpoints:
curl "http://localhost:3655/api/performance/metrics" -
View Dashboard:
http://localhost:3655 -
Run Tests:
bun run scripts/test-performance-api.ts
| Endpoint | Method | Description |
|---|---|---|
/api/performance/metrics |
GET | Real-time performance metrics |
/api/performance/history |
GET | Historical data with query params |
/api/performance/alerts |
GET | Active performance alerts |
/api/performance/benchmarks |
GET | System benchmarks and specs |
/api/performance/dashboard |
GET | Aggregated dashboard data |
All endpoints return JSON responses with proper HTTP status codes and error handling.