Monitor Performance

Track query performance and identify bottlenecks in your CQL application.

Prerequisites

  • Working CQL application

  • Log or metrics infrastructure

Enable Query Logging

Log all queries with execution time:

MyDB.on_query do |sql, duration|
  Log.info { "[CQL] (#{duration.total_milliseconds.round(2)}ms) #{sql}" }
end

Log Slow Queries

Only log queries exceeding a threshold:

SLOW_QUERY_THRESHOLD = 100.milliseconds

MyDB.on_query do |sql, duration|
  if duration > SLOW_QUERY_THRESHOLD
    Log.warn { "[SLOW QUERY] (#{duration.total_milliseconds.round(2)}ms) #{sql}" }
  end
end

Track Query Metrics

Collect metrics for monitoring systems:

Per-Request Tracking

Track queries per HTTP request:

Query Analysis

Analyze query patterns:

Database Statistics

Query database statistics directly:

Connection Pool Monitoring

Monitor pool usage:

Export to Prometheus

Verify Setup

Test your monitoring:

See Also

Last updated

Was this helpful?