Skip to content

[Feat.] Enable grafana to show metrics #4718

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Apr 21, 2025
Merged
76 changes: 76 additions & 0 deletions examples/monitoring/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# SGLang Monitoring Setup

This directory contains a ready-to-use monitoring setup for SGLang using Prometheus and Grafana.

## Prerequisites

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

## Usage

1. Start your SGLang server with metrics enabled:

```bash
sglang server --enable-metrics
```

By default, the metrics server will run on `127.0.0.1:30001`.

2. Start the monitoring stack:

```bash
cd examples/monitoring
docker compose up -d
```

3. Access the monitoring interfaces:
- Grafana: [http://localhost:3000](http://localhost:3000)
- Prometheus: [http://localhost:9090](http://localhost:9090)

Default Grafana login credentials:
- Username: `admin`
- Password: `admin`

You'll be prompted to change the password on first login.

4. The SGLang dashboard will be automatically available in the "SGLang Monitoring" folder.

## Troubleshooting

### Port Conflicts
If you see errors like "port is already allocated":

1. Check if you already have Prometheus or Grafana running:
```bash
docker ps | grep -E 'prometheus|grafana'
```

2. Stop any conflicting containers:
```bash
docker stop <container_id>
```

3. Ensure no other services are using ports 9090 and 3000:
```bash
lsof -i :9090
lsof -i :3000
```

### Connection Issues
If Grafana cannot connect to Prometheus:
1. Check that both services are running
2. Verify the datasource configuration in Grafana
3. Check that your SGLang server is properly exposing metrics

## Configuration

- Prometheus configuration: `prometheus.yaml`
- Docker Compose configuration: `docker-compose.yaml`
- Grafana datasource: `grafana/datasources/datasource.yaml`
- Grafana dashboard configuration: `grafana/dashboards/config/dashboard.yaml`
- SGLang dashboard JSON: `grafana/dashboards/json/sglang-dashboard.json`

## Customization

You can customize the monitoring setup by modifying the configuration files as needed.
16 changes: 11 additions & 5 deletions examples/monitoring/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
version: '3'
services:
prometheus:
image: prom/prometheus:latest
container_name: prometheus
network_mode: host
ports:
- "9090:9090"
volumes:
- ${PWD}/prometheus.yaml:/etc/prometheus/prometheus.yml
- ./prometheus.yaml:/etc/prometheus/prometheus.yml
command:
- '--config.file=/etc/prometheus/prometheus.yml'
- '--storage.tsdb.path=/prometheus'

grafana:
image: grafana/grafana:latest
container_name: grafana
network_mode: host
volumes:
- ./grafana/datasources:/etc/grafana/provisioning/datasources
- ./grafana/dashboards/config:/etc/grafana/provisioning/dashboards
- ./grafana/dashboards/json:/var/lib/grafana/dashboards
depends_on:
- prometheus
ports:
- "3000:3000"
11 changes: 11 additions & 0 deletions examples/monitoring/grafana/dashboards/config/dashboard.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: 1
providers:
- name: 'SGLang'
orgId: 1
folder: 'SGLang Monitoring'
type: file
disableDeletion: false
updateIntervalSeconds: 10
allowUiUpdates: false
options:
path: /var/lib/grafana/dashboards
Loading