All Projects → steventen → Sql_tracker

steventen / Sql_tracker

Licence: mit
Rails SQL Query Tracker

Programming Languages

ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to Sql tracker

Monitor Table Change With Sqltabledependency
Get SQL Server notification on record table change
Stars: ✭ 459 (+218.75%)
Mutual labels:  sql, tracking
Codecademy Exercise Answers
🎓 Codecademy.com exercise answers
Stars: ✭ 291 (+102.08%)
Mutual labels:  sql, rails
Scenic
Scenic is maintained by Derek Prior, Caleb Hearth, and you, our contributors.
Stars: ✭ 2,856 (+1883.33%)
Mutual labels:  sql, rails
Activerecord where assoc
Make ActiveRecord do conditions on your associations
Stars: ✭ 126 (-12.5%)
Mutual labels:  sql, rails
Graphjin
GraphJin - Build APIs in 5 minutes with GraphQL. An instant GraphQL to SQL compiler.
Stars: ✭ 1,264 (+777.78%)
Mutual labels:  sql, rails
Github Ds
A collection of Ruby libraries for working with SQL on top of ActiveRecord's connection
Stars: ✭ 597 (+314.58%)
Mutual labels:  sql, rails
Public activity
Easy activity tracking for models - similar to Github's Public Activity
Stars: ✭ 2,822 (+1859.72%)
Mutual labels:  rails, tracking
Vglist
A video game library tracking web app built in Rails and powered by Wikidata.
Stars: ✭ 78 (-45.83%)
Mutual labels:  rails, tracking
Lol dba
lol_dba is a small package of rake tasks that scan your application models and displays a list of columns that probably should be indexed. Also, it can generate .sql migration scripts.
Stars: ✭ 1,363 (+846.53%)
Mutual labels:  sql, rails
Reactive record
Generate ActiveRecord models for a pre-existing Postgres db
Stars: ✭ 132 (-8.33%)
Mutual labels:  sql, rails
Redis dashboard
Sinatra app to monitor Redis servers.
Stars: ✭ 141 (-2.08%)
Mutual labels:  rails
Vueport
Single file components for Rails with Vue JS and Webpack
Stars: ✭ 141 (-2.08%)
Mutual labels:  rails
Rails admin theme
rails_admin theme flat theme
Stars: ✭ 142 (-1.39%)
Mutual labels:  rails
Config
Easiest way to add multi-environment yaml settings to Rails, Sinatra, Pandrino and other Ruby projects.
Stars: ✭ 1,821 (+1164.58%)
Mutual labels:  rails
Credit card validations
💳 ruby gem for validating credit card numbers, generating valid numbers, luhn checks
Stars: ✭ 140 (-2.78%)
Mutual labels:  rails
Takt
Track your tasks and time
Stars: ✭ 142 (-1.39%)
Mutual labels:  tracking
Prometheus Sql
Service that exposes Prometheus metrics for a SQL result set.
Stars: ✭ 140 (-2.78%)
Mutual labels:  sql
Relay Rails Blog
A graphql, relay and standard rails application powered demo weblog. We are using Graphql server and relay for our react component data needs.
Stars: ✭ 140 (-2.78%)
Mutual labels:  rails
Builder
Lightweight and fast SQL builder for Go language, moved to https://gitea.com/xorm/builder
Stars: ✭ 140 (-2.78%)
Mutual labels:  sql
Rails api auth
Lightweight Rails Engine that implements the "Resource Owner Password Credentials Grant" OAuth 2.0 flow as well as Facebook authentication
Stars: ✭ 143 (-0.69%)
Mutual labels:  rails

Rails SQL Query Tracker

Code Climate Build Status

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:

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.

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

sql_tracker tmp/sql_tracker-*.json

The output report looks like this:

==================================
Total Unique SQL Queries: 24
==================================
Count | Avg Time (ms)   | SQL Query                                                                                                 | Source
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
8     | 0.33            | SELECT `users`.* FROM `users` WHERE `users`.`id` = xxx LIMIT 1                                            | app/controllers/users_controller.rb:125:in `create'
      |                 |                                                                                                           | app/controllers/projects_controller.rb:9:in `block in update'
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
4     | 0.27            | SELECT `projects`.* FROM `projects` WHERE `projects`.`user_id` = xxx AND `projects`.`id` = xxx LIMIT 1    | app/controllers/projects_controller.rb:4:in `update'
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2     | 0.27            | UPDATE `projects` SET `updated_at` = xxx WHERE `projects`.`id` = xxx                                      | app/controllers/projects_controller.rb:9:in `block in update'
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2     | 1.76            | SELECT projects.* FROM projects WHERE projects.priority BETWEEN xxx AND xxx ORDER BY created_at DESC      | app/controllers/projects_controller.rb:35:in `index'
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
... ...

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

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

Configurations

All the configurable variables and their defaults are list below:

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].