Skip to main content
SGLang exposes the following metrics via Prometheus. You can enable it by adding --enable-metrics when you launch the server. An example of the monitoring dashboard is available in examples/monitoring/grafana.json.

Language model metrics

sglang:time_to_first_token_seconds measures the time from request creation in the API server to the first token. For streaming requests it ends when the first output arrives after detokenization, which may contain no printable text. Non-streaming clients only see the final response, so for them it ends when the scheduler produced the first token. Here is an example of the metrics:
Output

Request-level time per output token (TPOT)

sglang:request_time_per_output_token_seconds records TPOT once per successfully finished request:
The first token is excluded because its latency belongs to TTFT. Requests with fewer than two output tokens, streaming requests that finish in their first output, aborted requests, and PD prefill workers do not contribute. The histogram is split by is_streaming and reuses the --bucket-inter-token-latency buckets. Unlike the token-weighted sglang:inter_token_latency_seconds, this metric gives every qualifying request equal weight. p95 TPOT per model:
Mean TPOT is rate(..._sum[5m]) / rate(..._count[5m]). Per-request decode tokens/s is its reciprocal, so p5 TPS is 1 / p95 TPOT; the reciprocal of mean TPOT is not mean TPS.

Rust frontend metrics

The Rust frontend (sglang-server) exports the frontend metrics above under the same names, plus these families of its own. They carry the same labels as the request metrics (model_name, engine_type, …), plus the one listed. The gauge is summed over processes.

Diffusion metrics

SGLang Diffusion exposes request, queue, stage and LoRA metrics with --enable-metrics. See Diffusion production metrics for the metric reference, counting semantics and disaggregated scraping setup.

Setup Guide

This section describes how to set up the monitoring stack (Prometheus + Grafana) provided in the examples/monitoring directory.

Prerequisites

  • Docker and Docker Compose installed
  • SGLang server running with metrics enabled

Usage

  1. Start your SGLang server with metrics enabled:
    Command
    Replace <your_model_path> with the actual path to your model (e.g., meta-llama/Meta-Llama-3.1-8B-Instruct). The example stack uses host networking, so the default --host 127.0.0.1 is reachable from it. If you bind SGLang to 0.0.0.0 instead, also set --api-key (see Server Arguments). By default, the metrics endpoint will be available at http://<sglang_server_host>:30000/metrics.
  2. Navigate to the monitoring example directory:
    Command
  3. Start the monitoring stack, choosing a Grafana admin password:
    Command
    This starts Prometheus and Grafana in the background. Docker Compose reads the password from .env (excluded by the repository’s .gitignore) for every later command too, such as docker compose ps or docker compose down; exporting GRAFANA_ADMIN_PASSWORD in your shell works as well. Every docker compose command for this stack fails while the variable is unset. Grafana applies the password only when it first creates its database. To change it later, change it in Grafana under your profile, or run docker compose exec grafana grafana cli admin reset-admin-password '<new password>', then update .env. Do not use docker compose down and a restart to change it: the example does not persist Grafana’s database or Prometheus’s data, so that discards dashboards, users and alert rules created in Grafana and Prometheus’s metric history.
  4. Access the monitoring interfaces:
  5. Log in to Grafana: as admin, with the password you set. Grafana and Prometheus listen on 127.0.0.1 only; to view them from another machine, use an SSH tunnel (ssh -L 3000:127.0.0.1:3000 <host>) instead of exposing the ports.
  6. View the Dashboard: The SGLang dashboard is pre-configured and should be available automatically. Navigate to Dashboards -> Browse -> SGLang Monitoring folder -> SGLang Dashboard.

Troubleshooting

  • Port Conflicts: If you encounter errors like “port is already allocated,” check if other services (including previous instances of Prometheus/Grafana) are using ports 9090 or 3000. Use docker ps to find running containers and docker stop <container_id> to stop them, or use lsof -i :<port> to find other processes using the ports. You might need to adjust the ports in the docker-compose.yaml file if they permanently conflict with other essential services on your system. To move Grafana to another port (like 3090), append GF_SERVER_HTTP_PORT to the existing environment list of the grafana service. Both services use host networking, so a ports: mapping has no effect.
  • Connection Issues:
    • Ensure both Prometheus and Grafana containers are running (docker ps).
    • Verify the Prometheus data source configuration in Grafana (usually auto-configured via grafana/datasources/datasource.yaml). Go to Connections -> Data sources -> Prometheus. The URL should point to the Prometheus service (e.g., http://prometheus:9090).
    • Confirm that your SGLang server is running and the metrics endpoint (http://<sglang_server_host>:30000/metrics) is accessible from the Prometheus container. If SGLang is running on your host machine and Prometheus is in Docker, use host.docker.internal (on Docker Desktop) or your machine’s network IP instead of localhost in the prometheus.yaml scrape configuration.
  • No Data on Dashboard:
    • Generate some traffic to your SGLang server to produce metrics. For example, run a benchmark:
      Command
    • Check the Prometheus UI (http://localhost:9090) under Status -> Targets to see if the SGLang endpoint is being scraped successfully.
    • Verify the model_name and instance labels in your Prometheus metrics match the variables used in the Grafana dashboard. You might need to adjust the Grafana dashboard variables or the labels in your Prometheus configuration.

Configuration Files

The monitoring setup is defined by the following files within the examples/monitoring directory:
  • docker-compose.yaml: Defines the Prometheus and Grafana services.
  • prometheus.yaml: Prometheus configuration, including scrape targets.
  • grafana/datasources/datasource.yaml: Configures the Prometheus data source for Grafana.
  • grafana/dashboards/config/dashboard.yaml: Tells Grafana to load dashboards from the specified path.
  • grafana/dashboards/json/sglang-dashboard.json: The actual Grafana dashboard definition in JSON format.
You can customize the setup by modifying these files. For instance, you might need to update the static_configs target in prometheus.yaml if your SGLang server runs on a different host or port.

Check if the metrics are being collected

Run:
Output
to generate some requests. Then you should be able to see the metrics in the Grafana dashboard. SGLang exports the following estimated per-GPU counters that can be used to derive Model FLOPs Utilization (MFU)-related signals:
  • sglang:estimated_flops_per_gpu_total: Estimated floating-point operations.
  • sglang:estimated_read_bytes_per_gpu_total: Estimated bytes read from memory.
  • sglang:estimated_write_bytes_per_gpu_total: Estimated bytes written to memory.
These metrics are available when both --enable-metrics and --enable-mfu-metrics are enabled. These are cumulative counters. Use Prometheus rate(...) to get per-second values.

PromQL examples

Average TFLOPS per GPU:
Average estimated memory bandwidth in GB/s:

Notes

  • These metrics are estimates intended for observability and trend analysis.
  • Estimated memory bytes reflect modeled traffic and are not a direct hardware counter from GPU profilers.