@@ -52,21 +52,21 @@ appears in OpenAPI / Swagger) and gzip compression is enabled by default
5252
53531 . Ensure ` ENABLE_METRICS=true ` in your shell or ` .env ` .
5454
55- ```bash
56- export ENABLE_METRICS=true
57- export METRICS_CUSTOM_LABELS="env=local,team=dev"
58- export METRICS_EXCLUDED_HANDLERS="/servers/.*/sse,/static/.*"
59- ```
55+ ``` bash
56+ export ENABLE_METRICS=true
57+ export METRICS_CUSTOM_LABELS=" env=local,team=dev"
58+ export METRICS_EXCLUDED_HANDLERS=" /servers/.*/sse,/static/.*"
59+ ```
6060
61612. Start the gateway (development). By default the app listens on port 4444. The Prometheus endpoint will be:
6262
63- http://localhost:4444/metrics/prometheus
63+ http://localhost:4444/metrics/prometheus
6464
65653. Quick check (get the first lines of exposition text):
6666
67- ```bash
68- curl -sS http://localhost:4444/metrics/prometheus | head -n 20
69- ```
67+ ` ` ` bash
68+ curl -sS http://localhost:4444/metrics/prometheus | head -n 20
69+ ` ` `
7070
71714. If metrics are disabled, the endpoint returns a small JSON 503 response.
7272
@@ -76,10 +76,10 @@ Add the job below to your `prometheus.yml` for local testing:
7676
7777` ` ` yaml
7878scrape_configs:
79- - job_name: 'mcp-gateway'
80- metrics_path: /metrics/prometheus
81- static_configs:
82- - targets: ['localhost:4444']
79+ - job_name: ' mcp-gateway'
80+ metrics_path: /metrics/prometheus
81+ static_configs:
82+ - targets: [' localhost:4444' ]
8383` ` `
8484
8585If Prometheus runs in Docker, adjust the target host accordingly (host networking
@@ -89,32 +89,32 @@ deploying Prometheus in Kubernetes.
8989# ## Grafana and dashboards
9090
9191- Use Grafana to import dashboards for Kubernetes, PostgreSQL and Redis (IDs
92- suggested elsewhere in the repo). For MCP Gateway app metrics, create panels
93- for:
94- - Request rate: `rate(http_requests_total[1m])`
95- - Error rate: `rate(http_requests_total{status=~"5.."}[5m])`
96- - P99 latency: `histogram_quantile(0.99, sum(rate(http_request_duration_seconds_bucket[5m])) by (le))`
92+ suggested elsewhere in the repo). For MCP Gateway app metrics, create panels
93+ for:
94+ - Request rate: ` rate(http_requests_total[1m])`
95+ - Error rate: ` rate(http_requests_total{status=~ " 5.." }[5m])`
96+ - P99 latency: ` histogram_quantile(0.99, sum(rate(http_request_duration_seconds_bucket[5m])) by (le))`
9797
9898# ## Common pitfalls — short guidance
9999
100100- High-cardinality labels
101- - Never add per-request identifiers (user IDs, full URIs, request IDs) as
102- Prometheus labels. They explode the number of time series and can crash
103- Prometheus memory.
104- - Use `METRICS_CUSTOM_LABELS` only for low-cardinality labels (env, region).
101+ - Never add per-request identifiers (user IDs, full URIs, request IDs) as
102+ Prometheus labels. They explode the number of time series and can crash
103+ Prometheus memory.
104+ - Use ` METRICS_CUSTOM_LABELS` only for low-cardinality labels (env, region).
105105
106106- Compression (gzip) vs CPU
107- - The metrics exposer in `mcpgateway.services.metrics` enables gzip by
108- default for the `/metrics/prometheus` endpoint. Compressing the payload
109- reduces network usage but increases CPU on scrape time. On CPU-constrained
110- nodes consider increasing scrape interval (e.g. 15s→30s) or disabling gzip
111- at the instrumentor layer.
107+ - The metrics exposer in ` mcpgateway.services.metrics` enables gzip by
108+ default for the ` /metrics/prometheus` endpoint. Compressing the payload
109+ reduces network usage but increases CPU on scrape time. On CPU-constrained
110+ nodes consider increasing scrape interval (e.g. 15s→30s) or disabling gzip
111+ at the instrumentor layer.
112112
113113- Duplicate collectors during reloads/tests
114- - Instrumentation registers collectors on the global Prometheus registry.
115- When reloading the app in the same process (tests, interactive sessions)
116- you may see "collector already registered"; restart the process or clear
117- the registry in test fixtures.
114+ - Instrumentation registers collectors on the global Prometheus registry.
115+ When reloading the app in the same process (tests, interactive sessions)
116+ you may see " collector already registered" ; restart the process or clear
117+ the registry in test fixtures.
118118
119119# ## Quick checklist
120120
@@ -127,9 +127,9 @@ deploying Prometheus in Kubernetes.
127127# # Where to look in the code
128128
129129- ` mcpgateway/main.py` — wiring: imports and calls ` setup_metrics(app)` from
130- `mcpgateway.services.metrics`. The function call instruments the app at
131- startup; the actual HTTP handler for `/metrics/prometheus` is registered by
132- the `Instrumentator` inside `mcpgateway/services/metrics.py`.
130+ ` mcpgateway.services.metrics` . The function call instruments the app at
131+ startup; the actual HTTP handler for ` /metrics/prometheus` is registered by
132+ the ` Instrumentator` inside ` mcpgateway/services/metrics.py` .
133133- ` mcpgateway/services/metrics.py` — instrumentation implementation and env-vars.
134134- ` mcpgateway/config.py` — settings defaults and names used by the app.
135135
0 commit comments