This document outlines the complete backend API implementation required to support the Health Monitor dashboard. The frontend application expects these endpoints to provide comprehensive error monitoring, analytics, and system management capabilities.
https://your-domain.com/api
All endpoints (except health check) require API key authentication:
X-API-Key: your-api-key-hereAll responses should follow this consistent format:
Success Response:
{
"data": { ... },
"status": "success"
}Error Response:
{
"error": "Error description",
"status": "error"
}GET /healthPurpose: API health status check
Authentication: Not required
Response:
{
"status": "ok",
"timestamp": "2025-01-20T10:30:00Z"
}POST /api/errorsPurpose: Create new error entries
Request Body:
{
"level": "error",
"message": "Database connection failed",
"stack_trace": "Error: Connection timeout\n at Database.connect...",
"context": {
"user_id": "12345",
"session_id": "abc-def-ghi",
"request_id": "req-789",
"additional_data": "any value"
},
"source": "backend",
"environment": "production",
"url": "https://api.example.com/users"
}Response:
{
"data": {
"id": "550e8400-e29b-41d4-a716-446655440000",
"timestamp": "2025-01-20T10:30:00Z",
"level": "error",
"message": "Database connection failed",
"stack_trace": "Error: Connection timeout...",
"context": { ... },
"source": "backend",
"environment": "production",
"user_agent": "Mozilla/5.0...",
"ip_address": "192.168.1.100",
"url": "https://api.example.com/users",
"fingerprint": "abc123def456",
"resolved": false,
"count": 1,
"first_seen": "2025-01-20T10:30:00Z",
"last_seen": "2025-01-20T10:30:00Z",
"created_at": "2025-01-20T10:30:00Z",
"updated_at": "2025-01-20T10:30:00Z"
},
"status": "success"
}GET /api/errorsPurpose: Retrieve paginated error list with filtering
Query Parameters:
limit(integer, 1-100): Number of errors to return. Default: 50offset(integer): Number of errors to skip. Default: 0level(string): Filter by error level (error, warning, info, debug)source(string): Filter by error sourceresolved(boolean): Filter by resolution statussearch(string): Search in error messages
Examples:
GET /api/errors?limit=20&offset=0
GET /api/errors?level=error&source=frontend
GET /api/errors?resolved=false&limit=10Response:
{
"data": {
"errors": [
{
"id": "550e8400-e29b-41d4-a716-446655440000",
"timestamp": "2025-01-20T10:30:00Z",
"level": "error",
"message": "Database connection failed",
"source": "backend",
"resolved": false,
"count": 5
}
],
"total": 150,
"page": 1,
"limit": 50
},
"status": "success"
}GET /api/errors/{id}Purpose: Get complete error details
Response: Full error object with all fields
PUT /api/errors/{id}/resolvePurpose: Mark an error as resolved
Response:
{
"data": {
"status": "resolved"
},
"status": "success"
}DELETE /api/errors/{id}Purpose: Delete an error
Response: 204 No Content
GET /api/statsPurpose: Get comprehensive error statistics
Response:
{
"data": {
"total_errors": 1250,
"resolved_errors": 856,
"errors_today": 23,
"errors_this_week": 145,
"errors_this_month": 567,
"error_rate_24h": 2.3,
"resolution_rate": 68.5,
"avg_resolution_time": "2h 15m"
},
"status": "success"
}GET /api/analytics/trendsPurpose: Get error trend data for charts
Query Parameters:
period(string): time, week, month, yeargroup_by(string): hour, day, week, month
Response:
{
"data": {
"period": "week",
"data_points": [
{
"timestamp": "2025-01-14T00:00:00Z",
"error_count": 45,
"resolved_count": 32,
"critical_count": 3
},
{
"timestamp": "2025-01-15T00:00:00Z",
"error_count": 52,
"resolved_count": 38,
"critical_count": 1
}
]
},
"status": "success"
}GET /api/analytics/performancePurpose: System performance analytics
Response:
{
"data": {
"avg_response_time": 245,
"error_rate_percent": 0.8,
"throughput_rpm": 1200,
"availability_percent": 99.95,
"performance_score": 8.7
},
"status": "success"
}GET /api/monitoring/servicesPurpose: Get health status of all services
Response:
{
"data": {
"services": [
{
"name": "Database",
"status": "healthy",
"uptime_percent": 99.8,
"response_time_ms": 12,
"last_checked": "2025-01-20T10:29:00Z",
"details": {
"connections": 45,
"max_connections": 100
}
},
{
"name": "Cache Service",
"status": "healthy",
"uptime_percent": 99.95,
"response_time_ms": 3,
"last_checked": "2025-01-20T10:29:00Z"
}
],
"overall_health": "healthy"
},
"status": "success"
}GET /api/monitoring/metricsPurpose: Get system performance metrics
Query Parameters:
timeframe(string): 1h, 6h, 24h, 7d, 30d
Response:
{
"data": {
"cpu_usage_percent": 65.2,
"memory_usage_percent": 78.1,
"disk_usage_percent": 45.7,
"network_io": {
"bytes_in": 1024000,
"bytes_out": 2048000
},
"active_connections": 45,
"requests_per_minute": 1200
},
"status": "success"
}GET /api/monitoring/uptimePurpose: Historical uptime data
Response:
{
"data": {
"current_uptime_hours": 720.5,
"uptime_percent_24h": 100.0,
"uptime_percent_7d": 99.8,
"uptime_percent_30d": 99.95,
"incidents_count": 2,
"last_downtime": "2025-01-10T14:30:00Z"
},
"status": "success"
}GET /api/alerts/rulesPurpose: Get all alert rules
Response:
{
"data": {
"rules": [
{
"id": "rule-1",
"name": "High Error Rate",
"condition": "error_count > 50 in 5 minutes",
"threshold": 50,
"enabled": true,
"notifications": ["email", "slack"],
"last_triggered": "2025-01-15T10:30:00Z",
"created_at": "2025-01-10T09:00:00Z"
}
]
},
"status": "success"
}POST /api/alerts/rulesPurpose: Create new alert rule
Request Body:
{
"name": "High Error Rate",
"condition": "error_count > threshold in time_window",
"threshold": 50,
"time_window": "5m",
"notifications": ["email", "slack"],
"enabled": true
}PUT /api/alerts/rules/{id}Purpose: Update alert rule
DELETE /api/alerts/rules/{id}Purpose: Delete alert rule
GET /api/alerts/incidentsPurpose: Get incident list
Response:
{
"data": {
"incidents": [
{
"id": "incident-1",
"title": "Database Connection Timeout",
"severity": "critical",
"status": "investigating",
"created_at": "2025-01-20T14:30:00Z",
"updated_at": "2025-01-20T14:45:00Z",
"assigned_to": "user-123",
"description": "Multiple database connection timeouts detected"
}
]
},
"status": "success"
}POST /api/alerts/incidentsPurpose: Create new incident
PUT /api/alerts/incidents/{id}Purpose: Update incident status
GET /api/settings/api-keysPurpose: Get list of API keys
Response:
{
"data": {
"api_keys": [
{
"id": "key-1",
"name": "Production API Key",
"key_preview": "sk_live_****7890",
"permissions": ["read", "write"],
"last_used": "2025-01-20T10:30:00Z",
"created_at": "2025-01-10T09:00:00Z"
}
]
},
"status": "success"
}POST /api/settings/api-keysPurpose: Create new API key
Request Body:
{
"name": "Development Key",
"permissions": ["read"],
"expires_at": "2025-12-31T23:59:59Z"
}DELETE /api/settings/api-keys/{id}Purpose: Revoke API key
GET /api/settings/teamPurpose: Get team members
Response:
{
"data": {
"members": [
{
"id": "user-1",
"name": "John Doe",
"email": "john@company.com",
"role": "developer",
"status": "active",
"last_active": "2025-01-20T10:30:00Z",
"created_at": "2025-01-10T09:00:00Z"
}
]
},
"status": "success"
}POST /api/settings/team/invitePurpose: Invite team member
Request Body:
{
"email": "newuser@company.com",
"role": "viewer"
}GET /api/settings/integrationsPurpose: Get integration status
Response:
{
"data": {
"integrations": [
{
"name": "slack",
"status": "connected",
"config": {
"webhook_url": "https://hooks.slack.com/...",
"channel": "#alerts"
},
"last_test": "2025-01-20T10:30:00Z"
}
]
},
"status": "success"
}For real-time error streaming and live updates:
// WebSocket connection
const ws = new WebSocket('wss://your-domain.com/ws?token=your-api-key');
// Message formats
{
"type": "new_error",
"data": { /* full error object */ }
}
{
"type": "error_resolved",
"data": { "id": "error-id" }
}
{
"type": "service_status_change",
"data": { "service": "database", "status": "unhealthy" }
}interface BackendError {
id: string;
timestamp: string;
level: "error" | "warning" | "info" | "debug";
message: string;
stack_trace?: string;
context?: Record<string, any>;
source: string;
environment?: string;
user_agent?: string;
ip_address?: string;
url?: string;
fingerprint?: string;
resolved: boolean;
count: number;
first_seen: string;
last_seen: string;
created_at: string;
updated_at: string;
}interface ServiceHealth {
name: string;
status: "healthy" | "unhealthy" | "unknown";
uptime_percent: number;
response_time_ms: number;
last_checked: string;
details?: Record<string, any>;
}Errors should be grouped using a fingerprint based on:
- Error message (normalized)
- Stack trace (first 3 lines, normalized)
- Source location
Example fingerprint generation:
function generateFingerprint(error) {
const message = normalizeMessage(error.message);
const stackTrace = normalizeStackTrace(error.stack_trace);
return hash(message + stackTrace + error.source);
}- Increment
countfor duplicate fingerprints - Update
last_seentimestamp - Keep
first_seenunchanged - Merge context data intelligently
- Error logging: 1000 requests/minute per API key
- Analytics queries: 100 requests/minute per API key
- General API: 500 requests/minute per API key
- Error lists: Cache for 2 minutes
- Statistics: Cache for 1 minute
- Service health: Cache for 30 seconds
- Configuration: Cache for 10 minutes
Required indexes for performance:
-- Errors table
CREATE INDEX idx_errors_timestamp ON errors(timestamp);
CREATE INDEX idx_errors_level ON errors(level);
CREATE INDEX idx_errors_source ON errors(source);
CREATE INDEX idx_errors_resolved ON errors(resolved);
CREATE INDEX idx_errors_fingerprint ON errors(fingerprint);
-- Composite indexes
CREATE INDEX idx_errors_level_timestamp ON errors(level, timestamp);
CREATE INDEX idx_errors_resolved_timestamp ON errors(resolved, timestamp);- Use secure random generation for API keys
- Store hashed versions in database
- Support key rotation without downtime
- Track key usage and last access
- Sanitize sensitive data in error contexts
- Support PII redaction
- Implement data retention policies
- Provide data export capabilities
Role-based permissions:
- Owner: Full access to all features
- Admin: Manage settings, view all data
- Developer: View errors, manage rules
- Viewer: Read-only access
- Error ingestion endpoint
- Error storage with fingerprinting
- Basic error retrieval
- Error resolution functionality
- Statistics aggregation
- Trend analysis endpoints
- Service health monitoring
- Performance metrics collection
- Alert rule engine
- Incident management
- Real-time WebSocket updates
- Team & permission management
- Advanced integrations
- Custom dashboards
- Data export/import
- Audit logging
This API implementation guide provides the complete backend structure needed to support the Health Monitor frontend application. Each endpoint is designed to provide the data and functionality expected by the corresponding frontend components.