> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ultrabalancer.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Monitoring

> Set up Grafana and Prometheus for UltraBalancer

## Quick Setup

```bash theme={null}
# One command to start monitoring
ultrabalancer dashboard --start
```

That's it! This creates:

* Grafana at [http://localhost:3000](http://localhost:3000) (admin + auto-generated password)
* Prometheus at [http://localhost:9090](http://localhost:9090)

## Dashboard Commands

```bash theme={null}
# Start monitoring stack
ultrabalancer dashboard --start

# Check what's running
ultrabalancer dashboard --status

# View logs
ultrabalancer dashboard --logs

# Stop everything
ultrabalancer dashboard --stop

# Full reset (removes all data)
ultrabalancer dashboard --reset
```

## Manual Setup

If you prefer Docker Compose:

```yaml docker-compose.yml theme={null}
version: '3.8'

services:
  prometheus:
    image: prom/prometheus:v2.48.0
    ports:
      - "9090:9090"
    volumes:
      - ./prometheus.yml:/etc/prometheus/prometheus.yml:ro
    command:
      - '--config.file=/etc/prometheus/prometheus.yml'

  grafana:
    image: grafana/grafana:10.2.0
    ports:
      - "3000:3000"
    environment:
      - GF_SECURITY_ADMIN_USER=admin
      - GF_SECURITY_ADMIN_PASSWORD=admin
```

```yaml prometheus.yml theme={null}
scrape_configs:
  - job_name: 'ultrabalancer'
    static_configs:
      - targets: ['localhost:8080']
    metrics_path: /prometheus
```

## Key Metrics

| Metric                                     | Description             |
| ------------------------------------------ | ----------------------- |
| `ultrabalancer_requests_total`             | Total requests          |
| `ultrabalancer_requests_failed`            | Failed requests         |
| `ultrabalancer_response_time_seconds`      | Response time histogram |
| `ultrabalancer_backend_healthy`            | Backend health (1/0)    |
| `ultrabalancer_backend_active_connections` | Connections per backend |

## Common Queries

```promql theme={null}
# Requests per second
rate(ultrabalancer_requests_total[5m])

# Error rate
rate(ultrabalancer_requests_failed[5m]) / rate(ultrabalancer_requests_total[5m])

# p95 latency
histogram_quantile(0.95, rate(ultrabalancer_response_time_seconds_bucket[5m]))

# Healthy backends
sum(ultrabalancer_backend_healthy)
```

## Admin API Metrics

The admin API also provides backend metrics:

```bash theme={null}
curl http://localhost:8080/admin/backends
```

Response:

```json theme={null}
{
  "success": true,
  "message": "Backends listed",
  "data": [
    {
      "address": "10.0.0.1:8080",
      "weight": 100,
      "healthy": true,
      "active_connections": 5,
      "total_requests": 1234
    }
  ]
}
```
