Created
March 16, 2012 11:12
-
-
Save killercup/2049630 to your computer and use it in GitHub Desktop.
Update Stathat from Rails in Background
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/initializers/stathat.rb | |
if Rails.env.production? | |
ezkey = # SET ME! | |
server = # SET ME! | |
def stathat(ezkey, stat, value, type) | |
# This is probably the most insane code you have ever seen | |
# http://ragefac.es/53 | |
system "curl -silent -d 'email=#{ezkey}&stat=#{stat}&#{type}=#{value}' 'http://api.stathat.com/ez' > /dev/null &" | |
return | |
end | |
ActiveSupport::Notifications.subscribe "process_action.action_controller" do |name, start, finish, id, payload| | |
stathat(ezkey, "#{server} page view", "1", "count") | |
stathat(ezkey, "#{server} request duration", (finish - start) * 1000, "value") | |
unless payload[:view_runtime].nil? | |
stathat(ezkey, "#{server} request view duration", payload[:view_runtime], "value") | |
end | |
unless payload[:db_runtime].nil? | |
stathat(ezkey, "#{server} request db duration", payload[:db_runtime], "value") | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment