In a self hosted setting, how do we know how many ...
# ask-ai
m
In a self hosted setting, how do we know how many rooms will get created in livekit media server?
✅ 1
t
Thanks for reaching out, Varun. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — I’m replying about how to know how many rooms will be created (and how to monitor current rooms) in a self‑hosted LiveKit deployment. You can determine and track rooms using any of these methods: • Use the Room service API (
listRooms()
/
room.list_rooms()
) to get all active rooms and read the count. This works from LiveKit server SDKs (Node/Python). ◦ Example (Node):
Copy code
const roomService = new RoomServiceClient(url, apiKey, apiSecret);
    const rooms = await roomService.listRooms();
    console.log(`Number of rooms: ${rooms.rooms.length}`);
• Example (Python):
Copy code
from livekit import api
    lkapi = api.LiveKitAPI(url, api_key, api_secret)
    rooms = await lkapi.room.list_rooms()
    print(len(rooms.items))
• Use Prometheus metrics the server exposes. LiveKit emits room lifecycle metrics you can scrape and visualize to track total/active rooms and trends over time. • Use webhooks for
room_started
and
room_finished
events to get real‑time notifications and maintain your own count/history. Notes: • Rooms are created dynamically when the first participant joins and are removed based on your server’s timeout configuration (e.g.,
empty_timeout
), so counts are runtime values, not pre-provisioned. • If you want, tell me which SDK/language you’re using or whether you prefer metrics or webhooks, and I’ll give exact code or Prometheus metric names you can use., with interactive elements
m
How do I use the prometheus metrics?
t
You're asking how to use Prometheus metrics to monitor LiveKit rooms — I’ll cover enabling metrics, scraping with Prometheus, useful metric names/queries, and next steps. Which environment are you running (Kubernetes with Helm, Docker Compose, or a single binary)? That helps me give exact commands and scrape configs. High-level steps 1. Enable LiveKit metrics ◦ LiveKit exposes Prometheus metrics from its telemetry endpoint by default when telemetry is enabled. Ensure telemetry/metrics are enabled in your LiveKit config. 1. Configure Prometheus to scrape LiveKit ◦ Add a scrape job pointing at your LiveKit instance(s)
/metrics
endpoint. ◦ Example job (replace host/port):
Copy code
- job_name: 'livekit'
       static_configs:
         - targets: ['livekit-host:7979']
1. Useful metrics to monitor ◦ LiveKit exports operational, room, and participant metrics. Specific names may vary, but typical useful metrics are: ▪︎ room lifecycle counters (total rooms created / finished) ▪︎ current active rooms (gauge) ▪︎ participant counts per room (gauge) ▪︎ session durations (histogram/summary) ▪︎ data/packet/bitrate metrics for tracks ◦ If you do not see a specific room metric, use webhook events (
room_started
/
room_finished
) to increment a custom Prometheus counter in your service. 1. Example PromQL queries ◦ Current active rooms (if gauge exists):
sum(livekit_rooms_active)
◦ Total rooms created (counter):
increase(livekit_rooms_created_total[1h])
◦ Participants across all rooms:
sum(livekit_participants_connected)
◦ Average session duration:
histogram_quantile(0.95, sum(rate(livekit_session_duration_seconds_bucket[5m])) by (le))
1. If metric names are missing ◦ Create and export custom metrics in a small service that receives LiveKit webhooks (
room_started
,
room_finished
) and exposes Prometheus counters/gauges. See Creating and Publishing Custom Metrics: Creating and Publishing Custom Metrics Next step Tell me which environment you use (K8s/Helm, Docker Compose, or binary) and whether you want example Prometheus scrape config, Grafana dashboard queries, or a webhook-to-metrics snippet — I’ll provide exact configs/code. Sources: Creating and Publishing Custom Metrics, with interactive elements
m
We are facing the following error:
Copy code
TwirpError(code=unknown, message=twirp error unknown: update room failed: could not connect after timeout, status=500)
t
Thanks — I’m responding about the TwirpError:
update room failed: could not connect after timeout, status=500
. To help diagnose and fix this, please share: • Which SDK/language and LiveKit server version you’re using. • Deployment type (Kubernetes/Helm, Docker Compose, single binary, or LiveKit Cloud). • When this happens: on room create, update, or when a participant joins? Repro steps. • Recent changes (config, network, scaling) before the error started. • Any relevant server logs around the error (LiveKit server and any gateway/proxy) and the client SDK logs. Meanwhile try these checks: • Verify network connectivity from the component calling LiveKit’s Room service to the LiveKit server (curl/telnet to the Twirp endpoint). • Check LiveKit server logs for the same timestamp — look for connection timeouts, RPC errors, or resource saturation (CPU/memory). • If behind a proxy/load balancer, confirm idle/timeouts and max connections aren’t closing Twirp calls prematurely. • Ensure API key/secret and TLS settings are correct for the Room service client. • Restart the LiveKit process that handles room updates to rule out transient state. • If using multiple LiveKit nodes, confirm the caller is reaching the correct node or a healthy gateway (sticky routing if required). If you can paste the SDK call code (redact secrets), a short server log excerpt around the error, and your deployment type, I’ll provide targeted next steps and commands to run. , with interactive elements