netuitive_rails_agent 0.10.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +18 -8
- data/config/agent.yml +36 -1
- data/lib/netuitive_rails_agent.rb +43 -17
- data/lib/netuitive_rails_agent/action_controller.rb +97 -0
- data/lib/netuitive_rails_agent/action_mailer.rb +29 -0
- data/lib/netuitive_rails_agent/action_view.rb +25 -0
- data/lib/netuitive_rails_agent/active_job.rb +25 -0
- data/lib/netuitive_rails_agent/active_record.rb +26 -0
- data/lib/netuitive_rails_agent/active_support.rb +46 -0
- data/lib/netuitive_rails_agent/api_interaction.rb +43 -0
- data/lib/netuitive_rails_agent/config_manager.rb +124 -0
- data/lib/netuitive_rails_agent/controller_utils.rb +17 -0
- data/lib/netuitive_rails_agent/error_tracker.rb +33 -0
- data/lib/netuitive_rails_agent/error_utils.rb +41 -0
- data/lib/netuitive_rails_agent/gc.rb +33 -0
- data/lib/netuitive_rails_agent/netuitive_logger.rb +49 -0
- data/lib/netuitive_rails_agent/objectspace.rb +19 -0
- data/lib/netuitive_rails_agent/request_data.rb +50 -0
- data/lib/netuitive_rails_agent/scheduler.rb +44 -0
- data/lib/netuitive_rails_agent/sidekiq.rb +67 -0
- metadata +23 -17
- data/lib/netuitive/action_controller.rb +0 -81
- data/lib/netuitive/action_mailer.rb +0 -22
- data/lib/netuitive/action_view.rb +0 -18
- data/lib/netuitive/active_job.rb +0 -18
- data/lib/netuitive/active_record.rb +0 -19
- data/lib/netuitive/active_support.rb +0 -39
- data/lib/netuitive/gc.rb +0 -23
- data/lib/netuitive/netuitive_rails_logger.rb +0 -24
- data/lib/netuitive/objectspace.rb +0 -13
- data/lib/netuitive/rails_config_manager.rb +0 -29
- data/lib/netuitive/scheduler.rb +0 -23
data/README.md
CHANGED
@@ -1,11 +1,21 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
Netuitive Rails Agent
|
2
|
+
======================
|
3
3
|
|
4
|
-
|
5
|
-
netuitived must be running
|
4
|
+
The Netuitive Rails Agent creates default rails metrics to be sent to NetuitiveD using the netuitive_ruby_api gem. The Netuitive Rails Agent is meant to work in conjunction with the [netuitive_ruby_api](https://rubygems.org/gems/netuitive_ruby_api) gem and NetuitiveD to help [Netuitive](https://www.netuitive.com) monitor your Ruby applications.
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
For more information on the Netuitive Rails Agent, see our Ruby agent [help docs](https://help.netuitive.com/Content/Misc/Datasources/new_ruby_datasource.htm), or contact Netuitive support at [support@netuitive.com](mailto:support@netuitive.com).
|
7
|
+
|
8
|
+
Requirements
|
9
|
+
-------------
|
10
|
+
|
11
|
+
[NetuitiveD](https://github.com/Netuitive/netuitived) must be installed and running.
|
12
|
+
|
13
|
+
Installing the Netuitive Rails Agent
|
14
|
+
-------------------------------------
|
15
|
+
|
16
|
+
1. Add `gem 'netuitive_rails_agent'` to your Gemfile.
|
17
|
+
|
18
|
+
2. Run `bundle install`.
|
19
|
+
|
20
|
+
3. Restart your rails app.
|
11
21
|
|
data/config/agent.yml
CHANGED
@@ -1,2 +1,37 @@
|
|
1
1
|
#all are configurable using environment variables
|
2
|
-
|
2
|
+
|
3
|
+
#log config options
|
4
|
+
logLocation: #NETUITIVE_RAILS_LOG_LOCATION absolute path of log file. leave blank for default location in the gem directory.
|
5
|
+
logAge: daily #NETUITIVE_RAILS_LOG_AGE Number of old log files to keep, or frequency of rotation (daily, weekly or monthly).
|
6
|
+
logSize: #NETUITIVE_RAILS_LOG_SIZE Maximum logfile size in bytes(only applies when shift_age is a number).
|
7
|
+
debugLevel: error #NETUITIVE_RAILS_DEBUG_LEVEL options (in ascending order of debugness) are: error, info, debug.
|
8
|
+
|
9
|
+
#feature flags
|
10
|
+
#active support nptifications
|
11
|
+
actionControllerEnabled: true #NETUITIVE_RAILS_ACTION_CONTROLLER_ENABLED
|
12
|
+
activeRecordEnabled: true #NETUITIVE_RAILS_ACTIVE_RECORD_ENABLED
|
13
|
+
actionViewEnabled: true #NETUITIVE_RAILS_ACTION_VIEW_ENABLED
|
14
|
+
actionMailerEnabled: true #NETUITIVE_RAILS_ACTION_MAILER_ENABLED
|
15
|
+
activeSupportEnabled: true #NETUITIVE_RAILS_ACTIVE_SUPPORT_ENABLED
|
16
|
+
activeJobEnabled: true #NETUITIVE_RAILS_ACTIVE_JOB_ENABLED
|
17
|
+
#injected instrumentation
|
18
|
+
requestWrapperEnabled: true #NETUITIVE_RAILS_REQUEST_WRAPPER_ENABLED
|
19
|
+
actionErrorsEnabled: true #NETUITIVE_RAILS_ACTION_ERRORS_ENABLED
|
20
|
+
#interpreter metrics
|
21
|
+
gcEnabled: true #NETUITIVE_RAILS_GC_ENABLED
|
22
|
+
objectSpaceEnabled: true #NETUITIVE_RAILS_OBJECT_SPACE_ENABLED
|
23
|
+
#3rd party
|
24
|
+
sidekiqEnabled: false #NETUITIVE_RAILS_SIDEKIQ_ENABLED toggle for collection of sidekiq metrics and errors. error events will not be sent if sendErrorEvents is set to false.
|
25
|
+
#error tracking features
|
26
|
+
sendErrorEvents: false #NETUITIVE_RAILS_SEND_ERROR_EVENTS toggle for sending exceptions to netuitived for export as external events.
|
27
|
+
|
28
|
+
#feature configs
|
29
|
+
queueTimeUnits: 1 #NETUITIVE_RAILS_QUEUE_TIME_UNITS this is the divisor required to get the queue time metric into seconds. examples: seconds: 1, milliseconds: 1000, microseconds: 1000000.
|
30
|
+
ignoredErrors: #NETUITIVE_RAILS_IGNORED_ERRORS list of exceptions to ignore. should be provided in the following yaml format:
|
31
|
+
#ignoredErrors:
|
32
|
+
# - RuntimeError
|
33
|
+
# - ArgumentError
|
34
|
+
#or the following env argument format: NETUITIVE_RAILS_IGNORED_ERRORS=RuntimeError,ArgumentError
|
35
|
+
#to ignore exceptions that match against an ancestor, add "^" to the exception class.
|
36
|
+
#Example: NETUITIVE_RAILS_IGNORED_ERRORS=RuntimeError^
|
37
|
+
#will ignore all errors that inherit from RuntimeError
|
@@ -1,20 +1,46 @@
|
|
1
|
+
require 'logger'
|
2
|
+
require 'active_support'
|
3
|
+
require 'action_controller'
|
4
|
+
require 'action_mailer'
|
5
|
+
require 'active_support/concern'
|
1
6
|
require 'netuitive_ruby_api'
|
2
|
-
require '
|
3
|
-
require '
|
4
|
-
require 'netuitive/active_record'
|
5
|
-
require 'netuitive/action_view'
|
6
|
-
require 'netuitive/action_mailer'
|
7
|
-
require 'netuitive/active_support'
|
8
|
-
require 'netuitive/active_job'
|
9
|
-
require 'netuitive/rails_config_manager'
|
10
|
-
require 'netuitive/scheduler'
|
7
|
+
require 'netuitive_rails_agent/config_manager'
|
8
|
+
require 'netuitive_rails_agent/netuitive_logger'
|
11
9
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
NetuitiveActiveSupportSub::subscribe
|
17
|
-
NetuitiveActiveJobSub::subscribe
|
10
|
+
# load config and logger
|
11
|
+
NetuitiveRailsAgent::ConfigManager.load_config
|
12
|
+
NetuitiveRailsAgent::NetuitiveLogger.setup
|
13
|
+
NetuitiveRailsAgent::ConfigManager.read_config
|
18
14
|
|
19
|
-
|
20
|
-
|
15
|
+
require 'netuitive_rails_agent/api_interaction'
|
16
|
+
require 'netuitive_rails_agent/controller_utils'
|
17
|
+
require 'netuitive_rails_agent/error_utils'
|
18
|
+
require 'netuitive_rails_agent/error_tracker'
|
19
|
+
require 'netuitive_rails_agent/request_data'
|
20
|
+
require 'netuitive_rails_agent/action_controller'
|
21
|
+
require 'netuitive_rails_agent/active_record'
|
22
|
+
require 'netuitive_rails_agent/action_view'
|
23
|
+
require 'netuitive_rails_agent/action_mailer'
|
24
|
+
require 'netuitive_rails_agent/active_support'
|
25
|
+
require 'netuitive_rails_agent/active_job'
|
26
|
+
require 'netuitive_rails_agent/sidekiq'
|
27
|
+
require 'netuitive_rails_agent/gc'
|
28
|
+
require 'netuitive_rails_agent/objectspace'
|
29
|
+
require 'netuitive_rails_agent/scheduler'
|
30
|
+
|
31
|
+
# subscribe to notifications
|
32
|
+
interaction = NetuitiveRailsAgent::ApiInteraction.new
|
33
|
+
NetuitiveRailsAgent::ActionControllerSub.new(interaction).subscribe if NetuitiveRailsAgent::ConfigManager.action_controller_enabled
|
34
|
+
NetuitiveRailsAgent::ActiveRecordSub.new(interaction).subscribe if NetuitiveRailsAgent::ConfigManager.active_record_enabled
|
35
|
+
NetuitiveRailsAgent::ActionViewSub.new(interaction).subscribe if NetuitiveRailsAgent::ConfigManager.action_view_enabled
|
36
|
+
NetuitiveRailsAgent::ActionMailerSub.new(interaction).subscribe if NetuitiveRailsAgent::ConfigManager.action_mailer_enabled
|
37
|
+
NetuitiveRailsAgent::ActiveSupportSub.new(interaction).subscribe if NetuitiveRailsAgent::ConfigManager.active_support_enabled
|
38
|
+
NetuitiveRailsAgent::ActiveJobSub.new(interaction).subscribe if NetuitiveRailsAgent::ConfigManager.active_job_enabled
|
39
|
+
|
40
|
+
# start metrics that are collected on a schedule
|
41
|
+
NetuitiveRailsAgent::Scheduler.new(interaction).start_schedule if NetuitiveRailsAgent::ConfigManager.gc_enabled || NetuitiveRailsAgent::ConfigManager.object_space_enabled
|
42
|
+
|
43
|
+
# sidekiq
|
44
|
+
NetuitiveRailsAgent::SidekiqTracker.new.setup if NetuitiveRailsAgent::ConfigManager.sidekiq_enabled
|
45
|
+
|
46
|
+
NetuitiveRailsAgent::NetuitiveLogger.log.info 'Netuitive rails agent installed'
|
@@ -0,0 +1,97 @@
|
|
1
|
+
ActionController::Base.class_eval do
|
2
|
+
include NetuitiveRailsAgent::ErrorTrackerHook if NetuitiveRailsAgent::ConfigManager.action_errors_enabled
|
3
|
+
if NetuitiveRailsAgent::ConfigManager.request_wrapper_enabled
|
4
|
+
include NetuitiveRailsAgent::RequestDataHook
|
5
|
+
before_action :netuitive_request_hook
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
module NetuitiveRailsAgent
|
10
|
+
class ActionControllerSub
|
11
|
+
attr_reader :interaction
|
12
|
+
|
13
|
+
def initialize(interaction)
|
14
|
+
@interaction = interaction
|
15
|
+
end
|
16
|
+
|
17
|
+
def subscribe
|
18
|
+
ActiveSupport::Notifications.subscribe(/process_action.action_controller/) do |*args|
|
19
|
+
process_action(*args)
|
20
|
+
end
|
21
|
+
ActiveSupport::Notifications.subscribe(/write_fragment.action_controller/) do |*_args|
|
22
|
+
write_fragment
|
23
|
+
end
|
24
|
+
ActiveSupport::Notifications.subscribe(/read_fragment.action_controller/) do |*_args|
|
25
|
+
read_fragment
|
26
|
+
end
|
27
|
+
ActiveSupport::Notifications.subscribe(/expire_fragment.action_controller/) do |*_args|
|
28
|
+
expire_fragment
|
29
|
+
end
|
30
|
+
ActiveSupport::Notifications.subscribe(/write_page.action_controller/) do |*_args|
|
31
|
+
write_page
|
32
|
+
end
|
33
|
+
ActiveSupport::Notifications.subscribe(/expire_page.action_controller/) do |*_args|
|
34
|
+
expire_page
|
35
|
+
end
|
36
|
+
ActiveSupport::Notifications.subscribe(/send_file.action_controller/) do |*_args|
|
37
|
+
send_file
|
38
|
+
end
|
39
|
+
ActiveSupport::Notifications.subscribe(/redirect_to.action_controller/) do |*_args|
|
40
|
+
redirect_to
|
41
|
+
end
|
42
|
+
ActiveSupport::Notifications.subscribe(/halted_callback.action_controller/) do |*_args|
|
43
|
+
halted_callback
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def process_action(*args)
|
48
|
+
event = ActiveSupport::Notifications::Event.new(*args)
|
49
|
+
controller = event.payload[:controller].to_s
|
50
|
+
action = event.payload[:action].to_s
|
51
|
+
interaction.add_sample("action_controller.#{controller}.#{action}.request.total_duration", event.duration)
|
52
|
+
interaction.add_sample("action_controller.#{controller}.#{action}.request.query_time", event.payload[:db_runtime])
|
53
|
+
interaction.add_sample("action_controller.#{controller}.#{action}.request.view_time", event.payload[:view_runtime])
|
54
|
+
interaction.add_sample("action_controller.#{controller}.request.total_duration", event.duration)
|
55
|
+
interaction.add_sample("action_controller.#{controller}.request.query_time", event.payload[:db_runtime])
|
56
|
+
interaction.add_sample("action_controller.#{controller}.request.view_time", event.payload[:view_runtime])
|
57
|
+
interaction.add_sample('action_controller.request.total_duration', event.duration)
|
58
|
+
interaction.add_sample('action_controller.request.query_time', event.payload[:db_runtime])
|
59
|
+
interaction.add_sample('action_controller.request.view_time', event.payload[:view_runtime])
|
60
|
+
interaction.aggregate_metric("action_controller.#{controller}.#{action}.total_requests", 1)
|
61
|
+
interaction.aggregate_metric("action_controller.#{controller}.total_requests", 1)
|
62
|
+
interaction.aggregate_metric('action_controller.total_requests', 1)
|
63
|
+
end
|
64
|
+
|
65
|
+
def write_fragment
|
66
|
+
interaction.aggregate_metric('action_controller.write_fragment', 1)
|
67
|
+
end
|
68
|
+
|
69
|
+
def read_fragment
|
70
|
+
interaction.aggregate_metric('action_controller.read_fragment', 1)
|
71
|
+
end
|
72
|
+
|
73
|
+
def expire_fragment
|
74
|
+
interaction.aggregate_metric('action_controller.expire_fragment', 1)
|
75
|
+
end
|
76
|
+
|
77
|
+
def write_page
|
78
|
+
interaction.aggregate_metric('action_controller.write_page', 1)
|
79
|
+
end
|
80
|
+
|
81
|
+
def expire_page
|
82
|
+
interaction.aggregate_metric('action_controller.expire_page', 1)
|
83
|
+
end
|
84
|
+
|
85
|
+
def send_file
|
86
|
+
interaction.aggregate_metric('action_controller.sent_file', 1)
|
87
|
+
end
|
88
|
+
|
89
|
+
def redirect_to
|
90
|
+
interaction.aggregate_metric('action_controller.redirect', 1)
|
91
|
+
end
|
92
|
+
|
93
|
+
def halted_callback
|
94
|
+
interaction.aggregate_metric('action_controller.halted_callback', 1)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module NetuitiveRailsAgent
|
2
|
+
class ActionMailerSub
|
3
|
+
attr_reader :interaction
|
4
|
+
def initialize(interaction)
|
5
|
+
@interaction = interaction
|
6
|
+
end
|
7
|
+
|
8
|
+
def subscribe
|
9
|
+
ActiveSupport::Notifications.subscribe(/receive.action_mailer/) do |*args|
|
10
|
+
receive(args)
|
11
|
+
end
|
12
|
+
ActiveSupport::Notifications.subscribe(/deliver.action_mailer/) do |*args|
|
13
|
+
deliver(args)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def receive(*args)
|
18
|
+
event = ActiveSupport::Notifications::Event.new(*args)
|
19
|
+
mailer = event.payload[:mailer].to_s
|
20
|
+
interaction.aggregate_metric("action_mailer.#{mailer}.receive", 1)
|
21
|
+
end
|
22
|
+
|
23
|
+
def deliver(*args)
|
24
|
+
event = ActiveSupport::Notifications::Event.new(*args)
|
25
|
+
mailer = event.payload[:mailer].to_s
|
26
|
+
interaction.aggregate_metric("action_mailer.#{mailer}.deliver", 1)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module NetuitiveRailsAgent
|
2
|
+
class ActionViewSub
|
3
|
+
attr_reader :interaction
|
4
|
+
def initialize(interaction)
|
5
|
+
@interaction = interaction
|
6
|
+
end
|
7
|
+
|
8
|
+
def subscribe
|
9
|
+
ActiveSupport::Notifications.subscribe(/render_template.action_view/) do |*_args|
|
10
|
+
render_template
|
11
|
+
end
|
12
|
+
ActiveSupport::Notifications.subscribe(/render_partial.action_view/) do |*_args|
|
13
|
+
render_partial
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def render_template
|
18
|
+
interaction.aggregate_metric('action_view.render_template', 1)
|
19
|
+
end
|
20
|
+
|
21
|
+
def render_partial
|
22
|
+
interaction.aggregate_metric('action_view.render_partial', 1)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module NetuitiveRailsAgent
|
2
|
+
class ActiveJobSub
|
3
|
+
attr_reader :interaction
|
4
|
+
def initialize(interaction)
|
5
|
+
@interaction = interaction
|
6
|
+
end
|
7
|
+
|
8
|
+
def subscribe
|
9
|
+
ActiveSupport::Notifications.subscribe(/enqueue.active_job/) do |*_args|
|
10
|
+
enqueue
|
11
|
+
end
|
12
|
+
ActiveSupport::Notifications.subscribe(/perform.active_job/) do |*_args|
|
13
|
+
perform
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def enqueue
|
18
|
+
interaction.aggregate_metric('active_job.enqueue', 1)
|
19
|
+
end
|
20
|
+
|
21
|
+
def perform
|
22
|
+
interaction.aggregate_metric('active_job.perform', 1)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module NetuitiveRailsAgent
|
2
|
+
class ActiveRecordSub
|
3
|
+
attr_reader :interaction
|
4
|
+
def initialize(interaction)
|
5
|
+
@interaction = interaction
|
6
|
+
end
|
7
|
+
|
8
|
+
def subscribe
|
9
|
+
ActiveSupport::Notifications.subscribe(/instantiation.active_record/) do |*_args|
|
10
|
+
instantiation
|
11
|
+
end
|
12
|
+
|
13
|
+
ActiveSupport::Notifications.subscribe(/sql.active_record/) do |*_args|
|
14
|
+
sql
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def instantiation
|
19
|
+
interaction.aggregate_metric('active_record.instantiation', 1)
|
20
|
+
end
|
21
|
+
|
22
|
+
def sql
|
23
|
+
interaction.aggregate_metric('active_record.sql.statement', 1)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module NetuitiveRailsAgent
|
2
|
+
class ActiveSupportSub
|
3
|
+
attr_reader :interaction
|
4
|
+
def initialize(interaction)
|
5
|
+
@interaction = interaction
|
6
|
+
end
|
7
|
+
|
8
|
+
def subscribe
|
9
|
+
ActiveSupport::Notifications.subscribe(/cache_read.active_support/) do |*_args|
|
10
|
+
cache_read
|
11
|
+
end
|
12
|
+
ActiveSupport::Notifications.subscribe(/cache_generate.active_support/) do |*_args|
|
13
|
+
cache_generate
|
14
|
+
end
|
15
|
+
ActiveSupport::Notifications.subscribe(/cache_fetch_hit.active_support/) do |*_args|
|
16
|
+
cache_fetch_hit
|
17
|
+
end
|
18
|
+
ActiveSupport::Notifications.subscribe(/cache_write.active_support/) do |*_args|
|
19
|
+
cache_write
|
20
|
+
end
|
21
|
+
ActiveSupport::Notifications.subscribe(/cache_delete.active_support/) do |*_args|
|
22
|
+
cache_delete
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def cache_read
|
27
|
+
interaction.aggregate_metric('active_support.cache_read', 1)
|
28
|
+
end
|
29
|
+
|
30
|
+
def cache_generate
|
31
|
+
interaction.aggregate_metric('active_support.cache_generate', 1)
|
32
|
+
end
|
33
|
+
|
34
|
+
def cache_fetch_hit
|
35
|
+
interaction.aggregate_metric('active_support.cache_fetch_hit', 1)
|
36
|
+
end
|
37
|
+
|
38
|
+
def cache_write
|
39
|
+
interaction.aggregate_metric('active_support.cache_write', 1)
|
40
|
+
end
|
41
|
+
|
42
|
+
def cache_delete
|
43
|
+
interaction.aggregate_metric('active_support.cache_delete', 1)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module NetuitiveRailsAgent
|
2
|
+
class ApiInteraction
|
3
|
+
def send_metrics
|
4
|
+
NetuitiveRubyAPI.send_metrics
|
5
|
+
end
|
6
|
+
|
7
|
+
def add_sample(metric_id, val)
|
8
|
+
NetuitiveRubyAPI.add_sample(metric_id, val)
|
9
|
+
end
|
10
|
+
|
11
|
+
def add_counter_sample(metric_id, val)
|
12
|
+
NetuitiveRubyAPI.add_counter_sample(metric_id, val)
|
13
|
+
end
|
14
|
+
|
15
|
+
def aggregate_metric(metric_id, val)
|
16
|
+
NetuitiveRubyAPI.aggregate_metric(metric_id, val)
|
17
|
+
end
|
18
|
+
|
19
|
+
def aggregate_counter_metric(metric_id, val)
|
20
|
+
NetuitiveRubyAPI.aggregate_counter_metric(metric_id, val)
|
21
|
+
end
|
22
|
+
|
23
|
+
def clear_metrics
|
24
|
+
NetuitiveRubyAPI.clear_metrics
|
25
|
+
end
|
26
|
+
|
27
|
+
def interval
|
28
|
+
NetuitiveRubyAPI.interval
|
29
|
+
end
|
30
|
+
|
31
|
+
def event(message, timestamp = Time.new, title = 'Ruby Event', level = 'Info', source = 'Ruby Agent', type = 'INFO', tags = nil)
|
32
|
+
NetuitiveRubyAPI.event(message, timestamp, title, level, source, type, tags)
|
33
|
+
end
|
34
|
+
|
35
|
+
def exception_event(exception, klass = nil, tags = nil)
|
36
|
+
NetuitiveRubyAPI.exception_event(exception, klass, tags)
|
37
|
+
end
|
38
|
+
|
39
|
+
def stop_server
|
40
|
+
NetuitiveRubyAPI.stop_server
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,124 @@
|
|
1
|
+
module NetuitiveRailsAgent
|
2
|
+
class ConfigManager
|
3
|
+
class << self
|
4
|
+
attr_accessor :capture_errors
|
5
|
+
|
6
|
+
attr_accessor :ignored_errors
|
7
|
+
|
8
|
+
attr_accessor :queue_time_divisor
|
9
|
+
|
10
|
+
attr_accessor :sidekiq_enabled
|
11
|
+
|
12
|
+
attr_accessor :action_controller_enabled
|
13
|
+
|
14
|
+
attr_accessor :active_record_enabled
|
15
|
+
|
16
|
+
attr_accessor :action_view_enabled
|
17
|
+
|
18
|
+
attr_accessor :action_mailer_enabled
|
19
|
+
|
20
|
+
attr_accessor :active_support_enabled
|
21
|
+
|
22
|
+
attr_accessor :active_job_enabled
|
23
|
+
|
24
|
+
attr_accessor :request_wrapper_enabled
|
25
|
+
|
26
|
+
attr_accessor :action_errors_enabled
|
27
|
+
|
28
|
+
attr_accessor :gc_enabled
|
29
|
+
|
30
|
+
attr_accessor :object_space_enabled
|
31
|
+
|
32
|
+
attr_accessor :data
|
33
|
+
|
34
|
+
def property(name, var, default = nil)
|
35
|
+
prop = ENV[var]
|
36
|
+
prop = data[name] if prop.nil? || (prop == '')
|
37
|
+
return prop unless prop.nil? || (prop == '')
|
38
|
+
default
|
39
|
+
end
|
40
|
+
|
41
|
+
def boolean_property(name, var)
|
42
|
+
prop = ENV[var].nil? ? nil : ENV[var].dup
|
43
|
+
if prop.nil? || (prop == '')
|
44
|
+
prop = data[name]
|
45
|
+
else
|
46
|
+
prop.strip!
|
47
|
+
prop = prop.casecmp('true').zero?
|
48
|
+
end
|
49
|
+
prop
|
50
|
+
end
|
51
|
+
|
52
|
+
def float_property(name, var)
|
53
|
+
prop = ENV[var].nil? ? nil : ENV[var]
|
54
|
+
if prop.nil? || (prop == '')
|
55
|
+
data[name].to_f
|
56
|
+
else
|
57
|
+
prop.to_f
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def string_list_property(name, var)
|
62
|
+
list = []
|
63
|
+
prop = ENV[var].nil? ? nil : ENV[var].dup
|
64
|
+
if prop.nil? || (prop == '')
|
65
|
+
list = data[name] if !data[name].nil? && data[name].is_a?(Array)
|
66
|
+
else
|
67
|
+
list = prop.split(',')
|
68
|
+
end
|
69
|
+
list.each(&:strip!) unless list.empty?
|
70
|
+
list
|
71
|
+
end
|
72
|
+
|
73
|
+
def load_config
|
74
|
+
gem_root = File.expand_path('../../..', __FILE__)
|
75
|
+
@data = YAML.load_file "#{gem_root}/config/agent.yml"
|
76
|
+
end
|
77
|
+
|
78
|
+
def read_config
|
79
|
+
debug_level_string = property('debugLevel', 'NETUITIVE_RAILS_DEBUG_LEVEL')
|
80
|
+
NetuitiveRailsAgent::NetuitiveLogger.log.level = if debug_level_string == 'error'
|
81
|
+
Logger::ERROR
|
82
|
+
elsif debug_level_string == 'info'
|
83
|
+
Logger::INFO
|
84
|
+
elsif debug_level_string == 'debug'
|
85
|
+
Logger::DEBUG
|
86
|
+
else
|
87
|
+
Logger::ERROR
|
88
|
+
end
|
89
|
+
|
90
|
+
@capture_errors = boolean_property('sendErrorEvents', 'NETUITIVE_RAILS_SEND_ERROR_EVENTS')
|
91
|
+
@queue_time_divisor = float_property('queueTimeUnits', 'NETUITIVE_RAILS_QUEUE_TIME_UNITS')
|
92
|
+
@ignored_errors = string_list_property('ignoredErrors', 'NETUITIVE_RAILS_IGNORED_ERRORS')
|
93
|
+
@sidekiq_enabled = boolean_property('sidekiqEnabled', 'NETUITIVE_RAILS_SIDEKIQ_ENABLED')
|
94
|
+
@action_controller_enabled = boolean_property('actionControllerEnabled', 'NETUITIVE_RAILS_ACTION_CONTROLLER_ENABLED')
|
95
|
+
@active_record_enabled = boolean_property('activeRecordEnabled', 'NETUITIVE_RAILS_ACTIVE_RECORD_ENABLED')
|
96
|
+
@action_view_enabled = boolean_property('actionViewEnabled', 'NETUITIVE_RAILS_ACTION_VIEW_ENABLED')
|
97
|
+
@action_mailer_enabled = boolean_property('actionMailerEnabled', 'NETUITIVE_RAILS_ACTION_MAILER_ENABLED')
|
98
|
+
@active_support_enabled = boolean_property('activeSupportEnabled', 'NETUITIVE_RAILS_ACTIVE_SUPPORT_ENABLED')
|
99
|
+
@active_job_enabled = boolean_property('activeJobEnabled', 'NETUITIVE_RAILS_ACTIVE_JOB_ENABLED')
|
100
|
+
@request_wrapper_enabled = boolean_property('requestWrapperEnabled', 'NETUITIVE_RAILS_REQUEST_WRAPPER_ENABLED')
|
101
|
+
@action_errors_enabled = boolean_property('actionErrorsEnabled', 'NETUITIVE_RAILS_ACTION_ERRORS_ENABLED')
|
102
|
+
@gc_enabled = boolean_property('gcEnabled', 'NETUITIVE_RAILS_GC_ENABLED')
|
103
|
+
@object_space_enabled = boolean_property('objectSpaceEnabled', 'NETUITIVE_RAILS_OBJECT_SPACE_ENABLED')
|
104
|
+
|
105
|
+
NetuitiveRailsAgent::NetuitiveLogger.log.debug "read config file. Results:
|
106
|
+
debugLevel: #{debug_level_string},
|
107
|
+
capture_errors: #{capture_errors},
|
108
|
+
ignored_errors: #{ignored_errors},
|
109
|
+
queue_time_divisor: #{queue_time_divisor},
|
110
|
+
sidekiq_enabled: #{sidekiq_enabled},
|
111
|
+
action_controller_enabled: #{action_controller_enabled},
|
112
|
+
active_record_enabled: #{active_record_enabled},
|
113
|
+
action_view_enabled: #{action_view_enabled},
|
114
|
+
action_mailer_enabled: #{action_mailer_enabled},
|
115
|
+
active_support_enabled: #{active_support_enabled},
|
116
|
+
active_job_enabled: #{active_job_enabled},
|
117
|
+
request_wrapper_enabled: #{request_wrapper_enabled},
|
118
|
+
action_errors_enabled: #{action_errors_enabled},
|
119
|
+
gc_enabled: #{gc_enabled},
|
120
|
+
object_space_enabled: #{object_space_enabled}"
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|