Skip to content

License Monitor API

License Monitor provides a comprehensive REST API with WebSocket and Server-Sent Events support for real-time data access and system management.

All API endpoints are prefixed with /api/ for consistency and future extensibility.

http://localhost:8080/api/

License Monitor supports API key authentication for secure access.

X-API-Key: your-api-key-here
Content-Type: application/json
Terminal window
curl -H "X-API-Key: your-api-key" \
-H "Content-Type: application/json" \
http://localhost:8080/api/health

Check the health status of the License Monitor service.

GET /api/health

Response:

{
"status": "healthy",
"timestamp": "2024-01-01T12:00:00Z",
"version": "1.0.0",
"uptime": 3600,
"memory_usage": {
"used": "50MB",
"total": "100MB"
}
}

Get comprehensive server information and capabilities.

GET /api/server-info

Response:

{
"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
}
}

Get lightweight server status information.

GET /api/status

Response:

{
"status": "running",
"mode": "both",
"active_connections": 5,
"last_update": "2024-01-01T12:00:00Z"
}

Get current performance metrics.

GET /api/metrics

Response:

{
"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
}

Get network interface information.

GET /api/network

Response:

{
"interfaces": [
{
"name": "eth0",
"ip": "192.168.1.100",
"status": "up",
"speed": "1000Mbps"
}
],
"listening_ports": [8080],
"external_ip": "203.0.113.1"
}

Execute license manager commands with JSON request body.

POST /api/execute

Request 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 (cached or fresh).

GET /api/licenses?refresh=false

Query 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 with system integration.

GET /api/stats

Response:

{
"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"
}

Get recent log entries with filtering.

GET /api/logs/recent?lines=100&levels=error,warning

Query Parameters:

  • lines (integer): Number of log lines to return
  • levels (string): Comma-separated log levels to filter
  • since (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 with pagination.

GET /api/logs/search?query=error&page=1&limit=50

Query Parameters:

  • query (string): Search query
  • page (integer): Page number
  • limit (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
}
}

Get log stream statistics.

GET /api/logs/stats

Response:

{
"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 all stored log entries.

POST /api/logs/clear

Response:

{
"success": true,
"cleared_lines": 10000,
"timestamp": "2024-01-01T12:00:00Z"
}
const ws = new WebSocket('ws://localhost:8080/ws/logs');
ws.onmessage = (event) => {
const data = JSON.parse(event.data);
console.log('Log entry:', data);
};
const ws = new WebSocket('ws://localhost:8080/ws/metrics');
ws.onmessage = (event) => {
const data = JSON.parse(event.data);
console.log('Metrics:', data);
};
const ws = new WebSocket('ws://localhost:8080/ws/combined');
ws.onmessage = (event) => {
const data = JSON.parse(event.data);
console.log('Data:', data);
};
const eventSource = new EventSource('http://localhost:8080/stream/logs');
eventSource.onmessage = (event) => {
const data = JSON.parse(event.data);
console.log('Log entry:', data);
};
const eventSource = new EventSource('http://localhost:8080/stream/metrics');
eventSource.onmessage = (event) => {
const data = JSON.parse(event.data);
console.log('Metrics:', data);
};

For backwards compatibility, legacy endpoints redirect to new API endpoints:

  • /execute/api/execute
  • /stats/api/stats
  • /health/api/health
  • /ping/api/ping
{
"error": {
"code": "INVALID_COMMAND",
"message": "Command execution failed",
"details": "Command 'invalid_command' not found",
"timestamp": "2024-01-01T12:00:00Z",
"request_id": "req_123456789"
}
}
  • 200 - Success
  • 400 - Bad Request
  • 401 - Unauthorized
  • 403 - Forbidden
  • 404 - Not Found
  • 429 - Too Many Requests
  • 500 - Internal Server Error
  • 503 - Service Unavailable
  • INVALID_COMMAND - Command execution failed
  • AUTHENTICATION_FAILED - Authentication failed
  • RATE_LIMIT_EXCEEDED - Rate limit exceeded
  • CONNECTION_FAILED - Connection to license server failed
  • PARSE_ERROR - Data parsing failed
  • CONFIGURATION_ERROR - Configuration error

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: 60
X-RateLimit-Remaining: 59
X-RateLimit-Reset: 1640995200