[Observability] Add Prometheus metrics endpoint for gRPC mode#20801
Merged
Kangyan-Zhou merged 3 commits intosgl-project:mainfrom Apr 10, 2026
Merged
[Observability] Add Prometheus metrics endpoint for gRPC mode#20801Kangyan-Zhou merged 3 commits intosgl-project:mainfrom
Kangyan-Zhou merged 3 commits intosgl-project:mainfrom
Conversation
Contributor
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
836e3c5 to
518d053
Compare
When --enable-metrics is set, start a lightweight aiohttp HTTP server on gRPC port + 1 to expose /metrics in standard Prometheus format. This is the standard pattern for gRPC services that need to serve Prometheus metrics on a separate HTTP port. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Switch from prometheus_client.generate_latest() (Prometheus exposition format) to prometheus_client.openmetrics.exposition.generate_latest() (OpenMetrics format). OpenMetrics converts colons to underscores in metric names (e.g. sglang:prompt_tokens_total → sglang_prompt_tokens_total), matching the output of make_asgi_app() used in HTTP mode. This ensures Grafana dashboards work consistently across HTTP and gRPC serving modes. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ling - Add configurable --metrics-http-port (default: --port + 1) instead of hardcoded port offset - Wrap entire metrics init in try/except so failures never crash gRPC server - Fix AppRunner resource leak if site.start() fails - Fix port defaulting to use `is not None` check (port 0 is valid) - Fix inaccurate comments about make_asgi_app and OpenMetrics format Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
518d053 to
eaf2187
Compare
Contributor
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
slin1237
approved these changes
Apr 9, 2026
Collaborator
Author
|
/tag-and-rerun-ci |
Fridge003
pushed a commit
that referenced
this pull request
Apr 11, 2026
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
pyc96
pushed a commit
to pyc96/sglang
that referenced
this pull request
Apr 14, 2026
…oject#20801) Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
yhyang201
pushed a commit
to yhyang201/sglang
that referenced
this pull request
Apr 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
--enable-metricsis set in gRPC mode, starts a lightweight aiohttp HTTP server to expose Prometheus/metricsendpoint--metrics-http-portarg to configure the metrics port (defaults to--port + 1)Changes
python/sglang/srt/entrypoints/grpc_server.py— new_start_metrics_server()and metrics lifecycle inserve_grpc()python/sglang/srt/server_args.py— newmetrics_http_port: Optional[int]field and--metrics-http-portCLI argTest plan
--enable-metricsand verify/metricsis accessible onport+1# EOFterminator--metrics-http-port 9090to verify custom port works--enable-metrics— no metrics server should start🤖 Generated with Claude Code