Is there an easy way to log every SQL call to the database? I''d like to log mysql queries and their respective execution times into a table so that I can closely monitor/report the performance of my application and identify potential bottlenecks. Thanks, Chad --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Chad Arimura wrote:> Is there an easy way to log every SQL call to the database? I''d like to > log > mysql queries and their respective execution times into a table so that > I > can closely monitor/report the performance of my application and > identify > potential bottlenecks. >If your config.log_level is :debug (which it is for the development environment, production defaults to :info) then all your sql calls will be logged. Fred -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
I might have been a little unclear... I''d like to log those sql calls TO a database table. in example: class SQLQueries < ActiveRecord::Migration def self.up create_table :sql_queries do |t| t.column :query, :string t.column :execution_time, :decimal t.column :date, :timestamp end end thanks, Chad --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
anybody else? is it really that tough? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Chad wrote:> anybody else? is it really that tough?Well you could write your implementation of Logger (eg there is one that logs to syslog) that stuck things in the database, but then you''d be getting all the logging statements, not just the ones about db queries. It might be easier to just patch the code for the DB driver you use (or possibly for the corresponding ActiveRecord db adaptor Fred -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
In case anyone in the future cares, I found a pretty good solution for tracking db layer performance: 1) I implemented the Query Stats plugin: http://code.google.com/p/query-stats/ 2) set an after_filter to insert the results of those calls to the database. see below: after_filter :logging_dbstats def logging_dbstats # log sql stats here (pull from footer) sql = "insert into logging_dbstats(controller,action,controller_queries,view_queries,execution_time) values (''#{params[:controller]}'',''#{params[:action]}'',''#{queries.count_with_label :controller}'', ''#{queries.count_with_label :view}'', ''#{queries.total_time}'')" ActiveRecord::Base.connection.execute(sql) end cheers --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
ignore the comment in the code On Nov 1, 11:49 pm, "Chad" <carim...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> In case anyone in the future cares, I found a pretty good solution for > tracking db layer performance: > > 1) I implemented the Query Stats plugin:http://code.google.com/p/query-stats/ > 2) set an after_filter to insert the results of those calls to the > database. see below: > > after_filter :logging_dbstats > > def logging_dbstats > # log sql stats here (pull from footer) > sql = "insert into > logging_dbstats(controller,action,controller_queries,view_queries,execution_time) > values > (''#{params[:controller]}'',''#{params[:action]}'',''#{queries.count_with_label > :controller}'', ''#{queries.count_with_label :view}'', > ''#{queries.total_time}'')" > ActiveRecord::Base.connection.execute(sql) > end > > cheers--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---