polite-dog-12152
12/11/2025, 2:18 PMtall-airline-16756
12/11/2025, 2:18 PMtall-airline-16756
12/11/2025, 2:18 PMprometheus_port (Ingress/Egress): set prometheus_port in their YAML to expose metrics directly. The agent server itself does not document a built-in prometheus_port, so custom instrumentation is typical.
I can help with whichever path you choose. To give exact steps or example config, please tell me:
1. Which agent implementation/language are you using (Python, Go, Node, etc.)?
2. Are you able to change the agent server code or prefer using a collector/sidecar?
3. Are you self-hosting Prometheus and the agent, or using LiveKit Cloud Agent Insights?
Which option would you like to pursue?
Sources: Self-hosting the Ingress Service | LiveKit docs | Self-hosting the Egress Service | LiveKit docs | Agents (Python) | livekit/livekit_composite | DeepWiki | Observability data hooks | LiveKit docs | Agent insights in LiveKit Cloud | LiveKit docspolite-dog-12152
12/11/2025, 2:19 PMtall-airline-16756
12/11/2025, 2:19 PMimport (
"net/http"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
• Define and register metrics:
var (
agentCalls = prometheus.NewCounterVec(
prometheus.CounterOpts{Name: "agent_calls_total", Help: "Total agent calls"},
[]string{"type"},
)
agentLatency = prometheus.NewHistogram(
prometheus.HistogramOpts{Name: "agent_call_duration_seconds", Help: "Agent call duration seconds"},
)
)
func init() {
prometheus.MustRegister(agentCalls, agentLatency)
}
• Instrument code where agent events occur:
func handleAgentCall(callType string, handler func()) {
timer := prometheus.NewTimer(agentLatency)
defer timer.ObserveDuration()
agentCalls.WithLabelValues(callType).Inc()
handler()
}
• Expose /metrics endpoint:
func main() {
http.Handle("/metrics", promhttp.Handler())
go http.ListenAndServe(":9100", nil) // exposes metrics on :9100/metrics
// start your agent server normally...
select {} // or your server run loop
}
Prometheus scrape config (prometheus.yml)
scrape_configs:
- job_name: 'livekit_agent'
static_configs:
- targets: ['agent-hostname:9100'] # replace with your host:port
2) Alternative — instrument with OpenTelemetry + Collector
• Export metrics from your agent using OpenTelemetry SDK (language of choice) to an OTLP endpoint.
• Run an OpenTelemetry Collector with a Prometheus exporter. Example collector config:
receivers:
otlp:
protocols:
grpc:
http:
exporters:
prometheus:
endpoint: "0.0.0.0:8889"
service:
pipelines:
metrics:
receivers: [otlp]
exporters: [prometheus]
• Prometheus scrape config for the collector:
scrape_configs:
- job_name: 'otel_collector'
static_configs:
- targets: ['collector-host:8889']
Which example do you want expanded?
• A full Go module example and Dockerfile
• Node.js or Python snippet
• OpenTelemetry Collector advanced config (auth, relabeling)polite-dog-12152
12/11/2025, 2:20 PMtall-airline-16756
12/11/2025, 2:20 PMfrom prometheus_client import start_http_server, Counter, Histogram
import time
import random
import threading
# Metrics
agent_calls = Counter('agent_calls_total', 'Total agent calls', ['type'])
agent_latency = Histogram('agent_call_duration_seconds', 'Agent call duration seconds')
def handle_agent_call(call_type):
start = time.time()
agent_calls.labels(type=call_type).inc()
# simulate work
time.sleep(random.random() * 0.5)
agent_latency.observe(time.time() - start)
# Expose /metrics on port 9100
def start_metrics_server(port=9100):
start_http_server(port)
# Example agent loop
def agent_loop():
types = ['llm', 'stt', 'tts', 'vad']
while True:
handle_agent_call(random.choice(types))
time.sleep(1)
if __name__ == '__main__':
start_metrics_server(9100)
t = threading.Thread(target=agent_loop, daemon=True)
t.start()
# keep main thread alive (replace with your agent's run loop)
while True:
time.sleep(10)
3) Prometheus scrape config (prometheus.yml)
scrape_configs:
- job_name: 'livekit_python_agent'
static_configs:
- targets: ['agent-hostname:9100'] # replace with agent host or IP and port
Notes and next steps
• Replace the simulated handler with your actual agent event hooks (increment agent_calls and observe durations where calls occur).
• Add labels relevant to your environment (room_id, region) but keep cardinality low.
• If you prefer OpenTelemetry, export metrics via OTLP to a Collector, then have Prometheus scrape the Collector.
Want a full Dockerfile, systemd unit, or an example showing instrumenting specific LiveKit agent events?