Skip to main content
Ant Media Server provides comprehensive monitoring capabilities to track system resources, streaming metrics, and overall health. This guide covers monitoring tools, metrics collection, and best practices.

System Resource Monitoring

REST API Endpoints

Access system resource information through the REST API:

Key Metrics Available

The system resource endpoint provides detailed metrics: CPU Metrics
  • System CPU load percentage
  • Process CPU load percentage
  • Process CPU time
  • System load average (last minute)
Memory Metrics
  • JVM memory (max, total, free, in-use)
  • System memory (total, free, in-use)
  • Native memory usage
  • Swap space (total, free, in-use)
  • Available memory
Storage Metrics
  • Total disk space
  • Free disk space
  • Usable disk space
  • In-use disk space
GPU Metrics (if available)
  • GPU utilization percentage
  • GPU memory utilization
  • GPU memory total/free/used
  • Encoder/decoder utilization
  • Device name and index
Thread Metrics
  • Thread count
  • Peak thread count
  • Dead-locked threads
  • Thread dumps with detailed state
Streaming Metrics
  • Total live streams
  • Local WebRTC live streams
  • Local WebRTC viewers
  • Local HLS viewers
  • Local DASH viewers
  • Database average query time

Monitoring Configuration

Configure monitoring settings in conf/red5.properties:

Resource Limits

Ant Media Server monitors resource usage and can reject new streams when limits are exceeded:

CPU Limits

The server calculates average CPU load over a configurable window:
  • Default CPU limit: 75%
  • Configurable range: 10% - 100%
  • Measurement: Rolling average over last 5 measurements (default)

Memory Limits

Memory monitoring uses different strategies based on OS: Linux Systems
  • Uses memory percentage limit (default: 75%)
  • Monitors available system memory
Other Systems
  • Uses minimum free RAM size (default: 50MB)
  • Checks absolute free memory amount

Checking Resource Availability

The StatsCollector provides the enoughResource() method to check if the server can accept new streams (src/main/java/io/antmedia/statistic/StatsCollector.java:911):

Kafka Integration

Stream metrics to Kafka for external monitoring and analytics:

Configure Kafka Brokers

Available Kafka Topics

ams-instance-stats
  • System resource metrics
  • Published every 15 seconds (default)
  • Contains all system metrics in JSON format
ams-webrtc-stats
  • WebRTC client statistics
  • Per-stream and per-client metrics
  • Measured bitrate, send bitrate
  • Audio/video frame send periods
  • Packet counts

Example Kafka Consumer

GPU Monitoring

For systems with NVIDIA GPUs, Ant Media Server provides detailed GPU metrics:

GPU Metrics Available

Check GPU Status

WebRTC Client Statistics

Monitor individual WebRTC client performance:

Client Metrics

  • measuredBitrate: Actual measured bitrate
  • sendBitrate: Target send bitrate
  • videoFrameSendPeriod: Video frame transmission rate
  • audioFrameSendPeriod: Audio frame transmission rate
  • videoPacketCount: Total video packets sent
  • audioPacketCount: Total audio packets sent
  • clientId: Unique client identifier
  • clientInfo: User agent or client information
  • clientIp: Client IP address

Access Client Stats

Thread Monitoring

Monitor thread health and detect deadlocks:

Thread Metrics

Thread information includes:
  • Thread count and peak count
  • Dead-locked thread IDs
  • Thread state (RUNNABLE, WAITING, etc.)
  • Blocked time and count
  • CPU time per thread
  • Lock information

Vertx Worker Queue Monitoring

Monitor Vertx worker thread queues to detect processing bottlenecks:
  • vertx-worker-thread-queue-size: Main Vertx worker queue
  • webrtc-vertx-worker-thread-queue-size: WebRTC Vertx worker queue
High queue sizes indicate processing delays.

Webhooks for Monitoring

Configure webhooks to receive notifications for critical events:

Webhook Events

High Resource Usage
  • Triggered when CPU or memory exceeds limits
  • Includes full resource information
  • Action: highResourceUsage
Unexpected Server Shutdown
  • Detected on server restart
  • Lists applications that didn’t shutdown properly
  • Action: unexpectedServerShutdown

Webhook Payload Example

Log-based Monitoring

System Resource Logs

Ant Media Server logs resource metrics every 5 minutes (src/main/java/io/antmedia/statistic/StatsCollector.java:360):

Log Levels

Configure logging in conf/red5.properties:

Best Practices

  1. Set Appropriate Limits: Configure CPU and memory limits based on your server capacity
  2. Enable Kafka: Stream metrics to Kafka for long-term storage and analysis
  3. Configure Webhooks: Set up webhook notifications for critical events
  4. Monitor Queue Sizes: Watch Vertx worker queue sizes for performance bottlenecks
  5. Track GPU Usage: Monitor GPU utilization when using hardware encoding
  6. Review Logs Regularly: Check logs for resource warnings and errors
  7. Database Performance: Monitor database query times for performance issues
  8. Client Statistics: Track WebRTC client stats to identify network issues

Health Check Endpoint

Implement health checks using the server time endpoint:

Monitoring Dashboard Integration

Integrate with popular monitoring tools:

Prometheus

Export metrics from Kafka or REST API to Prometheus format.

Grafana

Create dashboards using:
  • Kafka data source
  • REST API queries via JSON API plugin
  • Custom exporters

ELK Stack

Stream Kafka topics to Elasticsearch:
  • Use Logstash Kafka input plugin
  • Create Kibana dashboards
  • Set up alerts based on thresholds