-
Notifications
You must be signed in to change notification settings - Fork 0
Slow Query Monitoring
MySQLGenius captures slow SELECT queries in real time using ActiveSupport notifications and stores them in Redis.
MysqlGenius.configure do |config|
config.redis_url = ENV["REDIS_URL"] || "redis://127.0.0.1:6379/0"
config.slow_query_threshold_ms = 250 # default: 250ms
endMySQLGenius subscribes to sql.active_record notifications automatically when redis_url is configured. Any SELECT query exceeding the threshold is captured.
For each slow query:
- SQL text (first 2,000 characters)
- Duration in milliseconds
- Timestamp
- Non-SELECT queries (INSERT, UPDATE, DELETE, etc.)
- EXPLAIN queries
- SCHEMA queries (migrations, schema lookups)
The Slow Queries tab shows the most recent 200 captured queries, sorted by most recent first. Each entry shows:
- Duration badge (color-coded: blue < 1s, yellow 1-2s, red > 2s)
- Timestamp
- SQL with syntax highlighting
- Explain button to see the execution plan
- Use button to copy the SQL into the Query Explorer
The Dashboard tab shows the top 5 slowest queries from the captured list, linking directly to the Slow Queries tab for details.
Slow queries are stored in a Redis list under the key mysql_genius:slow_queries. The list is capped at 200 entries (oldest are trimmed automatically).
Set redis_url to nil to disable slow query monitoring entirely. The Slow Queries tab will show an empty state.
The notification subscriber is lightweight -- it only fires for queries that exceed the threshold and performs a single Redis LPUSH + LTRIM. There is no measurable impact on application performance.
< Dark Theme | Home >