Prometheus Metrics
The backend can expose its metrics in the Prometheus format, so you can scrape it with Prometheus (or Grafana Agent, the OpenTelemetry Collector, Datadog, New Relic and other Prometheus-compatible agents), build dashboards, and alert on gateway traffic, latency and errors.
The metrics cover the API gateway, the AI Gateway, workflows, the MCP servers, the management API, request and audit log writes, the MongoDB and Redis connection pools and the Go runtime. Every Zerq metric is served by this one listener.
Turn it on
Set METRICS_ADDR on the backend. Metrics are served on a separate listener, never on the public gateway port:
| Variable | Default | Description |
|---|---|---|
METRICS_ADDR | (unset, metrics off) | Address of the metrics listener, for example 127.0.0.1:9100, or :9100 on a private network. Serves GET /metrics. |
METRICS_TOKEN | (unset) | When set, scrapes must send Authorization: Bearer <token>. |
METRICS_CLIENT_LABEL | true | Adds a client_id label to zerq_gateway_requests_total. Turn it off if you have a very large number of API clients. |
ZERQ_VERSION | dev | Version reported on zerq_build_info. |
Keep the listener off the public internet: labels include collection names, route templates and client IDs.
Example Prometheus job:
scrape_configs:
- job_name: zerq
authorization:
credentials: <METRICS_TOKEN>
static_configs:
- targets: ['zerq-backend:9100']
Every backend instance keeps its own counters. Scrape every instance and aggregate with sum by (...) in your queries.
Gateway metrics
Labels never contain raw request paths or IDs from the URL. route is the path template of the matched proxy (for example /orders/{id}), also for responses served before the upstream call (cache hits, idempotent replays, 429). Requests that were rejected before a proxy matched (no credentials, unknown path) have route="unmatched", and collection="unknown" when no collection matched either. collection is the collection name.
| Metric | Type | Labels | Description |
|---|---|---|---|
zerq_gateway_requests_total | counter | collection, route, method, code, status_class, client_id | Every gateway response, including 401, 429, cache hits and idempotent replays. client_id is the client verified by authentication, or unauthenticated (a claimed X-Client-ID on a rejected request never becomes a label). |
zerq_gateway_request_duration_seconds | histogram | collection, route, method, status_class | End-to-end latency inside the gateway (authentication, policies, cache and the upstream call). |
zerq_gateway_upstream_duration_seconds | histogram | collection, route, outcome | Time waiting for the upstream service's response headers. outcome is ok when the upstream answered (any status) and error when it could not be reached or credentials could not be applied. |
zerq_gateway_overhead_seconds | histogram | collection, route | Time the gateway added to each request that called the upstream (end-to-end minus upstream time): authentication, policies, transformations, logging. |
zerq_gateway_requests_in_flight | gauge | Requests currently being processed. | |
zerq_gateway_cache_requests_total | counter | collection, result | Response-cache lookups (hit or miss) when GATEWAY_ENABLE_CACHE is on. |
zerq_gateway_request_size_bytes | histogram | collection | Request body size. |
zerq_gateway_response_size_bytes | histogram | collection | Response body size. Streamed (SSE) responses are not measured. |
method is one of GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS or OTHER.
Management API metrics
| Metric | Type | Labels | Description |
|---|---|---|---|
zerq_http_requests_total | counter | server, method, route, code | Requests to Zerq's own HTTP APIs. server is management (/api/v1/*: management API, developer portal API and Management MCP), ai_gateway (the AI model API) or mcp_gateway (the MCP gateway). route is the route template, for example /api/v1/proxies/:id. |
zerq_http_request_duration_seconds | histogram | server, method, route | Latency of those requests. |
Logging pipeline
| Metric | Type | Labels | Description |
|---|---|---|---|
zerq_logs_writes_total | counter | log (request or audit), result (ok or error) | Request and audit log writes. Every error is a log entry that was not stored; alert on it. |
zerq_logs_stream_records_total | counter | sink (otlp, splunk, webhook, queue), result (sent, failed, dropped) | Streamed log entries. |
zerq_logs_retention_deleted_total | counter | log (request, audit, ai, workflow_run) | Entries deleted by retention. |
Dependencies and runtime
| Metric | Type | Labels | Description |
|---|---|---|---|
zerq_mongodb_pool_connections | gauge | state (open, in_use) | MongoDB driver pool connections. |
zerq_mongodb_pool_events_total | counter | event (checkout_failed, pool_cleared) | Pool problems: a request could not get a connection, or the pool was cleared after a server error. |
zerq_mongodb_command_duration_seconds | histogram | command, outcome | MongoDB command latency (find, insert, aggregate, ...). |
zerq_redis_pool_connections | gauge | pool, state (total, idle, stale) | Redis/KeyDB pool connections (when CACHE_TYPE=redis). |
zerq_redis_pool_hits_total, zerq_redis_pool_misses_total, zerq_redis_pool_timeouts_total | counter | pool | Redis pool usage; timeouts mean callers waited too long for a connection. |
zerq_build_info | gauge | version, revision, goversion | Always 1; use it to see which version each instance runs. |
zerq_client_info | gauge | client_id, client_name | Always 1, one series per API client (plus unauthenticated). Join it on client_id to show client names instead of IDs. Names are read from the database at most once a minute; a client without a name gets its ID. |
go_*, process_* | Standard Go runtime and process metrics (goroutines, memory, GC, CPU, open file descriptors). |
AI Gateway metrics
Recorded for every AI Gateway request (see AI Gateway Observability).
| Metric | Type | Labels | Description |
|---|---|---|---|
zerq_ai_requests_total | counter | model, provider, client_id, outcome | AI requests. outcome is success, cache_hit or the error type (guardrail_blocked, budget_exceeded, upstream_unavailable, ...); provider is none when no provider was called. |
zerq_ai_tokens_total | counter | model, client_id, type (prompt, completion) | Tokens. |
zerq_ai_cost_usd_total | counter | model, client_id | Estimated cost in US dollars. |
zerq_ai_fallbacks_total | counter | model | Failed provider attempts followed by a fallback. |
zerq_ai_request_duration_seconds | histogram | model | AI request latency, with trace exemplars. |
zerq_ai_provider_attempts_total | counter | provider, result (ok, error) | Every call to a provider, including failed attempts before a fallback and requests no provider served. A provider that is down shows here even though it never serves a request. |
zerq_ai_provider_attempt_duration_seconds | histogram | provider | Duration of each provider call. |
Model API responses rejected before an AI log entry is written (an invalid AI key) are counted in zerq_http_requests_total{server="ai_gateway"}.
Workflow metrics
| Metric | Type | Labels | Description |
|---|---|---|---|
zerq_workflow_runs_total | counter | trigger, result (ok, error) | Workflow runs: gateway workflows (http_trigger), cron, Kafka and IMAP triggers, guardrail workflows and workflow tests. |
zerq_workflow_run_duration_seconds | histogram | trigger | Run duration. |
zerq_workflow_node_duration_seconds | histogram | node_type, result | Time per executed node (HTTP request, database, code, gateway call, ...); the _count with result="error" counts failed nodes. |
zerq_workflow_run_records_total | counter | result (written, error, dropped) | Run history writes. dropped: the write queue was full and the run was not recorded (the run itself is not affected). There is no workflow id label. |
zerq_workflow_async_runs_total | counter | result (started, rejected) | Execute Workflow steps in mode: async. rejected: the server's background pool (32) was full and the step took its error branch. No workflow id label. |
zerq_workflow_error_handler_runs_total | counter | result (succeeded, failed, skipped, dropped) | Error workflow runs. skipped: the error workflow is missing, unpublished or has no suitable trigger; dropped: the queue was full. No workflow id label. |
MCP metrics
| Metric | Type | Labels | Description |
|---|---|---|---|
zerq_mcp_tool_calls_total | counter | server (mcp_gateway, mcp_management), tool, result (ok, error) | MCP tools/call requests. error includes tools that returned an error result, such as an execute_endpoint call that got a 4xx or 5xx from the gateway. |
zerq_mcp_tool_call_duration_seconds | histogram | server, tool | Tool call duration. |
Profiling
Set PPROF_ENABLED=true to also serve the Go profiler (/debug/pprof/) on the METRICS_ADDR listener, behind METRICS_TOKEN when one is set. Use it to investigate CPU, memory or goroutine problems, for example go tool pprof -http=:0 "http://zerq:9100/debug/pprof/heap". Keep it off unless you need it, and never expose the listener publicly.
Exemplars
When tracing is on, zerq_gateway_request_duration_seconds, zerq_gateway_upstream_duration_seconds and zerq_ai_request_duration_seconds carry the trace ID of a sampled request as an exemplar (trace_id). Exemplars are served in the OpenMetrics format, which Prometheus requests automatically when --enable-feature=exemplar-storage is on. In Grafana, turn on Exemplars in a latency panel and click a point to open the trace.
Dashboards and alerts
The observability stack includes Grafana dashboards for these metrics and the Zerq alert rules.
Client names
Metrics label clients by client_id. Every instance exports zerq_client_info, and the recording rule zerq:client_info keeps one name per client across instances. To show names, join a per-client query with it, and keep clients without a name (deleted clients, or data from before the rule was loaded) under their ID:
sum by (client_id) (rate(zerq_ai_cost_usd_total[5m])) * on(client_id) group_left(client_name) zerq:client_info
or on(client_id) label_replace(sum by (client_id) (rate(zerq_ai_cost_usd_total[5m])), "client_name", "$1", "client_id", "(.+)")
Name history starts when the backend that exports zerq_client_info is deployed, so older data on a dashboard shows client IDs.
Example queries
# Requests per second by collection
sum by (collection) (rate(zerq_gateway_requests_total[5m]))
# Error ratio (5xx) per route
sum by (collection, route) (rate(zerq_gateway_requests_total{status_class="5xx"}[5m]))
/ sum by (collection, route) (rate(zerq_gateway_requests_total[5m]))
# p95 latency per route
histogram_quantile(0.95, sum by (le, collection, route) (rate(zerq_gateway_request_duration_seconds_bucket[5m])))
# Gateway overhead (p95 of the time added to upstream calls)
histogram_quantile(0.95, sum by (le) (rate(zerq_gateway_overhead_seconds_bucket[5m])))
# Auth and throttling pressure
sum by (code) (rate(zerq_gateway_requests_total{code=~"401|403|429"}[5m]))
# Lost log entries
sum by (log) (increase(zerq_logs_writes_total{result="error"}[15m]))
# AI cost per client over the last day
sum by (client_id) (increase(zerq_ai_cost_usd_total[1d]))
# Share of failed workflow runs per trigger
sum by (trigger) (rate(zerq_workflow_runs_total{result="error"}[10m])) / sum by (trigger) (rate(zerq_workflow_runs_total[10m]))