Lightweight load balancer for Icecast relays – redirects listeners to the least-loaded relay
1.7K
A lightweight load balancer for Icecast relays. It redirects listeners to the relay with the fewest active connections, distributing the load evenly across all relays.
All configured Icecast relays must serve the same mountpoints. This is typically achieved with an Icecast master-relay setup.
http://balancer.example.com/live/status-json.xsl endpoint of each configured relayUnreachable relays are automatically skipped.
| Environment Variable | Required | Default | Description |
|---|---|---|---|
ICECAST_RELAYS | Yes | - | Comma-separated list of Icecast relay hostnames (without protocol) |
ICECAST_RELAY_SCHEME | No | http | Protocol used to query relay status (http or https) |
CACHE_TTL | No | 60 | Seconds to cache relay listener counts (0 to disable) |
PORT | No | 8080 | Port the balancer listens on |
docker run -d \
-p 8080:8080 \
-e ICECAST_RELAYS='relay1.example.com,relay2.example.com' \
unclesamwk/icecast-balancer:latest
services:
icecast-balancer:
build: .
image: unclesamwk/icecast-balancer:latest
ports:
- 8080:8080
environment:
ICECAST_RELAYS: relay1.example.com,relay2.example.com
docker compose up -d
GET /statusReturns the current listener count for each reachable relay, sorted ascending.
curl http://localhost:8080/status
{
"relay2.example.com": 15,
"relay1.example.com": 55
}
GET /<mountpoint>Redirects to the least-loaded relay for the given mountpoint.
curl -v http://localhost:8080/live
# < HTTP/1.1 307 Temporary Redirect
# < location: http://relay2.example.com/live
The balancer supports running behind a reverse proxy (e.g. Traefik, nginx). It respects the X-Forwarded-Proto header to generate correct redirect URLs with HTTPS.
pip install -r requirements.txt
ICECAST_RELAYS='relay1.example.com,relay2.example.com' uvicorn app.main:app --reload --port 8080
icecast-balancer/
├── app/
│ ├── __init__.py
│ └── main.py
├── Dockerfile
├── docker-compose.yml
├── Pipfile
├── requirements.txt
└── README.md
Pull requests are welcome.
Content type
Image
Digest
Size
22.5 MB
Last updated
over 6 years ago
docker pull unclesamwk/icecast-balancer