Skip to main content

Overview

The Secure MCP Gateway exports comprehensive metrics via OpenTelemetry to Prometheus. These metrics provide insights into:
  • Operation Performance: Request rates, latencies, success/failure rates
  • Cache Efficiency: Hit/miss ratios, cache sizes
  • Security Events: Guardrail violations, blocked requests, PII redactions
  • Resource Usage: Active sessions, users, timeout operations
  • System Health: Authentication success/failure, error rates

Metrics Architecture

Available Metrics

Operation Metrics

Tool Call Counters

Counter
Total number of tool invocations across all servers.Labels: server_name, tool_name, project_idUsage: Track overall tool usage and identify popular tools
Counter
Total number of successful tool calls.Labels: server_name, tool_nameUsage: Calculate success rates, identify reliable tools
Counter
Total number of failed tool calls (e.g., server errors, timeouts).Labels: server_name, tool_name, error_typeUsage: Monitor error rates, set up alerts for high failure rates
Counter
Total number of tool call errors (exceptions, crashes).Labels: server_name, error_typeUsage: Track critical errors requiring immediate attention

Tool Call Latency

Histogram
Duration of tool calls in seconds. Includes percentiles (p50, p95, p99).Labels: server_name, tool_nameBuckets: 0.1, 0.5, 1.0, 2.0, 5.0, 10.0, +InfUsage: Identify slow tools, set SLOs, detect performance degradation
Example PromQL Queries:

Server Discovery

Counter
Number of times enkrypt_list_all_servers was called.Labels: user_id, project_idUsage: Track server listing frequency
Counter
Total number of servers discovered with tools.Labels: mcp_config_idUsage: Monitor server discovery operations

Cache Metrics

Counter
Total number of cache hits (data found in cache).Labels: cache_type (tools, gateway_config, server_config)Usage: Monitor cache effectiveness
Counter
Total number of cache misses (data not in cache, fetch required).Labels: cache_typeUsage: Identify cache tuning opportunities
Example PromQL Queries:

Security Metrics

Guardrail Violations

Counter
Total number of guardrail violations detected.Labels: violation_type, server_name, detectorUsage: Monitor security posture, detect attack patterns
Counter
Guardrail violations on input (before sending to server).Labels: violation_type, server_nameUsage: Track input validation issues
Counter
Guardrail violations on output (after receiving from server).Labels: violation_type, server_nameUsage: Monitor response quality and safety
Counter
Relevancy check violations (response not relevant to input).Labels: server_name, tool_name
Counter
Adherence check violations (response doesn’t follow instructions).Labels: server_name, tool_name
Counter
Hallucination detection violations.Labels: server_name, tool_name

Blocked Requests

Counter
Total number of tool calls blocked by guardrails.Labels: server_name, tool_name, reasonUsage: Monitor security enforcement, identify attack attempts
Counter
Total number of PII redaction operations performed.Labels: server_name, pii_typeUsage: Track PII protection, ensure compliance

Guardrail API Performance

Counter
Total number of API requests to guardrail service.Labels: endpoint, status_codeUsage: Monitor guardrail service usage
Histogram
Duration of guardrail API requests in seconds.Labels: endpointBuckets: 0.1, 0.5, 1.0, 2.0, 5.0, 10.0, +InfUsage: Monitor guardrail latency, set alerts for slow checks
Example PromQL Queries:

Authentication Metrics

Counter
Total number of successful authentications.Labels: auth_provider, project_idUsage: Monitor authentication activity
Counter
Total number of failed authentication attempts.Labels: auth_provider, failure_reasonUsage: Detect unauthorized access attempts, brute force attacks
UpDownCounter
Current number of active sessions.Usage: Monitor concurrent connections
UpDownCounter
Current number of active users.Usage: Track user concurrency
Example PromQL Queries:

Timeout Management Metrics

Counter
Total number of timeout operations tracked.Labels: operation_typeUsage: Monitor timeout tracking coverage
Counter
Number of operations completed successfully before timeout.Labels: operation_type
Counter
Number of operations that exceeded timeout threshold.Labels: operation_typeUsage: Set alerts for high timeout rates
Counter
Number of operations that were cancelled.Labels: operation_type

Timeout Escalations

Counter
Number of timeout escalation warnings (>80% of timeout).Labels: operation_typeUsage: Early warning for slow operations
Counter
Number of operations that reached timeout threshold.Labels: operation_type
Counter
Number of operations that exceeded timeout and failed.Labels: operation_type

Timeout Performance

Histogram
Duration of timeout-managed operations in seconds.Labels: operation_typeBuckets: 0.5, 1.0, 2.0, 5.0, 10.0, 30.0, 60.0, +Inf
UpDownCounter
Number of currently active timeout operations.Usage: Monitor concurrent operations
Example PromQL Queries:

Metrics Implementation

Creating Metrics

Metrics are created during OpenTelemetry provider initialization: Location: src/secure_mcp_gateway/plugins/telemetry/opentelemetry_provider.py:373

Recording Metrics

Metrics are recorded throughout the gateway:

Prometheus Configuration

Scrape Configuration

Location: infra/prometheus/prometheus.yml

Accessing Prometheus

Example Queries

In Prometheus UI (Expression Browser):

Grafana Dashboards

Pre-built Dashboards

The gateway includes two pre-configured Grafana dashboards:

1. Gateway Metrics Dashboard

Location: infra/grafana/provisioning/dashboards/gateway-metrics.json Panels:
  • Tool Call Rate (graph)
  • Tool Call Success Rate (gauge)
  • Tool Call Latency p95 (graph)
  • Cache Hit Ratio (gauge)
  • Guardrail Violations (graph)
  • Active Sessions (gauge)
  • Error Rate (graph)

2. OpenTelemetry Gateway Metrics Dashboard

Location: infra/grafana/provisioning/dashboards/OpenTelemetry Gateway Metrics.json Panels:
  • Request Volume
  • Response Times (percentiles)
  • Error Rates by Type
  • Throughput
  • System Health

Accessing Grafana

  1. Open http://localhost:3000
  2. No login required (anonymous admin mode)
  3. Navigate to Dashboards → Browse
  4. Select “Gateway Metrics” or “OpenTelemetry Gateway Metrics”

Creating Custom Dashboards

Example Panel (Tool Call Rate):
Example Panel (Cache Hit Ratio):

Alerting

Prometheus Alerts

Create alert rules in Prometheus: alerting_rules.yml:

Grafana Alerts

Create alerts in Grafana dashboards:
  1. Edit panel → Alert tab
  2. Create alert rule
  3. Configure notification channels (Slack, PagerDuty, email)

Best Practices

Focus on Service Level Indicators:
  • Availability: Success rate > 99.9%
  • Latency: p95 < 500ms, p99 < 1s
  • Error Rate: < 0.1%
  • Cache Hit Ratio: > 80%
Configure alerts for:
  • High error rates
  • Slow operations (p95 > threshold)
  • Security events (guardrail violations)
  • Resource exhaustion (high active sessions)
Avoid high-cardinality labels:
  • ✅ Good: server_name, tool_name, project_id
  • ❌ Bad: user_id, request_id, timestamp
High cardinality increases memory usage and query time.
Track security events:
  • Guardrail violations by type
  • Blocked requests over time
  • PII redaction frequency
  • Authentication failures
Set up alerts for anomalies.

Troubleshooting

Metrics Not Appearing in Prometheus

  1. Check collector metrics endpoint:
  2. Verify Prometheus scrape targets: http://localhost:9090/targets
  3. Check collector logs:

High Cardinality Issues

Symptom: Prometheus using excessive memory Solution: Reduce label cardinality

Dashboards Not Loading

  1. Check Grafana logs:
  2. Verify datasource connection: Grafana → Connections → Data sources → Prometheus → Test
  3. Check dashboard JSON:

Next Steps

Logging

Configure structured logging and log aggregation

OpenTelemetry Setup

Set up OTLP export and distributed tracing

Overview

Return to observability overview

API Reference

Explore the monitoring API