How can I use prometheus to record and log usage m...
# ask-ai
i
How can I use prometheus to record and log usage metrics?
t
Thanks for reaching out, Matthew. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
To get you started with using Prometheus for recording and logging usage metrics in LiveKit, here’s a simple step-by-step guide: 1. Enable Prometheus Metrics: First, in your LiveKit server configuration YAML file, set the
prometheus_port
(for example, 6789). This will make the metrics available at the
/metrics
endpoint. 2. Configure Prometheus: Next, add a scrape job in your Prometheus configuration to point to the LiveKit server’s
/metrics
endpoint. Here’s an example you can use:
Copy code
scrape_configs:
  - job_name: 'livekit'
    static_configs:
      - targets: ['<livekit-server-ip>:6789']
3. Monitor Metrics: Some important metrics to watch are room and participant counts, track stats, network performance, and system health. For instance,
livekit_room_total
shows active rooms, and
livekit_packet_loss_percent
helps you keep an eye on packet loss. 4. Visualize Data: Grafana is a great tool to create dashboards for metrics like room counts, network throughput, and overall system performance. Using PromQL queries, you can dig into specific insights that matter to you. 5. Optional AI Usage Tracking: If you’re interested in AI-related metrics, you can use the
UsageCollector
class to gather data like LLM tokens or TTS characters. This info can be logged or exported manually as needed. If you have any questions or want a hand with any of these steps, just let me know—I’m here to help! Sources: Docs::Home | pkg/telemetry/prometheus/quality.go | webhook/stats.go | Logs, metrics, and telemetry | LiveKit Docs | agents/src/metrics/usage_collector.ts
I'd love to help you get started with using Prometheus to record and log usage metrics in LiveKit! Here’s a simple step-by-step guide to make things easier: 1. Enable Prometheus Metrics: First, in your LiveKit server configuration YAML file, you’ll want to set the
prometheus_port
(for example, 6789). This will make the metrics available at the
/metrics
endpoint. 2. Configure Prometheus: Next, add a scrape job in your Prometheus server configuration to point to the LiveKit server’s
/metrics
endpoint. Here’s an example configuration to guide you:
Copy code
scrape_configs:
  - job_name: 'livekit'
    static_configs:
      - targets: ['<livekit-server-ip>:6789']
3. Monitor Metrics: Some important metrics to keep an eye on include room and participant counts, track statistics, network performance, and system health. For instance,
livekit_room_total
shows active rooms, and
livekit_packet_loss_percent
helps you monitor packet loss. 4. Visualize Data: To make the data easier to understand, you can use Grafana to build dashboards for things like room counts, network throughput, and overall system performance. You can query these metrics directly with PromQL. 5. Optional AI Agent Metrics: If you’re interested in session-specific details like LLM tokens or TTS characters, the
UsageCollector
class is a handy tool to aggregate those metrics. You can log or export this data manually as needed. With this setup, you’ll have a thorough way to monitor LiveKit’s real-time usage and performance. If you have any questions or need further help, feel free to ask—I’m here to support you!