hallmonitor 5.0.0 → 5.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 54c0631a67fb95ae8201691fdd5e5e12c09936f1
4
- data.tar.gz: d0dddea0967b40bfeea62612157649eeef033711
3
+ metadata.gz: 91292eab2c111a361683e82dde2bff423c1db242
4
+ data.tar.gz: 7c8b9deb17ff9fa07c86b27b55ce2ba86ea45d2a
5
5
  SHA512:
6
- metadata.gz: 0e314315927b4dbaa450022ac88e054ff6e1e230a5f81db0930cab21e54c7e28d20d3521d17cce6671897f1837f8ad7a400409038f7e0a2e8e34e4da4e721045
7
- data.tar.gz: 193b9d428e2cca3a95618f5a8b77853fefd8194673f2bf83ef8937326c05c0c47ad667c5328372a99845c4ae862b4f6acf948a77ec1e64b8de9e3721ceff5349
6
+ metadata.gz: de4981e3e0bdb1b4ae7ee75ea2d477fd5a0bce7582db2a088c6063513928e884f312e854ff33bd11de397bd933f6bfc18975bfed4b8eea6e18fde0483ca08cf9
7
+ data.tar.gz: 80449291d9b3c367be0271ad42499b811a26ad95a065725e0a3c3d041faa00bea077e75127d04413a78beb3ce951d89106382723b19965067f4eea9993ce6722
data/README.md CHANGED
@@ -30,22 +30,49 @@ Hallmonitor.add_outputter Hallmonitor::Outputters::Datadog.new(datadog)
30
30
  ```
31
31
 
32
32
  ## Configuration
33
- Right now there's only one configuration option and here's how you can set it:
33
+ There are a few configuration options, two of which are only
34
+ applicable when used within rails. You can configure their values like so:
34
35
 
35
36
  ```ruby
36
37
  # Configure Hallmonitor
37
38
  Hallmonitor.config |config|
38
39
  config.trap_outputter_exceptions = true # Default value is false
40
+ config.instrument_rails_controller_actions = true # Default value is false
41
+ config.controller_action_measure_name = 'controller.action.measure' # this is the default
42
+ config.controller_action_count_name = 'controller.action.count' # this is the default
39
43
  end
40
44
  ```
41
45
 
42
- **trap_outputter_exceptions:** instructs the output framework to ignore and squash any exceptions that might be raised from inside an outputter. This can be useful if you want to configure multiple outputter and not have a misbehaving one interrupt other outputter, or your system.
46
+ * **trap_outputter_exceptions:** instructs the output framework to ignore and squash any exceptions that might be raised from inside an outputter. This can be useful if you want to configure multiple outputter and not have a misbehaving one interrupt other outputter, or your system.
47
+ * **instrument_rails_controller_actions:** Whether or not to auto instrument rails controller actions, defaults to false
48
+ * **controller_action_measure_name:** the metric name to use for the auto-instrumented metric for rails actions that include time measurements
49
+ * **controller_action_count_name:** the metric name to use for the auto-instrumented metric for rails actions that tracks action invocation counts
43
50
 
44
51
  ## Usage
45
52
 
46
53
  There are a few different ways to use Hallmonitor:
47
54
 
55
+ ## Rails Autoinstrumentation
56
+
57
+ If `config.instrument_rails_controller_actions` is true, and Rails is
58
+ defined Hallmonitor will define a Railtie that auto-instruments all
59
+ rails controller actions to collect execution duration and count
60
+ information. You can see details of the metrics gathered in the
61
+ `hallmonitor/railtie.rb` file.
62
+
63
+ You can configure the metric names that are used via the
64
+ `config.controller_action_measure_name` and
65
+ `config.controller_action_count_name` configuration directives.
66
+
67
+
48
68
  ### Included in your class
69
+
70
+ The easiest way is to include `Hallmonitor::Monitored` in your class
71
+ and use its `emit(...)` and `watch(...)` methods. `emit` emits a
72
+ single count metric with a name and optional tags, while `watch`
73
+ executes the provided block and emits a `Hallmonitor::TimedEvent` with
74
+ the duration that the block took to execute.
75
+
49
76
  ```ruby
50
77
  class Foo
51
78
  # Monitored adds a few methods you can use, like emit(...) and watch(...)
@@ -53,7 +80,6 @@ class Foo
53
80
 
54
81
  # This method will emit 100 events
55
82
  def bar
56
-
57
83
  # Emit 100 events. The string will be the name of the Event object that gets emitted
58
84
  100.times do
59
85
  emit("event") # Will emit a new Event with the name 'event'
@@ -82,16 +108,19 @@ foo.time_me # Will emit a single TimedEvent
82
108
  ```
83
109
 
84
110
  ### Explicit Event objects
111
+
112
+ You can also construct and manually emit a `Hallmonitor::Event` object
113
+ if you need to:
114
+
85
115
  ```ruby
86
- # Event objects include Hallmonitor::Monitored and so they have
87
- # an emit method of their own
88
116
  event = Hallmonitor::Event.new("event")
89
117
  event.emit
90
118
  ```
91
119
 
92
120
  ## Contributing to Hallmonitor
93
121
 
94
- * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
122
+ * Check out the latest master to make sure the feature hasn't been
123
+ implemented or the bug hasn't been fixed yet.
95
124
  * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
96
125
  * Fork the project.
97
126
  * Start a feature/bugfix branch.
data/lib/hallmonitor.rb CHANGED
@@ -6,25 +6,30 @@ require 'hallmonitor/timed_event'
6
6
  require 'hallmonitor/gauge_event'
7
7
  require 'hallmonitor/outputter'
8
8
  require 'hallmonitor/middleware'
9
+ require 'hallmonitor/railtie' if defined?(Rails)
9
10
 
11
+ # Top-level module, allows for configuration
10
12
  module Hallmonitor
11
13
  class << self
12
- attr_accessor :config
13
- end
14
+ # @return {Hallmonitor::Configuration} instance
15
+ def config
16
+ @config ||= Hallmonitor::Configuration.new
17
+ end
14
18
 
15
- # Method to configure Hallmonitor, takes a block and passes a
16
- # {Hallmonitor::Configuration} object in, which can be used to
17
- # set configuration options.
18
- def self.configure
19
- self.config ||= Hallmonitor::Configuration.new
20
- yield(config)
21
- end
19
+ # Method to configure Hallmonitor, takes a block and passes a
20
+ # {Hallmonitor::Configuration} object in, which can be used to
21
+ # set configuration options.
22
+ def configure
23
+ yield(config)
24
+ end
22
25
 
23
- # Adds an outputter to Hallmonitor. Whenever events are emitted
24
- # they will be sent to all registered outputters
25
- # @param outputter [Outputter] An instance of an outputter
26
- # @note This delegates to {Dispatcher.add_outputter}
27
- def self.add_outputter(outputter)
28
- Dispatcher.add_outputter(outputter)
26
+ # Adds an outputter to Hallmonitor. Whenever events are emitted
27
+ # they will be sent to all registered outputters
28
+ #
29
+ # @param outputter [Outputter] An instance of an outputter
30
+ # @note This delegates to {Dispatcher.add_outputter}
31
+ def add_outputter(outputter)
32
+ Dispatcher.add_outputter(outputter)
33
+ end
29
34
  end
30
35
  end
@@ -4,8 +4,22 @@ module Hallmonitor
4
4
  # Whether or not to trap outputter exceptions, defaults to false
5
5
  attr_accessor :trap_outputter_exceptions
6
6
 
7
+ # Whether or not to autoinstrument rails controller actions, defaults to false
8
+ attr_accessor :instrument_rails_controller_actions
9
+
10
+ # The metric name to use for controller action measurements,
11
+ # defaults to 'controller.action.measure'
12
+ attr_accessor :controller_action_measure_name
13
+
14
+ # The metric name to use for controller action counts, defaults to
15
+ # 'controller.action.measure'
16
+ attr_accessor :controller_action_count_name
17
+
7
18
  def initialize
8
19
  @trap_outputter_exceptions = false
20
+ @controller_action_measure_name = 'controller.action.measure'
21
+ @controller_action_count_name = 'controller.action.count'
22
+ @instrument_rails_controller_actions = false
9
23
  end
10
24
  end
11
25
  end
@@ -0,0 +1,72 @@
1
+ module Hallmonitor
2
+ # Auto-instruments Rails ActionController actions to collect metrics
3
+ # about their behavior
4
+ class Railtie < Rails::Railtie
5
+ config.after_initialize do
6
+ if Hallmonitor.config.instrument_rails_controller_actions
7
+ Hallmonitor::Railtie.enable_action_controller_metrics
8
+ end
9
+ end
10
+
11
+ def self.enable_action_controller_metrics
12
+ # See https://guides.rubyonrails.org/active_support_instrumentation.html#process-action-action-controller
13
+ # for information on this notification
14
+ ActiveSupport::Notifications.subscribe(/process_action.action_controller/) do |*args|
15
+ begin
16
+ event_args = parse_process_action_payload(args)
17
+
18
+ tags = {
19
+ controller: event_args[:controller],
20
+ action: event_args[:action],
21
+ status_code: event_args[:status]
22
+ }
23
+
24
+ Hallmonitor::TimedEvent.new(
25
+ 'controller.action.measure',
26
+ duration: {
27
+ total: event_args[:total_duration],
28
+ database: event_args[:db_time],
29
+ view: event_args[:view_time]
30
+ },
31
+ tags: tags
32
+ ).emit
33
+
34
+ Hallmonitor::Event.new('controller.action.count', tags: tags).emit
35
+ rescue => ex
36
+ Rails.logger.error("Caught error in Telemeter: #{ex.message}", ex)
37
+ end
38
+ end
39
+ end
40
+
41
+ # example args
42
+ # ["process_action.action_controller",
43
+ # 2013-11-22 11:17:04 -0600,
44
+ # 2013-11-22 11:17:04 -0600,
45
+ # "6a1302819619cb089922",
46
+ # {:controller=>"BranchesController",
47
+ # :action=>"index",
48
+ # :params=>{"action"=>"index", "controller"=>"branches"},
49
+ # :format=>:html,
50
+ # :method=>"GET",
51
+ # :path=>"/branches",
52
+ # :status=>200,
53
+ # :view_runtime=>0.06999999999999999}]
54
+ def self.parse_process_action_payload(args)
55
+ parsed_arguments = {}
56
+ rails_payload = args[4]
57
+
58
+ parsed_arguments[:total_duration] = 1000.0 * (args[2] - args[1])
59
+ parsed_arguments[:view_time] = rails_payload[:view_runtime] || 0
60
+ parsed_arguments[:db_time] = rails_payload[:db_runtime] || 0
61
+ parsed_arguments[:status] = rails_payload[:status]
62
+ parsed_arguments[:controller] = rails_payload[:controller]
63
+ parsed_arguments[:action] = rails_payload[:action]
64
+ parsed_arguments[:format] = rails_payload[:format] || 'all'
65
+ parsed_arguments[:format] = 'all' if parsed_arguments[:format] == '*/*'
66
+
67
+ parsed_arguments
68
+ end
69
+
70
+
71
+ end
72
+ end
@@ -1,7 +1,7 @@
1
1
  module Hallmonitor
2
2
  module Version
3
3
  MAJOR = 5
4
- MINOR = 0
4
+ MINOR = 1
5
5
  PATCH = 0
6
6
  BUILD = nil
7
7
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hallmonitor
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.0
4
+ version: 5.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris TenHarmsel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-10 00:00:00.000000000 Z
11
+ date: 2018-09-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -172,6 +172,7 @@ files:
172
172
  - lib/hallmonitor/outputters/iooutputter.rb
173
173
  - lib/hallmonitor/outputters/new_relic.rb
174
174
  - lib/hallmonitor/outputters/statsd_outputter.rb
175
+ - lib/hallmonitor/railtie.rb
175
176
  - lib/hallmonitor/timed_event.rb
176
177
  - lib/hallmonitor/version.rb
177
178
  - spec/hallmonitor/dispatcher_spec.rb