百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
S

sql_tracker

> 后端框架
开源

Rails SQL 查询跟踪器

176 stars0 点赞2 次浏览
访问官网GitHub

工具介绍

Rails SQL 查询跟踪器

Rails SQL Query Tracker

sql_tracker tracks SQL queries by subscribing to Rails' sql.active_record event notifications.

It then aggregates and generates report to give you insights about all the sql queries happened in your Rails application.

Installation

Add this line to your application's Gemfile:

ruby
group :development, :test do
  ... ...
  gem 'sql_tracker'
end

And then execute:

$ bundle

Tracking

To start tracking, simply start your rails application server. When your server is shutting down, sql_tracker will dump all the tracking data into one or more json file(s) under the tmp folder of your application.

sql_tracker can also track sql queries when running rails tests (e.g. your controller or integration tests), it will dump the data after all the tests are finished.

Tracking Using a Block

It is also possible to track queries executed within a block. This method uses a new subscriber to sql.active_record event notifications for each invocation. Results using this method are not saved to a file.

ruby
query_data = SqlTracker.track do
  # Run some active record queries
end

query_data.values
# =>
# [{
#  :sql=>"SELECT * FROM users",
#  :count=>1,
#  :duration=>1.0,
#  :source=>["app/models/user.rb:12"]
# }]

Reporting

To generate report, run

bash
sql_tracker tmp/sql_tracker-*.json

The output report looks like this:

…

By default, the report will be sorted by the total count of each query, you can also choose to sort it by average duration:

bash
sql_tracker tmp/sql_tracker-*.json --sort-by=duration

Configurations

All the configurable variables and their defaults are list below:

ruby
SqlTracker::Config.enabled = true
SqlTracker::Config.tracked_paths = %w(app lib)
SqlTracker::Config.tracked_sql_command = %w(SELECT INSERT UPDATE DELETE)
SqlTracker::Config.output_path = File.join(Rails.root.to_s, 'tmp')

License

The gem is available as open source under the terms of the MIT License.

Issues· 1 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Rubyrailssqltracking

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类后端框架
定价开源

> 相关工具

N
Node.js
基于 V8 的 JavaScript 运行时
D
Django
Python 高级 Web 框架
S
Spring Boot
Java 生态主流微服务框架