Skip to main content
Installation

Monitoring and tracing

The gateway's health check, Prometheus metrics and the scrape token, the metric list and common queries, the Grafana dashboard, and OpenTelemetry tracing settings.

The gateway exposes Prometheus metrics and OpenTelemetry traces without extra components. Example configuration is in the package's monitoring/ directory.

Health check

GET /healthz returns ok while the gateway is running. It needs no authentication and suits load balancers and process monitors.

Prometheus metrics

Scrape http://<gateway>:8080/metrics with the header Authorization: Bearer <RST_FABRIC_METRICS_TOKEN>. install.sh generates the token and writes it to .env.

Without RST_FABRIC_METRICS_TOKEN, /metrics accepts only direct requests from the gateway host; requests through a reverse proxy or from other machines are refused. The metrics include model names, project IDs, upstream addresses and call volumes, so always set a token for remote scraping and keep it in a file Prometheus can read. If the token leaks, change it in .env and run docker compose up -d.

scrape_configs:
  - job_name: rst-ai-fabric
    static_configs: [{ targets: ["10.0.0.10:8080"] }]
    authorization:
      type: Bearer
      credentials_file: /etc/prometheus/secrets/rst-fabric-metrics-token

The full example is monitoring/prometheus/prometheus.yml. Example alert rules in monitoring/prometheus/alerts.yml cover scrape failures, a high 5xx ratio, rejections from full models, upstreams ejected or all down, p95 latency, p95 time to first token, queue backlog, KV cache saturation, an invalid licence and dropped trace spans. Adjust the thresholds to your models and check the file with promtool check rules alerts.yml.

Metrics

All label values are bounded: model takes only model names configured in the console (requests for unknown models count as unknown); endpoint is chat, completions, embeddings, rerank, score or messages; status is 2xx, 4xx, 429 or 5xx; upstream is the upstream's host:port. Metrics never carry API keys or client IPs.

MetricTypeLabelsDescription
fabric_requests_totalcountermodel, endpoint, project, statusRequests
fabric_errors_totalcountermodel, endpoint, codeFailed requests by error code
fabric_tokens_totalcountermodel, typeTokens; type is prompt or completion
fabric_cost_totalcountermodelBilled amount (CNY)
fabric_pii_masked_totalcounterdirection, kindMasked personal information; direction is input or output, kind is phone, id_card, bank_card or email
fabric_pii_blocked_totalcounterRequests blocked for personal information
fabric_request_duration_secondshistogrammodel, endpoint, statusEnd-to-end time; streams are timed to the last chunk
fabric_ttft_secondshistogrammodel, endpointStreaming time to first token
fabric_queue_secondshistogrammodel, endpointTime spent waiting for a model concurrency slot
fabric_upstream_request_duration_secondshistogramupstream, statusTime per upstream call
fabric_upstream_attempts_totalcounterupstreamUpstream calls, including retries
fabric_upstream_failures_totalcounterupstream, reasonFailed upstream calls; reason is transport, http_429 or http_5xx
fabric_inflight_requestsgaugemodelRequests in progress per model
fabric_model_queue_depthgaugemodelRequests waiting for a slot
fabric_upstream_upgaugemodel, upstream1 when the upstream is healthy, 0 when ejected
fabric_upstream_inflightgaugemodel, upstreamRequests in progress per upstream
fabric_engine_running, fabric_engine_waitinggaugemodel, upstreamvLLM running and waiting requests
fabric_engine_kv_cache_usage_ratiogaugemodel, upstreamvLLM KV cache usage, 0 to 1
fabric_license_validgauge1 while the licence is usable
fabric_build_infogaugeversion, goversionBuild information, always 1

Go runtime metrics (go_*), process metrics (process_*) and, with tracing on, export statistics (fabric_trace_*) are also exposed.

Common queries:

# p95 latency per model (successful requests)
histogram_quantile(0.95, sum by (le, model) (rate(fabric_request_duration_seconds_bucket{status="2xx"}[5m])))
# 5xx ratio
sum(rate(fabric_requests_total{status="5xx"}[5m])) / sum(rate(fabric_requests_total[5m]))
# Failure rate by error code
sum by (code) (rate(fabric_errors_total[5m]))

Grafana

In Grafana, choose Dashboards > New > Import, upload monitoring/grafana/rst-ai-fabric.json and pick the Prometheus data source that scrapes the gateway. Panels cover request rate, 5xx ratio, p50 / p95 / p99 latency, time to first token, queue time and depth, failures by error code, upstream health and timing, vLLM running requests and KV cache, tokens and hourly cost, runtime and process. Filter by job and model at the top.

OpenTelemetry tracing

Setting an OTLP endpoint turns tracing on; without one it is fully off. The gateway supports OTLP/HTTP JSON only, usually on port 4318.

Each request produces a SERVER span (named like POST /v1/chat/completions) with HTTP attributes, GenAI semantic convention attributes (requested model, model actually served, input and output tokens and so on) and fabric.request_id, which matches the X-Request-Id response header. Queue waiting and each upstream call get child spans. Spans never contain API keys, prompts, model output or upstream error text.

The gateway accepts traceparent and tracestate from clients as the parent span and injects traceparent towards upstreams, so inference servers with OpenTelemetry support join the same trace. With tracing on, request-related gateway log lines carry trace_id and span_id.

SettingDefaultDescription
OTEL_EXPORTER_OTLP_ENDPOINTEmpty (off)The collector's OTLP/HTTP base URL; the gateway appends /v1/traces. For example http://otel-collector:4318
OTEL_EXPORTER_OTLP_TRACES_ENDPOINTEmptyFull traces URL, used as is; takes precedence over the above
OTEL_EXPORTER_OTLP_HEADERSEmptyHeaders such as authentication, k1=v1,k2=v2, values URL-encoded, for example Authorization=Bearer%20xxx
OTEL_SERVICE_NAMErst-ai-fabricservice.name
OTEL_RESOURCE_ATTRIBUTESEmptyExtra resource attributes, for example deployment.environment=prod
OTEL_TRACES_SAMPLERparentbased_always_onalways_on, always_off, traceidratio, parentbased_always_on, parentbased_always_off, parentbased_traceidratio
OTEL_TRACES_SAMPLER_ARG1.0Sampling ratio for *traceidratio, 0 to 1

Set them in .env and run docker compose up -d. Example with 10% sampling in production:

OTEL_EXPORTER_OTLP_ENDPOINT=http://otel-collector:4318
OTEL_TRACES_SAMPLER=parentbased_traceidratio
OTEL_TRACES_SAMPLER_ARG=0.1
OTEL_RESOURCE_ATTRIBUTES=deployment.environment=prod

Spans are exported in the background in batches. When the queue is full, new spans are dropped and counted in fabric_trace_spans_dropped_total; requests are never blocked.

On this page