License Monitor API
License Monitor API Reference
Section titled “License Monitor API Reference”License Monitor provides a comprehensive REST API with WebSocket and Server-Sent Events support for real-time data access and system management.
Base URL
Section titled “Base URL”All API endpoints are prefixed with /api/ for consistency and future extensibility.
http://localhost:8080/api/Authentication
Section titled “Authentication”License Monitor supports API key authentication for secure access.
Headers
Section titled “Headers”X-API-Key: your-api-key-hereContent-Type: application/jsonExample
Section titled “Example”curl -H "X-API-Key: your-api-key" \ -H "Content-Type: application/json" \ http://localhost:8080/api/healthSystem Information Endpoints
Section titled “System Information Endpoints”Health Check
Section titled “Health Check”Check the health status of the License Monitor service.
GET /api/healthResponse:
{ "status": "healthy", "timestamp": "2024-01-01T12:00:00Z", "version": "1.0.0", "uptime": 3600, "memory_usage": { "used": "50MB", "total": "100MB" }}Server Information
Section titled “Server Information”Get comprehensive server information and capabilities.
GET /api/server-infoResponse:
{ "name": "license-monitor", "version": "1.0.0", "build_date": "2024-01-01T00:00:00Z", "capabilities": [ "command_mode", "tail_mode", "api_mode", "websocket", "sse" ], "operating_mode": "both", "config": { "api_enabled": true, "websocket_enabled": true, "max_connections": 100 }}Server Status
Section titled “Server Status”Get lightweight server status information.
GET /api/statusResponse:
{ "status": "running", "mode": "both", "active_connections": 5, "last_update": "2024-01-01T12:00:00Z"}Performance Metrics
Section titled “Performance Metrics”Get current performance metrics.
GET /api/metricsResponse:
{ "cpu_usage": 15.5, "memory_usage": 45.2, "disk_usage": 30.1, "network_io": { "bytes_in": 1024000, "bytes_out": 2048000 }, "requests_per_second": 10.5, "active_connections": 5}Network Information
Section titled “Network Information”Get network interface information.
GET /api/networkResponse:
{ "interfaces": [ { "name": "eth0", "ip": "192.168.1.100", "status": "up", "speed": "1000Mbps" } ], "listening_ports": [8080], "external_ip": "203.0.113.1"}License Management Endpoints
Section titled “License Management Endpoints”Execute Command
Section titled “Execute Command”Execute license manager commands with JSON request body.
POST /api/executeRequest Body:
{ "command": "lmstat -a", "timeout": 30, "working_directory": "/opt/license_manager", "environment": { "LM_LICENSE_FILE": "/opt/licenses/license.dat" }}Response:
{ "success": true, "exit_code": 0, "stdout": "Users of feature1: (Total of 10 licenses issued; Total of 8 licenses in use)", "stderr": "", "execution_time": 1.5, "timestamp": "2024-01-01T12:00:00Z"}Get License Information
Section titled “Get License Information”Get license information (cached or fresh).
GET /api/licenses?refresh=falseQuery Parameters:
refresh(boolean): Force refresh of license data
Response:
{ "licenses": [ { "feature": "feature1", "total": 10, "used": 8, "available": 2, "users": [ { "user": "user1", "host": "host1", "display": "user1@host1", "start_time": "2024-01-01T10:00:00Z" } ] } ], "timestamp": "2024-01-01T12:00:00Z", "cached": true}Get Enhanced Stats
Section titled “Get Enhanced Stats”Get enhanced stats with system integration.
GET /api/statsResponse:
{ "license_stats": { "total_features": 5, "total_licenses": 50, "used_licenses": 35, "available_licenses": 15 }, "system_stats": { "uptime": 3600, "memory_usage": "45MB", "cpu_usage": 15.5 }, "timestamp": "2024-01-01T12:00:00Z"}Log Management Endpoints
Section titled “Log Management Endpoints”Get Recent Logs
Section titled “Get Recent Logs”Get recent log entries with filtering.
GET /api/logs/recent?lines=100&levels=error,warningQuery Parameters:
lines(integer): Number of log lines to returnlevels(string): Comma-separated log levels to filtersince(string): ISO timestamp to filter logs since
Response:
{ "logs": [ { "timestamp": "2024-01-01T12:00:00Z", "level": "info", "message": "License check completed", "source": "command_mode" } ], "total_lines": 100, "filtered_lines": 50}Advanced Log Search
Section titled “Advanced Log Search”Advanced log search with pagination.
GET /api/logs/search?query=error&page=1&limit=50Query Parameters:
query(string): Search querypage(integer): Page numberlimit(integer): Results per page
Response:
{ "results": [ { "timestamp": "2024-01-01T12:00:00Z", "level": "error", "message": "License server connection failed", "source": "api" } ], "pagination": { "page": 1, "limit": 50, "total": 150, "pages": 3 }}Log Statistics
Section titled “Log Statistics”Get log stream statistics.
GET /api/logs/statsResponse:
{ "total_logs": 10000, "logs_by_level": { "error": 50, "warning": 100, "info": 9500, "debug": 350 }, "logs_by_source": { "command_mode": 5000, "tail_mode": 3000, "api": 2000 }, "last_log": "2024-01-01T12:00:00Z"}Clear Logs
Section titled “Clear Logs”Clear all stored log entries.
POST /api/logs/clearResponse:
{ "success": true, "cleared_lines": 10000, "timestamp": "2024-01-01T12:00:00Z"}Real-time Streaming Endpoints
Section titled “Real-time Streaming Endpoints”WebSocket Endpoints
Section titled “WebSocket Endpoints”Log Streaming
Section titled “Log Streaming”const ws = new WebSocket('ws://localhost:8080/ws/logs');ws.onmessage = (event) => { const data = JSON.parse(event.data); console.log('Log entry:', data);};Metrics Streaming
Section titled “Metrics Streaming”const ws = new WebSocket('ws://localhost:8080/ws/metrics');ws.onmessage = (event) => { const data = JSON.parse(event.data); console.log('Metrics:', data);};Combined Streaming
Section titled “Combined Streaming”const ws = new WebSocket('ws://localhost:8080/ws/combined');ws.onmessage = (event) => { const data = JSON.parse(event.data); console.log('Data:', data);};Server-Sent Events (SSE)
Section titled “Server-Sent Events (SSE)”Log Streaming
Section titled “Log Streaming”const eventSource = new EventSource('http://localhost:8080/stream/logs');eventSource.onmessage = (event) => { const data = JSON.parse(event.data); console.log('Log entry:', data);};Metrics Streaming
Section titled “Metrics Streaming”const eventSource = new EventSource('http://localhost:8080/stream/metrics');eventSource.onmessage = (event) => { const data = JSON.parse(event.data); console.log('Metrics:', data);};Legacy Compatibility
Section titled “Legacy Compatibility”For backwards compatibility, legacy endpoints redirect to new API endpoints:
/execute→/api/execute/stats→/api/stats/health→/api/health/ping→/api/ping
Error Handling
Section titled “Error Handling”Error Response Format
Section titled “Error Response Format”{ "error": { "code": "INVALID_COMMAND", "message": "Command execution failed", "details": "Command 'invalid_command' not found", "timestamp": "2024-01-01T12:00:00Z", "request_id": "req_123456789" }}HTTP Status Codes
Section titled “HTTP Status Codes”200- Success400- Bad Request401- Unauthorized403- Forbidden404- Not Found429- Too Many Requests500- Internal Server Error503- Service Unavailable
Error Codes
Section titled “Error Codes”INVALID_COMMAND- Command execution failedAUTHENTICATION_FAILED- Authentication failedRATE_LIMIT_EXCEEDED- Rate limit exceededCONNECTION_FAILED- Connection to license server failedPARSE_ERROR- Data parsing failedCONFIGURATION_ERROR- Configuration error
Rate Limiting
Section titled “Rate Limiting”License Monitor implements rate limiting to prevent abuse:
- Default: 60 requests per minute per IP
- Configurable: Via configuration file
- Headers: Rate limit information in response headers
X-RateLimit-Limit: 60X-RateLimit-Remaining: 59X-RateLimit-Reset: 1640995200Next Steps
Section titled “Next Steps”- WebSocket & SSE: Real-time streaming protocols
- Authentication: Authentication methods and security
- Error Handling: Error codes and troubleshooting
- License Monitor Configuration: Configuration options