Skip to content

Commit 36d6f0b

Browse files
authored
fix: fix the missing metrics on non-rank0 nodes (#7720)
1 parent 2a1936d commit 36d6f0b

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

python/sglang/srt/entrypoints/engine.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,9 @@ def _launch_subprocesses(
765765
# When using `Engine` as a Python API, we don't want to block here.
766766
return None, None, None
767767

768-
launch_dummy_health_check_server(server_args.host, server_args.port)
768+
launch_dummy_health_check_server(
769+
server_args.host, server_args.port, server_args.enable_metrics
770+
)
769771

770772
for proc in scheduler_procs:
771773
proc.join()

python/sglang/srt/utils.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@
8585
from torch.utils._contextlib import _DecoratorContextManager
8686
from triton.runtime.cache import FileCacheManager
8787

88+
from sglang.srt.metrics.func_timer import enable_func_timer
89+
8890
logger = logging.getLogger(__name__)
8991

9092
show_time_cost = False
@@ -2049,7 +2051,7 @@ def rank0_log(msg: str):
20492051
logger.info(msg)
20502052

20512053

2052-
def launch_dummy_health_check_server(host, port):
2054+
def launch_dummy_health_check_server(host, port, enable_metrics):
20532055
import asyncio
20542056

20552057
import uvicorn
@@ -2067,6 +2069,11 @@ async def health_generate():
20672069
"""Check the health of the http server."""
20682070
return Response(status_code=200)
20692071

2072+
# Add prometheus middleware
2073+
if enable_metrics:
2074+
add_prometheus_middleware(app)
2075+
enable_func_timer()
2076+
20702077
config = uvicorn.Config(
20712078
app,
20722079
host=host,

0 commit comments

Comments
 (0)