slowgrowl 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. data/Gemfile +7 -0
  2. data/README.md +30 -0
  3. data/Rakefile +20 -0
  4. data/VERSION +1 -0
  5. data/lib/slowgrowl.rb +72 -0
  6. metadata +77 -0
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'growl'
4
+
5
+ # group :test do
6
+ # gem 'rspec'
7
+ # end
data/README.md ADDED
@@ -0,0 +1,30 @@
1
+ SlowGrowl
2
+ =========
3
+
4
+ Rails 3 plugin which surfaces slow code paths in your Rails application by integrating with the new Notifications API in Rails 3 with your system Growl notification service. By default, any activity which takes longer than one second, will generate a growl alert, with the description of the action, time taken, and other meta data. A preview in action:
5
+
6
+ ![slowgrowl notification](http://img.skitch.com/20100804-8w1wte8bad7tby418kmucs4hsm.png)
7
+
8
+ Integrating with Rails 3
9
+ ------------------------
10
+
11
+ # in your Gemfile
12
+ group :development do
13
+ gem 'slowgrowl'
14
+ end
15
+
16
+ That's it.
17
+
18
+ Optional Configuration for SlowGrowl
19
+ ------------------------------------
20
+
21
+ # in your config/environments/development.rb
22
+ config.slowgrowl.warn = 1000 # growl any action which takes > 1000ms (1s)
23
+ config.slowgrowl.sticky = true # make really slow (2x warn) alerts sticky
24
+
25
+ Resources
26
+ ---------
27
+
28
+ * [Rails 3 Internals: Railtie & Creating Plugins](http://www.igvita.com/2010/08/04/rails-3-internals-railtie-creating-plugins/)
29
+ * [Rails 3 Notifications API](http://edgeapi.rubyonrails.org/classes/ActiveSupport/Notifications.html)
30
+ * [Railties](http://edgeapi.rubyonrails.org/classes/Rails/Railtie.html)
data/Rakefile ADDED
@@ -0,0 +1,20 @@
1
+ require 'rake'
2
+ require 'spec/rake/spectask'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gemspec|
7
+ gemspec.name = 'slowgrowl'
8
+ gemspec.summary = 'Surface slow code paths in your Rails 3 app via Growl'
9
+ gemspec.description = gemspec.summary
10
+ gemspec.email = 'ilya@igvita.com'
11
+ gemspec.homepage = 'http://github.com/igrigorik/slowgrowl'
12
+ gemspec.authors = ['Ilya Grigorik']
13
+ gemspec.add_dependency('growl')
14
+ gemspec.rubyforge_project = 'slowgrowl'
15
+ end
16
+
17
+ Jeweler::GemcutterTasks.new
18
+ rescue LoadError
19
+ puts 'Jeweler not available. Install it with: sudo gem install jeweler -s http://gemcutter.org'
20
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/lib/slowgrowl.rb ADDED
@@ -0,0 +1,72 @@
1
+ require 'growl'
2
+
3
+ module SlowGrowl
4
+ class Railtie < Rails::Railtie
5
+ config.slowgrowl = ActiveSupport::OrderedOptions.new
6
+ config.slowgrowl.warn = 1000 # default slow alert set to 1000ms
7
+ config.slowgrowl.sticky = false # should error warnings be sticky?
8
+
9
+ initializer "slowgrowl.initialize" do |app|
10
+
11
+ ActiveSupport::Notifications.subscribe do |*args|
12
+ if Growl.installed?
13
+ event = ActiveSupport::Notifications::Event.new(*args)
14
+
15
+ sticky = false
16
+ action, type = event.name.split('.')
17
+ alert = case event.duration
18
+ when (0...config.slowgrowl.warn) then
19
+ false
20
+ when (config.slowgrowl.warn..config.slowgrowl.warn*2) then
21
+ :warning
22
+ else
23
+ sticky = config.slowgrowl.sticky
24
+ :error
25
+ end
26
+
27
+ e = event.payload
28
+ message = case type
29
+ when 'action_controller' then
30
+ case action
31
+ when 'process_action' then
32
+ # {:controller=>"WidgetsController", :action=>"index", :params=>{"controller"=>"widgets", "action"=>"index"},
33
+ # :formats=>[:html], :method=>"GET", :path=>"/widgets", :status=>200, :view_runtime=>52.25706100463867,
34
+ # :db_runtime=>0}
35
+
36
+ if e[:exception]
37
+ "%s#%s.\n\n%s" % [
38
+ e[:controller], e[:action], e[:exception].join(', ')
39
+ ]
40
+ else
41
+ "%s#%s (%s).\nDB: %.1f, View: %.1f" % [
42
+ e[:controller], e[:action], e[:status], e[:db_runtime], e[:view_runtime]
43
+ ]
44
+ end
45
+
46
+ else
47
+ '%s#%s (%s)' % [e[:controller], e[:action], e[:status]]
48
+ end
49
+
50
+ when 'action_view' then
51
+ # {:identifier=>"text template", :layout=>nil }
52
+ '%s, layout: %s' % [e[:identifier], e[:layout].nil? ? 'none' : e[:layout]]
53
+
54
+ when 'active_record' then
55
+ # {:sql=>"SELECT "widgets".* FROM "widgets", :name=>"Widget Load", :connection_id=>2159415800}
56
+ "%s\n\n%s" % [e[:name], e[:sql].gsub("\n", ' ').squeeze(' ')]
57
+ else
58
+ 'Duration: %.1f' % [event.duration]
59
+ end
60
+
61
+ if alert
62
+ Growl.send("notify_#{alert}", message, {
63
+ :title => "%1.fms - %s : %s" % [event.duration, action.humanize, type.camelize],
64
+ :sticky => sticky
65
+ })
66
+ end
67
+ end
68
+ end
69
+
70
+ end
71
+ end
72
+ end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: slowgrowl
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Ilya Grigorik
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-08-04 00:00:00 -04:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: growl
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ type: :runtime
31
+ version_requirements: *id001
32
+ description: Surface slow code paths in your Rails 3 app via Growl
33
+ email: ilya@igvita.com
34
+ executables: []
35
+
36
+ extensions: []
37
+
38
+ extra_rdoc_files:
39
+ - README.md
40
+ files:
41
+ - Gemfile
42
+ - README.md
43
+ - Rakefile
44
+ - VERSION
45
+ - lib/slowgrowl.rb
46
+ has_rdoc: true
47
+ homepage: http://github.com/igrigorik/slowgrowl
48
+ licenses: []
49
+
50
+ post_install_message:
51
+ rdoc_options:
52
+ - --charset=UTF-8
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ segments:
60
+ - 0
61
+ version: "0"
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ segments:
67
+ - 0
68
+ version: "0"
69
+ requirements: []
70
+
71
+ rubyforge_project: slowgrowl
72
+ rubygems_version: 1.3.6
73
+ signing_key:
74
+ specification_version: 3
75
+ summary: Surface slow code paths in your Rails 3 app via Growl
76
+ test_files: []
77
+