Add Prometheus metrics support and update configuration #46
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
AI Generated Details/Description:
Add Prometheus Metrics Support for Observability
Summary
This PR adds comprehensive Prometheus metrics support to the AAP MCP Server, enabling production-ready monitoring and observability of the service.
Changes
New Features
1. Metrics Service (
src/metrics.ts)MetricsServiceclass usingprom-client2. Available Metrics
HTTP Metrics:
http_requests_total- Counter for all HTTP requests (labeled by method, route, status_code)http_request_duration_seconds- Histogram of request durationMCP Tool Metrics:
mcp_tool_executions_total- Counter for tool executions (labeled by tool_name, service, category, status)mcp_tool_execution_duration_seconds- Histogram of tool execution duration (labeled by tool_name, service, category)mcp_tool_errors_total- Counter for tool errors (labeled by tool_name, service, category, error_type)mcp_active_tools- Gauge of currently active tools per servicemcp_active_sessions- Gauge of active MCP sessionsAPI Call Metrics:
mcp_api_calls_total- Counter for AAP API calls (labeled by service, endpoint, method, status_code)System Metrics:
3. Integration Points
src/logger.tsnow records metrics for every tool execution4. Configuration
Metrics can be enabled/disabled via configuration:
Or via environment variable:
export ENABLE_METRICS=true5. Endpoints
GET /metrics- Prometheus-formatted metrics endpoint (only available when metrics are enabled)Key Enhancements
getCategoryForTool()helper function to automatically determine which category a tool belongs to (e.g.,job_management,inventory_management, etc.)Usage
Enable Metrics
Access Metrics
Configure Prometheus
Example Queries
Benefits
Breaking Changes
None. Metrics are opt-in and disabled by default.
Testing
Documentation
Updated
README.mdwith Prometheus metrics section including:Dependencies
prom-client@^15.1.3for Prometheus metrics collectionFuture Enhancements