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. Here is an example of the metrics:
Output

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). Ensure the server is accessible from the monitoring stack (you might need --host 0.0.0.0 if running in Docker). 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:
    Command
    This command will start Prometheus and Grafana in the background.
  4. Access the monitoring interfaces:
  5. Log in to Grafana:
    • Default Username: admin
    • Default Password: admin You will be prompted to change the password upon your first login.
  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 modify Grafana’s port to the other one(like 3090) in your Docker Compose file, you need to explicitly specify the port mapping under the grafana service. Option 1: Add GF_SERVER_HTTP_PORT to the environment section:
Option 2: Use port mapping:
  • 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.