metrician 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +18 -0
  3. data/.rspec +2 -0
  4. data/.rubocop.yml +65 -0
  5. data/.rubocop_todo.yml +24 -0
  6. data/.ruby-version +1 -0
  7. data/.travis.yml +36 -0
  8. data/Gemfile +1 -0
  9. data/METRICS.MD +48 -0
  10. data/README.md +77 -0
  11. data/Rakefile +12 -0
  12. data/config/metrician.yaml +136 -0
  13. data/gemfiles/Gemfile.4.2.sidekiq-4 +24 -0
  14. data/gemfiles/Gemfile.4.2.sidekiq-4.lock +173 -0
  15. data/gemfiles/Gemfile.5.0.pg +24 -0
  16. data/gemfiles/Gemfile.5.0.pg.lock +182 -0
  17. data/lib/metrician.rb +80 -0
  18. data/lib/metrician/configuration.rb +33 -0
  19. data/lib/metrician/jobs.rb +32 -0
  20. data/lib/metrician/jobs/delayed_job_callbacks.rb +33 -0
  21. data/lib/metrician/jobs/resque_plugin.rb +36 -0
  22. data/lib/metrician/jobs/sidekiq_middleware.rb +28 -0
  23. data/lib/metrician/middleware.rb +64 -0
  24. data/lib/metrician/middleware/application_timing.rb +29 -0
  25. data/lib/metrician/middleware/request_timing.rb +152 -0
  26. data/lib/metrician/reporter.rb +41 -0
  27. data/lib/metrician/reporters/active_record.rb +63 -0
  28. data/lib/metrician/reporters/delayed_job.rb +17 -0
  29. data/lib/metrician/reporters/honeybadger.rb +26 -0
  30. data/lib/metrician/reporters/memcache.rb +49 -0
  31. data/lib/metrician/reporters/method_tracer.rb +70 -0
  32. data/lib/metrician/reporters/middleware.rb +22 -0
  33. data/lib/metrician/reporters/net_http.rb +28 -0
  34. data/lib/metrician/reporters/redis.rb +31 -0
  35. data/lib/metrician/reporters/resque.rb +17 -0
  36. data/lib/metrician/reporters/sidekiq.rb +19 -0
  37. data/lib/metrician/version.rb +5 -0
  38. data/metrician.gemspec +25 -0
  39. data/script/setup +72 -0
  40. data/script/test +36 -0
  41. data/spec/metrician_spec.rb +372 -0
  42. data/spec/spec_helper.rb +23 -0
  43. data/spec/support/database.rb +33 -0
  44. data/spec/support/database.sample.yml +10 -0
  45. data/spec/support/database.travis.yml +9 -0
  46. data/spec/support/models.rb +2 -0
  47. data/spec/support/test_delayed_job.rb +12 -0
  48. data/spec/support/test_resque_job.rb +8 -0
  49. data/spec/support/test_sidekiq_worker.rb +8 -0
  50. metadata +188 -0
@@ -0,0 +1,173 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ metrician (0.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ actionmailer (4.2.8)
10
+ actionpack (= 4.2.8)
11
+ actionview (= 4.2.8)
12
+ activejob (= 4.2.8)
13
+ mail (~> 2.5, >= 2.5.4)
14
+ rails-dom-testing (~> 1.0, >= 1.0.5)
15
+ actionpack (4.2.8)
16
+ actionview (= 4.2.8)
17
+ activesupport (= 4.2.8)
18
+ rack (~> 1.6)
19
+ rack-test (~> 0.6.2)
20
+ rails-dom-testing (~> 1.0, >= 1.0.5)
21
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
22
+ actionview (4.2.8)
23
+ activesupport (= 4.2.8)
24
+ builder (~> 3.1)
25
+ erubis (~> 2.7.0)
26
+ rails-dom-testing (~> 1.0, >= 1.0.5)
27
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
28
+ activejob (4.2.8)
29
+ activesupport (= 4.2.8)
30
+ globalid (>= 0.3.0)
31
+ activemodel (4.2.8)
32
+ activesupport (= 4.2.8)
33
+ builder (~> 3.1)
34
+ activerecord (4.2.8)
35
+ activemodel (= 4.2.8)
36
+ activesupport (= 4.2.8)
37
+ arel (~> 6.0)
38
+ activesupport (4.2.8)
39
+ i18n (~> 0.7)
40
+ minitest (~> 5.1)
41
+ thread_safe (~> 0.3, >= 0.3.4)
42
+ tzinfo (~> 1.1)
43
+ arel (6.0.4)
44
+ builder (3.2.3)
45
+ byebug (9.0.6)
46
+ concurrent-ruby (1.0.5)
47
+ connection_pool (2.2.1)
48
+ database_cleaner (1.6.1)
49
+ delayed_job (4.1.3)
50
+ activesupport (>= 3.0, < 5.2)
51
+ delayed_job_active_record (4.1.2)
52
+ activerecord (>= 3.0, < 5.2)
53
+ delayed_job (>= 3.0, < 5)
54
+ diff-lcs (1.3)
55
+ erubis (2.7.0)
56
+ gemika (0.3.2)
57
+ globalid (0.4.0)
58
+ activesupport (>= 4.2.0)
59
+ i18n (0.8.4)
60
+ instrumental_agent (1.0.1)
61
+ loofah (2.0.3)
62
+ nokogiri (>= 1.5.9)
63
+ mail (2.6.6)
64
+ mime-types (>= 1.16, < 4)
65
+ memcached (1.8.0)
66
+ mime-types (3.1)
67
+ mime-types-data (~> 3.2015)
68
+ mime-types-data (3.2016.0521)
69
+ mini_portile2 (2.2.0)
70
+ minitest (5.10.2)
71
+ mono_logger (1.1.0)
72
+ multi_json (1.12.1)
73
+ mysql2 (0.3.17)
74
+ nokogiri (1.8.0)
75
+ mini_portile2 (~> 2.2.0)
76
+ rack (1.6.8)
77
+ rack-protection (1.5.3)
78
+ rack
79
+ rack-test (0.6.3)
80
+ rack (>= 1.0)
81
+ rails (4.2.8)
82
+ actionmailer (= 4.2.8)
83
+ actionpack (= 4.2.8)
84
+ actionview (= 4.2.8)
85
+ activejob (= 4.2.8)
86
+ activemodel (= 4.2.8)
87
+ activerecord (= 4.2.8)
88
+ activesupport (= 4.2.8)
89
+ bundler (>= 1.3.0, < 2.0)
90
+ railties (= 4.2.8)
91
+ sprockets-rails
92
+ rails-deprecated_sanitizer (1.0.3)
93
+ activesupport (>= 4.2.0.alpha)
94
+ rails-dom-testing (1.0.8)
95
+ activesupport (>= 4.2.0.beta, < 5.0)
96
+ nokogiri (~> 1.6)
97
+ rails-deprecated_sanitizer (>= 1.0.1)
98
+ rails-html-sanitizer (1.0.3)
99
+ loofah (~> 2.0)
100
+ railties (4.2.8)
101
+ actionpack (= 4.2.8)
102
+ activesupport (= 4.2.8)
103
+ rake (>= 0.8.7)
104
+ thor (>= 0.18.1, < 2.0)
105
+ rake (12.0.0)
106
+ redis (3.3.3)
107
+ redis-namespace (1.5.3)
108
+ redis (~> 3.0, >= 3.0.4)
109
+ resque (1.27.4)
110
+ mono_logger (~> 1.0)
111
+ multi_json (~> 1.0)
112
+ redis-namespace (~> 1.3)
113
+ sinatra (>= 0.9.2)
114
+ vegas (~> 0.1.2)
115
+ rspec (3.6.0)
116
+ rspec-core (~> 3.6.0)
117
+ rspec-expectations (~> 3.6.0)
118
+ rspec-mocks (~> 3.6.0)
119
+ rspec-core (3.6.0)
120
+ rspec-support (~> 3.6.0)
121
+ rspec-expectations (3.6.0)
122
+ diff-lcs (>= 1.2.0, < 2.0)
123
+ rspec-support (~> 3.6.0)
124
+ rspec-mocks (3.6.0)
125
+ diff-lcs (>= 1.2.0, < 2.0)
126
+ rspec-support (~> 3.6.0)
127
+ rspec-support (3.6.0)
128
+ sidekiq (4.2.10)
129
+ concurrent-ruby (~> 1.0)
130
+ connection_pool (~> 2.2, >= 2.2.0)
131
+ rack-protection (>= 1.5.0)
132
+ redis (~> 3.2, >= 3.2.1)
133
+ sinatra (1.4.8)
134
+ rack (~> 1.5)
135
+ rack-protection (~> 1.4)
136
+ tilt (>= 1.3, < 3)
137
+ sprockets (3.7.1)
138
+ concurrent-ruby (~> 1.0)
139
+ rack (> 1, < 3)
140
+ sprockets-rails (3.2.0)
141
+ actionpack (>= 4.0)
142
+ activesupport (>= 4.0)
143
+ sprockets (>= 3.0.0)
144
+ thor (0.19.4)
145
+ thread_safe (0.3.6)
146
+ tilt (2.0.7)
147
+ tzinfo (1.2.3)
148
+ thread_safe (~> 0.1)
149
+ vegas (0.1.11)
150
+ rack (>= 1.0.0)
151
+
152
+ PLATFORMS
153
+ ruby
154
+
155
+ DEPENDENCIES
156
+ byebug
157
+ database_cleaner
158
+ delayed_job_active_record
159
+ gemika
160
+ instrumental_agent
161
+ memcached
162
+ metrician!
163
+ mysql2 (= 0.3.17)
164
+ rack-test
165
+ rails (~> 4.2.0)
166
+ rake
167
+ redis
168
+ resque
169
+ rspec (~> 3.4)
170
+ sidekiq (~> 4.0)
171
+
172
+ BUNDLED WITH
173
+ 1.14.6
@@ -0,0 +1,24 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Runtime dependencies
4
+ gem 'rails', '~>5.0.0'
5
+
6
+ # Differentiated development dependencies
7
+ gem 'pg', '~>0.18.4'
8
+ gem 'sidekiq', require: 'sidekiq/testing'
9
+ gem 'rspec', '~>3.5'
10
+
11
+ # Development dependencies
12
+ gem 'instrumental_agent'
13
+ gem 'rake'
14
+ gem 'byebug'
15
+ gem 'gemika'
16
+ gem 'database_cleaner'
17
+ gem 'delayed_job_active_record'
18
+ gem 'resque'
19
+ gem 'redis'
20
+ gem 'dalli'
21
+ gem 'rack-test'
22
+
23
+ # Gem under test
24
+ gem 'metrician', :path => '..'
@@ -0,0 +1,182 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ metrician (0.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ actioncable (5.0.3)
10
+ actionpack (= 5.0.3)
11
+ nio4r (>= 1.2, < 3.0)
12
+ websocket-driver (~> 0.6.1)
13
+ actionmailer (5.0.3)
14
+ actionpack (= 5.0.3)
15
+ actionview (= 5.0.3)
16
+ activejob (= 5.0.3)
17
+ mail (~> 2.5, >= 2.5.4)
18
+ rails-dom-testing (~> 2.0)
19
+ actionpack (5.0.3)
20
+ actionview (= 5.0.3)
21
+ activesupport (= 5.0.3)
22
+ rack (~> 2.0)
23
+ rack-test (~> 0.6.3)
24
+ rails-dom-testing (~> 2.0)
25
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
26
+ actionview (5.0.3)
27
+ activesupport (= 5.0.3)
28
+ builder (~> 3.1)
29
+ erubis (~> 2.7.0)
30
+ rails-dom-testing (~> 2.0)
31
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
32
+ activejob (5.0.3)
33
+ activesupport (= 5.0.3)
34
+ globalid (>= 0.3.6)
35
+ activemodel (5.0.3)
36
+ activesupport (= 5.0.3)
37
+ activerecord (5.0.3)
38
+ activemodel (= 5.0.3)
39
+ activesupport (= 5.0.3)
40
+ arel (~> 7.0)
41
+ activesupport (5.0.3)
42
+ concurrent-ruby (~> 1.0, >= 1.0.2)
43
+ i18n (~> 0.7)
44
+ minitest (~> 5.1)
45
+ tzinfo (~> 1.1)
46
+ arel (7.1.4)
47
+ builder (3.2.3)
48
+ byebug (9.0.6)
49
+ concurrent-ruby (1.0.5)
50
+ connection_pool (2.2.1)
51
+ dalli (2.7.6)
52
+ database_cleaner (1.5.3)
53
+ delayed_job (4.1.3)
54
+ activesupport (>= 3.0, < 5.2)
55
+ delayed_job_active_record (4.1.2)
56
+ activerecord (>= 3.0, < 5.2)
57
+ delayed_job (>= 3.0, < 5)
58
+ diff-lcs (1.3)
59
+ erubis (2.7.0)
60
+ gemika (0.3.2)
61
+ globalid (0.4.0)
62
+ activesupport (>= 4.2.0)
63
+ i18n (0.8.4)
64
+ instrumental_agent (1.0.1)
65
+ loofah (2.0.3)
66
+ nokogiri (>= 1.5.9)
67
+ mail (2.6.5)
68
+ mime-types (>= 1.16, < 4)
69
+ method_source (0.8.2)
70
+ mime-types (3.1)
71
+ mime-types-data (~> 3.2015)
72
+ mime-types-data (3.2016.0521)
73
+ mini_portile2 (2.2.0)
74
+ minitest (5.10.2)
75
+ mono_logger (1.1.0)
76
+ multi_json (1.12.1)
77
+ mustermann (1.0.0)
78
+ nio4r (2.1.0)
79
+ nokogiri (1.8.0)
80
+ mini_portile2 (~> 2.2.0)
81
+ pg (0.18.4)
82
+ rack (2.0.3)
83
+ rack-protection (2.0.0)
84
+ rack
85
+ rack-test (0.6.3)
86
+ rack (>= 1.0)
87
+ rails (5.0.3)
88
+ actioncable (= 5.0.3)
89
+ actionmailer (= 5.0.3)
90
+ actionpack (= 5.0.3)
91
+ actionview (= 5.0.3)
92
+ activejob (= 5.0.3)
93
+ activemodel (= 5.0.3)
94
+ activerecord (= 5.0.3)
95
+ activesupport (= 5.0.3)
96
+ bundler (>= 1.3.0, < 2.0)
97
+ railties (= 5.0.3)
98
+ sprockets-rails (>= 2.0.0)
99
+ rails-dom-testing (2.0.3)
100
+ activesupport (>= 4.2.0)
101
+ nokogiri (>= 1.6)
102
+ rails-html-sanitizer (1.0.3)
103
+ loofah (~> 2.0)
104
+ railties (5.0.3)
105
+ actionpack (= 5.0.3)
106
+ activesupport (= 5.0.3)
107
+ method_source
108
+ rake (>= 0.8.7)
109
+ thor (>= 0.18.1, < 2.0)
110
+ rake (12.0.0)
111
+ redis (3.3.3)
112
+ redis-namespace (1.5.3)
113
+ redis (~> 3.0, >= 3.0.4)
114
+ resque (1.27.4)
115
+ mono_logger (~> 1.0)
116
+ multi_json (~> 1.0)
117
+ redis-namespace (~> 1.3)
118
+ sinatra (>= 0.9.2)
119
+ vegas (~> 0.1.2)
120
+ rspec (3.6.0)
121
+ rspec-core (~> 3.6.0)
122
+ rspec-expectations (~> 3.6.0)
123
+ rspec-mocks (~> 3.6.0)
124
+ rspec-core (3.6.0)
125
+ rspec-support (~> 3.6.0)
126
+ rspec-expectations (3.6.0)
127
+ diff-lcs (>= 1.2.0, < 2.0)
128
+ rspec-support (~> 3.6.0)
129
+ rspec-mocks (3.6.0)
130
+ diff-lcs (>= 1.2.0, < 2.0)
131
+ rspec-support (~> 3.6.0)
132
+ rspec-support (3.6.0)
133
+ sidekiq (5.0.0)
134
+ concurrent-ruby (~> 1.0)
135
+ connection_pool (~> 2.2, >= 2.2.0)
136
+ rack-protection (>= 1.5.0)
137
+ redis (~> 3.3, >= 3.3.3)
138
+ sinatra (2.0.0)
139
+ mustermann (~> 1.0)
140
+ rack (~> 2.0)
141
+ rack-protection (= 2.0.0)
142
+ tilt (~> 2.0)
143
+ sprockets (3.7.1)
144
+ concurrent-ruby (~> 1.0)
145
+ rack (> 1, < 3)
146
+ sprockets-rails (3.2.0)
147
+ actionpack (>= 4.0)
148
+ activesupport (>= 4.0)
149
+ sprockets (>= 3.0.0)
150
+ thor (0.19.4)
151
+ thread_safe (0.3.6)
152
+ tilt (2.0.7)
153
+ tzinfo (1.2.3)
154
+ thread_safe (~> 0.1)
155
+ vegas (0.1.11)
156
+ rack (>= 1.0.0)
157
+ websocket-driver (0.6.5)
158
+ websocket-extensions (>= 0.1.0)
159
+ websocket-extensions (0.1.2)
160
+
161
+ PLATFORMS
162
+ ruby
163
+
164
+ DEPENDENCIES
165
+ byebug
166
+ dalli
167
+ database_cleaner
168
+ delayed_job_active_record
169
+ gemika
170
+ instrumental_agent
171
+ metrician!
172
+ pg (~> 0.18.4)
173
+ rack-test
174
+ rails (~> 5.0.0)
175
+ rake
176
+ redis
177
+ resque
178
+ rspec (~> 3.5)
179
+ sidekiq
180
+
181
+ BUNDLED WITH
182
+ 1.15.1
@@ -0,0 +1,80 @@
1
+ require "metrician/configuration"
2
+ require "metrician/reporter"
3
+ require "metrician/jobs"
4
+ require "metrician/middleware"
5
+
6
+ module Metrician
7
+
8
+ AgentNotInitialized = Class.new(StandardError)
9
+ MissingAgent = Class.new(ArgumentError)
10
+ IncompatibleAgent = Class.new(ArgumentError)
11
+
12
+ REQUIRED_AGENT_METHODS = [
13
+ :cleanup,
14
+ :gauge,
15
+ :increment,
16
+ :logger,
17
+ "logger=".to_sym,
18
+ ]
19
+
20
+ def self.activate(agent)
21
+ self.agent = agent
22
+ Metrician::Reporter.all.each(&:instrument)
23
+ end
24
+
25
+ def self.agent=(agent)
26
+ if agent.nil?
27
+ raise MissingAgent.new
28
+ end
29
+
30
+ REQUIRED_AGENT_METHODS.each do |method|
31
+ raise IncompatibleAgent.new("agent must implement #{method}") unless agent.respond_to?(method)
32
+ end
33
+
34
+ @agent = agent
35
+ end
36
+
37
+ def self.agent
38
+ @agent || raise(AgentNotInitialized.new)
39
+ end
40
+
41
+ def self.logger=(logger)
42
+ agent.logger = logger
43
+ end
44
+
45
+ def self.logger
46
+ agent.logger
47
+ end
48
+
49
+ def self.dotify(klass)
50
+ klass.to_s.underscore.gsub(%r{/}, ".")
51
+ end
52
+
53
+ # TODO: consider removal/movement to Instrumental Agent
54
+ def self.prefix=(prefix)
55
+ @prefix = prefix.to_s[-1] == "." ? prefix.to_s : "#{prefix}."
56
+ end
57
+
58
+ # TODO: consider removal/movement to Instrumental Agent
59
+ def self.prefix
60
+ @prefix || ""
61
+ end
62
+
63
+ # TODO: consider removal/movement to Instrumental Agent
64
+ def self.prefixed?
65
+ @prefixed ||= !prefix.empty?
66
+ end
67
+
68
+ def self.increment(metric, value = 1)
69
+ prefixed? ? agent.increment("#{prefix}#{metric}", value) : agent.increment(metric, value)
70
+ end
71
+
72
+ # TODO: add block form
73
+ def self.gauge(metric, value)
74
+ prefixed? ? agent.gauge("#{prefix}#{metric}", value) : agent.gauge(metric, value)
75
+ end
76
+
77
+ def self.configuration
78
+ @configuration ||= Metrician::Configuration.load
79
+ end
80
+ end