app_monit_rails 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +13 -0
  3. data/Gemfile +22 -0
  4. data/Gemfile.lock +185 -0
  5. data/Guardfile +24 -0
  6. data/MIT-LICENSE +20 -0
  7. data/README.rdoc +3 -0
  8. data/Rakefile +9 -0
  9. data/appmonit_rails_gem.gemspec +30 -0
  10. data/lib/app_monit/rails/railtie.rb +10 -0
  11. data/lib/app_monit/rails/subscriber.rb +47 -0
  12. data/lib/app_monit/rails/version.rb +5 -0
  13. data/lib/app_monit/rails/worker.rb +131 -0
  14. data/lib/app_monit_rails.rb +17 -0
  15. data/lib/tasks/app_monit_tasks.rake +4 -0
  16. data/spec/dummy/README.rdoc +28 -0
  17. data/spec/dummy/Rakefile +6 -0
  18. data/spec/dummy/app/assets/images/.keep +0 -0
  19. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  20. data/spec/dummy/app/assets/javascripts/posts.js +2 -0
  21. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  22. data/spec/dummy/app/assets/stylesheets/posts.css +4 -0
  23. data/spec/dummy/app/assets/stylesheets/scaffold.css +56 -0
  24. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  25. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  26. data/spec/dummy/app/controllers/posts_controller.rb +63 -0
  27. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  28. data/spec/dummy/app/helpers/posts_helper.rb +2 -0
  29. data/spec/dummy/app/mailers/.keep +0 -0
  30. data/spec/dummy/app/models/.keep +0 -0
  31. data/spec/dummy/app/models/concerns/.keep +0 -0
  32. data/spec/dummy/app/models/post.rb +2 -0
  33. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  34. data/spec/dummy/app/views/posts/_form.html.erb +25 -0
  35. data/spec/dummy/app/views/posts/edit.html.erb +6 -0
  36. data/spec/dummy/app/views/posts/index.html.erb +29 -0
  37. data/spec/dummy/app/views/posts/new.html.erb +5 -0
  38. data/spec/dummy/app/views/posts/show.html.erb +14 -0
  39. data/spec/dummy/bin/bundle +3 -0
  40. data/spec/dummy/bin/rails +4 -0
  41. data/spec/dummy/bin/rake +4 -0
  42. data/spec/dummy/config/application.rb +28 -0
  43. data/spec/dummy/config/boot.rb +5 -0
  44. data/spec/dummy/config/database.yml +25 -0
  45. data/spec/dummy/config/environment.rb +5 -0
  46. data/spec/dummy/config/environments/development.rb +29 -0
  47. data/spec/dummy/config/environments/production.rb +80 -0
  48. data/spec/dummy/config/environments/test.rb +36 -0
  49. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  50. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  51. data/spec/dummy/config/initializers/inflections.rb +16 -0
  52. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  53. data/spec/dummy/config/initializers/secret_token.rb +12 -0
  54. data/spec/dummy/config/initializers/session_store.rb +3 -0
  55. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  56. data/spec/dummy/config/locales/en.yml +23 -0
  57. data/spec/dummy/config/railsrunner.yml +8 -0
  58. data/spec/dummy/config/routes.rb +5 -0
  59. data/spec/dummy/config.ru +4 -0
  60. data/spec/dummy/db/migrate/20130719074144_create_posts.rb +10 -0
  61. data/spec/dummy/db/schema.rb +23 -0
  62. data/spec/dummy/lib/assets/.keep +0 -0
  63. data/spec/dummy/log/.keep +0 -0
  64. data/spec/dummy/public/404.html +58 -0
  65. data/spec/dummy/public/422.html +58 -0
  66. data/spec/dummy/public/500.html +57 -0
  67. data/spec/dummy/public/favicon.ico +0 -0
  68. data/spec/features/trigger_events_spec.rb +45 -0
  69. data/spec/spec_helper.rb +40 -0
  70. metadata +280 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0769d189aabb5b61c156b284e4da0b101fb7589b
4
+ data.tar.gz: d4022043cde9af84b6a27709a457649dbf6c9fa0
5
+ SHA512:
6
+ metadata.gz: 69105b1f1c655666bc87cd01cd3c30671f1c2e3017666fd38496fb4e92187aa25e3ff2e0328131ba27f44ee1845dea0787e27e1c0802e8cf21a8773e21e9cde0
7
+ data.tar.gz: 20826e4ad2f2c35ba3eb280b1465c4e75e2d80ec07b05f6989088b983409a78ef5373d5ef50c12135fdd9af3392f645a009504ef4f429e11ea70005a702cde7f
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ .bundle/
2
+ log/*.log
3
+ pkg/
4
+ spec/dummy/db/*.sqlite3
5
+ spec/dummy/db/*.sqlite3-journal
6
+ spec/dummy/log/*.log
7
+ spec/dummy/tmp/
8
+ spec/dummy/.sass-cache
9
+ .DS_Store
10
+ coverage
11
+ tmp
12
+ .idea
13
+ .rspec
data/Gemfile ADDED
@@ -0,0 +1,22 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Declare your gem's dependencies in app_monit.gemspec.
4
+ # Bundler will treat runtime dependencies like base dependencies, and
5
+ # development dependencies will be added by default to the :development group.
6
+ gemspec
7
+
8
+ # Declare any dependencies that are still in development here instead of in
9
+ # your gemspec. These might include edge Rails or gems from your path or
10
+ # Git. Remember to move these dependencies to your gemspec before releasing
11
+ # your gem to rubygems.org.
12
+
13
+ # To use debugger
14
+ # gem 'debugger'
15
+
16
+ group :test, :development do
17
+ gem 'sqlite3'
18
+ gem 'rspec-rails'
19
+ gem 'capybara'
20
+ gem 'simplecov'
21
+ gem 'guard-rspec'
22
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,185 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ app_monit_rails (0.0.5)
5
+ app_monit (>= 0.0.7)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ actionmailer (4.1.6)
11
+ actionpack (= 4.1.6)
12
+ actionview (= 4.1.6)
13
+ mail (~> 2.5, >= 2.5.4)
14
+ actionpack (4.1.6)
15
+ actionview (= 4.1.6)
16
+ activesupport (= 4.1.6)
17
+ rack (~> 1.5.2)
18
+ rack-test (~> 0.6.2)
19
+ actionview (4.1.6)
20
+ activesupport (= 4.1.6)
21
+ builder (~> 3.1)
22
+ erubis (~> 2.7.0)
23
+ activemodel (4.1.6)
24
+ activesupport (= 4.1.6)
25
+ builder (~> 3.1)
26
+ activerecord (4.1.6)
27
+ activemodel (= 4.1.6)
28
+ activesupport (= 4.1.6)
29
+ arel (~> 5.0.0)
30
+ activesupport (4.1.6)
31
+ i18n (~> 0.6, >= 0.6.9)
32
+ json (~> 1.7, >= 1.7.7)
33
+ minitest (~> 5.1)
34
+ thread_safe (~> 0.1)
35
+ tzinfo (~> 1.1)
36
+ addressable (2.3.6)
37
+ ansi (1.4.3)
38
+ app_monit (0.0.7)
39
+ arel (5.0.1.20140414130214)
40
+ builder (3.2.2)
41
+ capybara (2.4.4)
42
+ mime-types (>= 1.16)
43
+ nokogiri (>= 1.3.3)
44
+ rack (>= 1.0.0)
45
+ rack-test (>= 0.5.4)
46
+ xpath (~> 2.0)
47
+ celluloid (0.16.0)
48
+ timers (~> 4.0.0)
49
+ coderay (1.1.0)
50
+ crack (0.4.2)
51
+ safe_yaml (~> 1.0.0)
52
+ diff-lcs (1.2.5)
53
+ docile (1.1.5)
54
+ erubis (2.7.0)
55
+ ffi (1.9.6)
56
+ formatador (0.2.5)
57
+ guard (2.6.1)
58
+ formatador (>= 0.2.4)
59
+ listen (~> 2.7)
60
+ lumberjack (~> 1.0)
61
+ pry (>= 0.9.12)
62
+ thor (>= 0.18.1)
63
+ guard-minitest (2.3.2)
64
+ guard (~> 2.0)
65
+ minitest (>= 3.0)
66
+ guard-rspec (4.3.1)
67
+ guard (~> 2.1)
68
+ rspec (>= 2.14, < 4.0)
69
+ hike (1.2.3)
70
+ hitimes (1.2.2)
71
+ i18n (0.6.11)
72
+ json (1.8.1)
73
+ listen (2.7.11)
74
+ celluloid (>= 0.15.2)
75
+ rb-fsevent (>= 0.9.3)
76
+ rb-inotify (>= 0.9)
77
+ lumberjack (1.0.9)
78
+ mail (2.6.1)
79
+ mime-types (>= 1.16, < 3)
80
+ method_source (0.8.2)
81
+ mime-types (2.4.3)
82
+ mini_portile (0.6.0)
83
+ minitest (5.4.2)
84
+ minitest-reporters (1.0.6)
85
+ ansi
86
+ builder
87
+ minitest (>= 5.0)
88
+ ruby-progressbar
89
+ multi_json (1.10.1)
90
+ nokogiri (1.6.3.1)
91
+ mini_portile (= 0.6.0)
92
+ pry (0.10.1)
93
+ coderay (~> 1.1.0)
94
+ method_source (~> 0.8.1)
95
+ slop (~> 3.4)
96
+ rack (1.5.2)
97
+ rack-test (0.6.2)
98
+ rack (>= 1.0)
99
+ rails (4.1.6)
100
+ actionmailer (= 4.1.6)
101
+ actionpack (= 4.1.6)
102
+ actionview (= 4.1.6)
103
+ activemodel (= 4.1.6)
104
+ activerecord (= 4.1.6)
105
+ activesupport (= 4.1.6)
106
+ bundler (>= 1.3.0, < 2.0)
107
+ railties (= 4.1.6)
108
+ sprockets-rails (~> 2.0)
109
+ railties (4.1.6)
110
+ actionpack (= 4.1.6)
111
+ activesupport (= 4.1.6)
112
+ rake (>= 0.8.7)
113
+ thor (>= 0.18.1, < 2.0)
114
+ rake (10.3.2)
115
+ rb-fsevent (0.9.4)
116
+ rb-inotify (0.9.5)
117
+ ffi (>= 0.5.0)
118
+ rspec (3.1.0)
119
+ rspec-core (~> 3.1.0)
120
+ rspec-expectations (~> 3.1.0)
121
+ rspec-mocks (~> 3.1.0)
122
+ rspec-core (3.1.7)
123
+ rspec-support (~> 3.1.0)
124
+ rspec-expectations (3.1.2)
125
+ diff-lcs (>= 1.2.0, < 2.0)
126
+ rspec-support (~> 3.1.0)
127
+ rspec-mocks (3.1.3)
128
+ rspec-support (~> 3.1.0)
129
+ rspec-rails (3.1.0)
130
+ actionpack (>= 3.0)
131
+ activesupport (>= 3.0)
132
+ railties (>= 3.0)
133
+ rspec-core (~> 3.1.0)
134
+ rspec-expectations (~> 3.1.0)
135
+ rspec-mocks (~> 3.1.0)
136
+ rspec-support (~> 3.1.0)
137
+ rspec-support (3.1.2)
138
+ ruby-progressbar (1.6.0)
139
+ safe_yaml (1.0.4)
140
+ simplecov (0.9.1)
141
+ docile (~> 1.1.0)
142
+ multi_json (~> 1.0)
143
+ simplecov-html (~> 0.8.0)
144
+ simplecov-html (0.8.0)
145
+ slop (3.6.0)
146
+ sprockets (2.11.0)
147
+ hike (~> 1.2)
148
+ multi_json (~> 1.0)
149
+ rack (~> 1.0)
150
+ tilt (~> 1.1, != 1.3.0)
151
+ sprockets-rails (2.2.0)
152
+ actionpack (>= 3.0)
153
+ activesupport (>= 3.0)
154
+ sprockets (>= 2.8, < 4.0)
155
+ sqlite3 (1.3.7)
156
+ thor (0.19.1)
157
+ thread_safe (0.3.4)
158
+ tilt (1.4.1)
159
+ timers (4.0.1)
160
+ hitimes
161
+ tzinfo (1.2.2)
162
+ thread_safe (~> 0.1)
163
+ webmock (1.20.0)
164
+ addressable (>= 2.3.6)
165
+ crack (>= 0.3.2)
166
+ xpath (2.0.0)
167
+ nokogiri (~> 1.3)
168
+
169
+ PLATFORMS
170
+ ruby
171
+
172
+ DEPENDENCIES
173
+ app_monit_rails!
174
+ bundler (>= 1.5.0)
175
+ capybara
176
+ guard-minitest
177
+ guard-rspec
178
+ minitest (>= 5.2.2)
179
+ minitest-reporters
180
+ rails (>= 4.1)
181
+ rake
182
+ rspec-rails
183
+ simplecov
184
+ sqlite3
185
+ webmock (>= 1.17.1)
data/Guardfile ADDED
@@ -0,0 +1,24 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard :rspec do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+
9
+ # Rails example
10
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
11
+ watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
12
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
13
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
14
+ watch('config/routes.rb') { "spec/routing" }
15
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
16
+
17
+ # Capybara features specs
18
+ watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
19
+
20
+ # Turnip features and steps
21
+ watch(%r{^spec/acceptance/(.+)\.feature$})
22
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
23
+ end
24
+
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2013 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,3 @@
1
+ = AppMonit
2
+
3
+ This project rocks and uses MIT-LICENSE.
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << 'spec'
6
+ t.pattern = 'spec/**/*_spec.rb'
7
+ end
8
+
9
+ task :default => :test
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'app_monit/rails/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "app_monit_rails"
8
+ spec.version = AppMonit::Rails::VERSION
9
+ spec.authors = ["Redmar Kerkhoff", "Benoist Claassen"]
10
+ spec.email = ["redmar@appmon.it", "benoist@appmon.it"]
11
+ spec.summary = %q{Client gem for pushing events from ruby to the appmon.it service}
12
+ spec.description = %q{Client gem for pushing events from ruby to the appmon.it service}
13
+ spec.homepage = "https://appmon.it"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(spec|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "app_monit", ">= 0.0.7"
22
+
23
+ spec.add_development_dependency "bundler", ">= 1.5.0"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "minitest", ">= 5.2.2"
26
+ spec.add_development_dependency "minitest-reporters"
27
+ spec.add_development_dependency "webmock", ">= 1.17.1"
28
+ spec.add_development_dependency "rails", ">= 4.1"
29
+ spec.add_development_dependency "guard-minitest" if RUBY_PLATFORM =~ /darwin/
30
+ end
@@ -0,0 +1,10 @@
1
+ module AppMonit
2
+ module Rails
3
+ class Railtie < ::Rails::Railtie
4
+ initializer 'app_monit.configure' do |app|
5
+ AppMonit::Rails::Subscriber.register
6
+ AppMonit::Rails.logger.debug '[RAILSRUNNER] started'
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,47 @@
1
+ module AppMonit
2
+ module Rails
3
+ class Subscriber
4
+
5
+ class << self
6
+ def register
7
+ ActiveSupport::Notifications.subscribe /process_action/, self.new
8
+ end
9
+ end
10
+
11
+ def call(*args)
12
+ event = ActiveSupport::Notifications::Event.new(*args)
13
+
14
+ payload = event.payload
15
+ endpoint = "#{payload[:controller]}##{payload[:action]}"
16
+ minute = event.time.to_i - (event.time.to_i % 60)
17
+
18
+ if payload[:exception]
19
+ trigger_error(minute, endpoint, event.duration.to_i)
20
+ trigger_error(minute, 'total', event.duration.to_i)
21
+ else
22
+ durations = { total: event.duration.to_i, view: payload[:view_runtime].to_i,
23
+ db: payload[:db_runtime].to_i, ext: payload[:ext_runtime].to_i }
24
+ trigger_event(minute, endpoint, durations)
25
+ trigger_event(minute, 'total', durations)
26
+ end
27
+ end
28
+
29
+ # @return [AppMonit::Worker]
30
+ def worker
31
+ AppMonit::Rails::Worker.instance
32
+ end
33
+
34
+ def trigger_error(minute, endpoint, duration)
35
+ event = AppMonit::Rails::Error.new(minute, endpoint, duration)
36
+ AppMonit::Rails.logger.debug event
37
+ worker.push(event)
38
+ end
39
+
40
+ def trigger_event(minute, endpoint, durations)
41
+ event = AppMonit::Rails::Event.new(minute, endpoint, durations)
42
+ AppMonit::Rails.logger.debug event
43
+ worker.push(event)
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,5 @@
1
+ module AppMonit
2
+ module Rails
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,131 @@
1
+ module AppMonit
2
+ module Rails
3
+ class Worker
4
+ MUTEX = Mutex.new
5
+ MAX_MULTIPLIER = 5
6
+
7
+ attr_accessor :requests, :errors
8
+
9
+ class << self
10
+ def instance
11
+ return @instance if @instance
12
+ MUTEX.synchronize do
13
+ return @instance if @instance
14
+ @instance = new.start
15
+ end
16
+ end
17
+ end
18
+
19
+ def initialize
20
+ @queue = Queue.new
21
+ @multiplier = 1
22
+ @flush_rate = 60
23
+ reset
24
+ end
25
+
26
+ def reset
27
+ @requests = Hash.new do |requests, minutes|
28
+ requests[minutes] = Hash.new do |minute, endpoints|
29
+ minute[endpoints] = Hash.new do |endpoint, duration|
30
+ endpoint[duration] = { sum: 0, count: 0, average: 0 }
31
+ end
32
+ end
33
+ end
34
+ @errors = Hash.new do |errors, minutes|
35
+ errors[minutes] = Hash.new do |minute, endpoint|
36
+ minute[endpoint] = { sum: 0, count: 0, average: 0 }
37
+ end
38
+ end
39
+ end
40
+
41
+ def current_minute
42
+ time = Time.now.to_i
43
+ time - (time % 60)
44
+ end
45
+
46
+ def start
47
+ Thread.new do
48
+ while (event = @queue.pop)
49
+ begin
50
+ case event
51
+ when Error
52
+ update_error(event)
53
+ when Event
54
+ update_event(event)
55
+ when :flush
56
+ send_to_collector
57
+ end
58
+ rescue Exception => e
59
+ AppMonit::Rails.logger.debug ["Event error:", event.inspect, e.message]
60
+ end
61
+ end
62
+ end
63
+ start_flusher
64
+
65
+ self
66
+ end
67
+
68
+ def update_error(event)
69
+ bucket = @errors[event.minute][event.endpoint]
70
+ bucket[:sum] += event.duration
71
+ bucket[:count] += 1
72
+ bucket[:average] = (bucket[:sum] / bucket[:count].to_f)
73
+ end
74
+
75
+ # @param [AppMonit::Rails::Event] event
76
+ def update_event(event)
77
+ event.durations.each do |duration, value|
78
+ bucket = @requests[event.minute][event.endpoint][duration]
79
+ bucket[:sum] += value
80
+ bucket[:count] += 1
81
+ bucket[:average] = (bucket[:sum] / bucket[:count].to_f)
82
+ end
83
+ end
84
+
85
+ def start_flusher
86
+ Thread.new do
87
+ loop do
88
+ sleep @multiplier * @flush_rate
89
+ push(:flush)
90
+ end
91
+ end
92
+ end
93
+
94
+ def push(event)
95
+ @queue << event
96
+ end
97
+
98
+ def convert_requests_to_events
99
+ @requests.flat_map do |minute, endpoints|
100
+ endpoints.collect do |endpoint, durations|
101
+ payload = { endpoint: endpoint }.merge(durations.delete(:total) || {}).merge(durations)
102
+ { created_at: Time.at(minute), name: 'page_load', payload: payload }
103
+ end
104
+ end
105
+ end
106
+
107
+ def convert_errors_to_events
108
+ @errors.flat_map do |minute, endpoints|
109
+ endpoints.collect do |endpoint, duration|
110
+ payload = duration.merge(endpoint: endpoint)
111
+ { created_at: Time.at(minute), name: 'page_error', payload: payload }
112
+ end
113
+ end
114
+ end
115
+
116
+ def send_to_collector
117
+ AppMonit::Rails.logger.debug "Sending to collector"
118
+
119
+ events = convert_requests_to_events
120
+ errors = convert_errors_to_events
121
+
122
+ AppMonit::Http.post('/v1/events', event: (events + errors))
123
+
124
+ @requests.clear
125
+ @errors.clear
126
+
127
+ reset
128
+ end
129
+ end
130
+ end
131
+ end
@@ -0,0 +1,17 @@
1
+ require 'app_monit'
2
+ module AppMonit
3
+ module Rails
4
+ Event = Struct.new(:minute, :endpoint, :durations)
5
+ Error = Struct.new(:minute, :endpoint, :duration)
6
+
7
+ require 'app_monit/rails/subscriber'
8
+ require 'app_monit/rails/railtie'
9
+ require 'app_monit/rails/worker'
10
+
11
+ class << self
12
+ def logger
13
+ @logger ||= ::Rails.env.test? ? Logger.new($STDOUT) : Logger.new('log/app_monit_rails.log')
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :app_monit do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,28 @@
1
+ == README
2
+
3
+ This README would normally document whatever steps are necessary to get the
4
+ application up and running.
5
+
6
+ Things you may want to cover:
7
+
8
+ * Ruby version
9
+
10
+ * System dependencies
11
+
12
+ * Configuration
13
+
14
+ * Database creation
15
+
16
+ * Database initialization
17
+
18
+ * How to run the test suite
19
+
20
+ * Services (job queues, cache servers, search engines, etc.)
21
+
22
+ * Deployment instructions
23
+
24
+ * ...
25
+
26
+
27
+ Please feel free to use a different markup language if you do not plan to run
28
+ <tt>rake doc:app</tt>.
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+
6
+ Dummy::Application.load_tasks
File without changes
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -0,0 +1,13 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
9
+ * compiled file, but it's generally better to create a new file per style scope.
10
+ *
11
+ *= require_self
12
+ *= require_tree .
13
+ */
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,56 @@
1
+ body { background-color: #fff; color: #333; }
2
+
3
+ body, p, ol, ul, td {
4
+ font-family: verdana, arial, helvetica, sans-serif;
5
+ font-size: 13px;
6
+ line-height: 18px;
7
+ }
8
+
9
+ pre {
10
+ background-color: #eee;
11
+ padding: 10px;
12
+ font-size: 11px;
13
+ }
14
+
15
+ a { color: #000; }
16
+ a:visited { color: #666; }
17
+ a:hover { color: #fff; background-color:#000; }
18
+
19
+ div.field, div.actions {
20
+ margin-bottom: 10px;
21
+ }
22
+
23
+ #notice {
24
+ color: green;
25
+ }
26
+
27
+ .field_with_errors {
28
+ padding: 2px;
29
+ background-color: red;
30
+ display: table;
31
+ }
32
+
33
+ #error_explanation {
34
+ width: 450px;
35
+ border: 2px solid red;
36
+ padding: 7px;
37
+ padding-bottom: 0;
38
+ margin-bottom: 20px;
39
+ background-color: #f0f0f0;
40
+ }
41
+
42
+ #error_explanation h2 {
43
+ text-align: left;
44
+ font-weight: bold;
45
+ padding: 5px 5px 5px 15px;
46
+ font-size: 12px;
47
+ margin: -7px;
48
+ margin-bottom: 0px;
49
+ background-color: #c00;
50
+ color: #fff;
51
+ }
52
+
53
+ #error_explanation ul li {
54
+ font-size: 12px;
55
+ list-style: square;
56
+ }
@@ -0,0 +1,5 @@
1
+ class ApplicationController < ActionController::Base
2
+ # Prevent CSRF attacks by raising an exception.
3
+ # For APIs, you may want to use :null_session instead.
4
+ protect_from_forgery with: :exception
5
+ end