scout_apm 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.markdown +4 -0
- data/lib/scout_apm.rb +48 -23
- data/lib/scout_apm/agent.rb +93 -130
- data/lib/scout_apm/agent/reporting.rb +34 -63
- data/lib/scout_apm/app_server_load.rb +29 -0
- data/lib/scout_apm/background_worker.rb +6 -6
- data/lib/scout_apm/capacity.rb +48 -48
- data/lib/scout_apm/config.rb +5 -5
- data/lib/scout_apm/context.rb +3 -3
- data/lib/scout_apm/environment.rb +64 -100
- data/lib/scout_apm/framework_integrations/rails_2.rb +32 -0
- data/lib/scout_apm/framework_integrations/rails_3_or_4.rb +33 -0
- data/lib/scout_apm/framework_integrations/ruby.rb +26 -0
- data/lib/scout_apm/framework_integrations/sinatra.rb +27 -0
- data/lib/scout_apm/instruments/active_record_instruments.rb +1 -1
- data/lib/scout_apm/instruments/mongoid_instruments.rb +1 -1
- data/lib/scout_apm/instruments/moped_instruments.rb +3 -3
- data/lib/scout_apm/instruments/net_http.rb +2 -2
- data/lib/scout_apm/instruments/process/process_cpu.rb +41 -20
- data/lib/scout_apm/instruments/process/process_memory.rb +45 -30
- data/lib/scout_apm/instruments/rails/action_controller_instruments.rb +20 -18
- data/lib/scout_apm/instruments/rails3_or_4/action_controller_instruments.rb +17 -14
- data/lib/scout_apm/layaway.rb +12 -12
- data/lib/scout_apm/layaway_file.rb +1 -1
- data/lib/scout_apm/metric_meta.rb +9 -9
- data/lib/scout_apm/metric_stats.rb +8 -8
- data/lib/scout_apm/reporter.rb +83 -0
- data/lib/scout_apm/serializers/app_server_load_serializer.rb +15 -0
- data/lib/scout_apm/serializers/directive_serializer.rb +15 -0
- data/lib/scout_apm/serializers/payload_serializer.rb +14 -0
- data/lib/scout_apm/server_integrations/null.rb +30 -0
- data/lib/scout_apm/server_integrations/passenger.rb +35 -0
- data/lib/scout_apm/server_integrations/puma.rb +30 -0
- data/lib/scout_apm/server_integrations/rainbows.rb +36 -0
- data/lib/scout_apm/server_integrations/thin.rb +41 -0
- data/lib/scout_apm/server_integrations/unicorn.rb +35 -0
- data/lib/scout_apm/server_integrations/webrick.rb +25 -0
- data/lib/scout_apm/slow_transaction.rb +3 -3
- data/lib/scout_apm/stack_item.rb +19 -17
- data/lib/scout_apm/store.rb +35 -35
- data/lib/scout_apm/tracer.rb +121 -110
- data/lib/scout_apm/utils/sql_sanitizer.rb +2 -2
- data/lib/scout_apm/version.rb +2 -1
- data/test/unit/environment_test.rb +5 -5
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 91a0c14d41ab0d56bce566a96e08014a452ba693
|
4
|
+
data.tar.gz: 8b1f7239c3f43bfaa1cb6191ff20d8bcc29bd288
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0f11acf434f45f02d92106f76d7976aa13c86808a10e5716d6698660f82889a9de4a374060acaa5c170df182b60eb9943226da10478f76c33e6ac02bebd4bde6
|
7
|
+
data.tar.gz: baa5db394ee68a07b26fae9a493a96f0e512c6dbc0c583082b2eb5974dfdbd946632c11d83b914cd8033c60f85b3cebc94bccb44b18153f3f95d478fa801c487
|
data/CHANGELOG.markdown
CHANGED
data/lib/scout_apm.rb
CHANGED
@@ -1,32 +1,57 @@
|
|
1
1
|
module ScoutApm
|
2
2
|
end
|
3
|
-
|
4
|
-
require '
|
3
|
+
|
4
|
+
require 'cgi'
|
5
|
+
require 'logger'
|
5
6
|
require 'net/http'
|
6
7
|
require 'openssl'
|
7
|
-
require '
|
8
|
+
require 'set'
|
9
|
+
require 'socket'
|
8
10
|
require 'yaml'
|
9
|
-
require 'cgi'
|
10
11
|
|
11
|
-
require
|
12
|
-
|
13
|
-
require
|
14
|
-
require
|
15
|
-
require
|
16
|
-
require
|
17
|
-
require
|
18
|
-
require
|
19
|
-
require
|
20
|
-
|
21
|
-
require
|
22
|
-
require
|
23
|
-
require
|
24
|
-
require
|
25
|
-
|
26
|
-
require
|
27
|
-
|
28
|
-
require
|
29
|
-
require
|
12
|
+
require 'scout_apm/version'
|
13
|
+
|
14
|
+
require 'scout_apm/server_integrations/passenger'
|
15
|
+
require 'scout_apm/server_integrations/puma'
|
16
|
+
require 'scout_apm/server_integrations/rainbows'
|
17
|
+
require 'scout_apm/server_integrations/thin'
|
18
|
+
require 'scout_apm/server_integrations/unicorn'
|
19
|
+
require 'scout_apm/server_integrations/webrick'
|
20
|
+
require 'scout_apm/server_integrations/null'
|
21
|
+
|
22
|
+
require 'scout_apm/framework_integrations/rails_2'
|
23
|
+
require 'scout_apm/framework_integrations/rails_3_or_4'
|
24
|
+
require 'scout_apm/framework_integrations/sinatra'
|
25
|
+
require 'scout_apm/framework_integrations/ruby'
|
26
|
+
|
27
|
+
require 'scout_apm/app_server_load'
|
28
|
+
|
29
|
+
require 'scout_apm/utils/sql_sanitizer'
|
30
|
+
require 'scout_apm/utils/null_logger'
|
31
|
+
require 'scout_apm/config'
|
32
|
+
require 'scout_apm/environment'
|
33
|
+
require 'scout_apm/agent'
|
34
|
+
require 'scout_apm/agent/logging'
|
35
|
+
require 'scout_apm/agent/reporting'
|
36
|
+
require 'scout_apm/layaway'
|
37
|
+
require 'scout_apm/layaway_file'
|
38
|
+
require 'scout_apm/reporter'
|
39
|
+
require 'scout_apm/background_worker'
|
40
|
+
require 'scout_apm/metric_meta'
|
41
|
+
require 'scout_apm/metric_stats'
|
42
|
+
require 'scout_apm/stack_item'
|
43
|
+
require 'scout_apm/store'
|
44
|
+
require 'scout_apm/tracer'
|
45
|
+
require 'scout_apm/context'
|
46
|
+
require 'scout_apm/slow_transaction'
|
47
|
+
require 'scout_apm/capacity'
|
48
|
+
require 'scout_apm/instruments/process/process_cpu'
|
49
|
+
require 'scout_apm/instruments/process/process_memory'
|
50
|
+
|
51
|
+
|
52
|
+
require 'scout_apm/serializers/payload_serializer'
|
53
|
+
require 'scout_apm/serializers/directive_serializer'
|
54
|
+
require 'scout_apm/serializers/app_server_load_serializer'
|
30
55
|
|
31
56
|
if defined?(Rails) and Rails.respond_to?(:version) and Rails.version >= '3'
|
32
57
|
module ScoutApm
|
data/lib/scout_apm/agent.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
module ScoutApm
|
2
|
-
# The agent gathers performance data from a Ruby application. One Agent instance is created per-Ruby process.
|
2
|
+
# The agent gathers performance data from a Ruby application. One Agent instance is created per-Ruby process.
|
3
3
|
#
|
4
|
-
# Each Agent object creates a worker thread (unless monitoring is disabled or we're forking).
|
5
|
-
# The worker thread wakes up every +Agent#period+, merges in-memory metrics w/those saved to disk,
|
4
|
+
# Each Agent object creates a worker thread (unless monitoring is disabled or we're forking).
|
5
|
+
# The worker thread wakes up every +Agent#period+, merges in-memory metrics w/those saved to disk,
|
6
6
|
# saves tshe merged data to disk, and sends it to the Scout server.
|
7
7
|
class Agent
|
8
8
|
# see self.instance
|
@@ -12,19 +12,18 @@ module ScoutApm
|
|
12
12
|
attr_accessor :store
|
13
13
|
attr_accessor :layaway
|
14
14
|
attr_accessor :config
|
15
|
-
attr_accessor :environment
|
16
15
|
attr_accessor :capacity
|
17
16
|
attr_accessor :logger
|
18
17
|
attr_accessor :log_file # path to the log file
|
19
18
|
attr_accessor :options # options passed to the agent when +#start+ is called.
|
20
19
|
attr_accessor :metric_lookup # Hash used to lookup metric ids based on their name and scope
|
21
20
|
|
22
|
-
# All access to the agent is thru this class method to ensure multiple Agent instances are not initialized per-Ruby process.
|
21
|
+
# All access to the agent is thru this class method to ensure multiple Agent instances are not initialized per-Ruby process.
|
23
22
|
def self.instance(options = {})
|
24
23
|
@@instance ||= self.new(options)
|
25
24
|
end
|
26
25
|
|
27
|
-
# Note - this doesn't start instruments or the worker thread. This is handled via +#start+ as we don't
|
26
|
+
# Note - this doesn't start instruments or the worker thread. This is handled via +#start+ as we don't
|
28
27
|
# want to start the worker thread or install instrumentation if (1) disabled for this environment (2) a worker thread shouldn't
|
29
28
|
# be started (when forking).
|
30
29
|
def initialize(options = {})
|
@@ -32,74 +31,108 @@ module ScoutApm
|
|
32
31
|
@options ||= options
|
33
32
|
@config = ScoutApm::Config.new(options[:config_path])
|
34
33
|
|
35
|
-
@store
|
36
|
-
@layaway
|
37
|
-
@metric_lookup
|
38
|
-
|
39
|
-
@
|
40
|
-
@capacity = ScoutApm::Capacity.new
|
34
|
+
@store = ScoutApm::Store.new
|
35
|
+
@layaway = ScoutApm::Layaway.new
|
36
|
+
@metric_lookup = Hash.new
|
37
|
+
|
38
|
+
@capacity = ScoutApm::Capacity.new
|
41
39
|
end
|
42
40
|
|
43
41
|
def environment
|
44
|
-
|
42
|
+
ScoutApm::Environment.instance
|
45
43
|
end
|
46
44
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
if !config.value('monitor') and !@options[:force]
|
45
|
+
def apm_enabled?
|
46
|
+
config.value('monitor') and !@options[:force]
|
47
|
+
end
|
48
|
+
|
49
|
+
def preconditions_met?
|
50
|
+
if !apm_enabled?
|
54
51
|
logger.warn "Monitoring isn't enabled for the [#{environment.env}] environment."
|
55
52
|
return false
|
56
|
-
|
53
|
+
end
|
54
|
+
|
55
|
+
if !Environment.instance.application_name
|
57
56
|
logger.warn "An application name is required. Specify the :name value in scout_apm.yml. Not starting agent."
|
58
57
|
return false
|
59
|
-
|
58
|
+
end
|
59
|
+
|
60
|
+
if !environment.app_server
|
60
61
|
logger.warn "Couldn't find a supported app server. Not starting agent."
|
61
62
|
return false
|
62
|
-
|
63
|
+
end
|
64
|
+
|
65
|
+
if started?
|
63
66
|
logger.warn "Already started agent."
|
64
67
|
return false
|
65
68
|
end
|
69
|
+
|
70
|
+
true
|
71
|
+
end
|
72
|
+
|
73
|
+
# This is called via +ScoutApm::Agent.instance.start+ when ScoutApm is required in a Ruby application.
|
74
|
+
# It initializes the agent and starts the worker thread (if appropiate).
|
75
|
+
def start(options = {})
|
76
|
+
@options.merge!(options)
|
77
|
+
init_logger
|
78
|
+
logger.info "Attempting to start Scout Agent [#{ScoutApm::VERSION}] on [#{environment.hostname}]"
|
79
|
+
|
80
|
+
return false unless preconditions_met?
|
81
|
+
|
66
82
|
@started = true
|
67
|
-
|
83
|
+
|
84
|
+
logger.info "Starting monitoring for [#{environment.application_name}]. Framework [#{environment.framework}] App Server [#{environment.app_server}]."
|
85
|
+
|
68
86
|
load_instruments
|
69
|
-
|
87
|
+
@samplers = [
|
88
|
+
ScoutApm::Instruments::Process::ProcessCpu.new(environment.processors, logger),
|
89
|
+
ScoutApm::Instruments::Process::ProcessMemory.new(logger)
|
90
|
+
]
|
91
|
+
|
92
|
+
app_server_load_hook
|
93
|
+
|
94
|
+
if start_background_worker? # TODO: Clarify name. This is not the path that unicorn workers take....
|
95
|
+
# This branch fires only on non-forking servers, directly starts the
|
96
|
+
# background thread and then requests are served.
|
97
|
+
start_background_worker
|
98
|
+
handle_exit
|
99
|
+
logger.info "Scout Agent [#{ScoutApm::VERSION}] Initialized"
|
100
|
+
else
|
101
|
+
# This branch fires on.... master only? of forking servers
|
70
102
|
logger.debug "Not starting worker thread. Will start worker loops after forking."
|
71
|
-
|
72
|
-
install_unicorn_worker_loop if environment.app_server == :unicorn
|
73
|
-
install_rainbows_worker_loop if environment.app_server == :rainbows
|
74
|
-
install_puma_worker_loop if environment.app_server == :puma
|
75
|
-
return
|
103
|
+
environment.app_server_integration.install
|
76
104
|
end
|
77
|
-
start_background_worker
|
78
|
-
handle_exit
|
79
|
-
logger.info "Scout Agent [#{ScoutApm::VERSION}] Initialized"
|
80
105
|
end
|
81
|
-
|
106
|
+
|
107
|
+
# Sends a ping to APM right away, smoothes out onboarding
|
108
|
+
# Collects up any relevant info (framework, app server, system time, ruby version, etc)
|
109
|
+
def app_server_load_hook
|
110
|
+
AppServerLoad.new.run
|
111
|
+
end
|
112
|
+
|
113
|
+
def exit_handler_unsupported?
|
114
|
+
environment.sinatra? || environment.jruby? || environment.rubinius?
|
115
|
+
end
|
116
|
+
|
82
117
|
# at_exit, calls Agent#shutdown to wrapup metric reporting.
|
83
118
|
def handle_exit
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
if
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
end
|
98
|
-
end # at_exit
|
119
|
+
logger.debug "Exit handler not supported" and return if exit_handler_unsupported?
|
120
|
+
|
121
|
+
at_exit do
|
122
|
+
logger.debug "Shutdown!"
|
123
|
+
# MRI 1.9 bug drops exit codes.
|
124
|
+
# http://bugs.ruby-lang.org/issues/5218
|
125
|
+
if environment.ruby_19?
|
126
|
+
status = $!.status if $!.is_a?(SystemExit)
|
127
|
+
shutdown
|
128
|
+
exit status if status
|
129
|
+
else
|
130
|
+
shutdown
|
131
|
+
end
|
99
132
|
end
|
100
133
|
end
|
101
|
-
|
102
|
-
# Called via an at_exit handler, it (1) stops the background worker and (2) runs it a final time.
|
134
|
+
|
135
|
+
# Called via an at_exit handler, it (1) stops the background worker and (2) runs it a final time.
|
103
136
|
# The final run ensures metrics are stored locally to the layaway / reported to scoutapp.com. Otherwise,
|
104
137
|
# in-memory metrics would be lost and a gap would appear on restarts.
|
105
138
|
def shutdown
|
@@ -107,68 +140,21 @@ module ScoutApm
|
|
107
140
|
@background_worker.stop
|
108
141
|
@background_worker.run_once
|
109
142
|
end
|
110
|
-
|
143
|
+
|
111
144
|
def started?
|
112
145
|
@started
|
113
146
|
end
|
114
|
-
|
115
|
-
def gem_root
|
116
|
-
File.expand_path(File.join("..","..",".."), __FILE__)
|
117
|
-
end
|
118
|
-
|
147
|
+
|
119
148
|
# The worker thread will automatically start UNLESS:
|
120
149
|
# * A supported application server isn't detected (example: running via Rails console)
|
121
|
-
# * A supported application server is detected, but it forks. In this case,
|
150
|
+
# * A supported application server is detected, but it forks. In this case,
|
122
151
|
# the agent is started in the forked process.
|
123
152
|
def start_background_worker?
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
## TODO - Likely possible to unify starting the worker loop in forking servers by listening for the first transaction
|
128
|
-
## to start and starting the background worker then in that process.
|
129
|
-
|
130
|
-
def install_passenger_events
|
131
|
-
PhusionPassenger.on_event(:starting_worker_process) do |forked|
|
132
|
-
logger.debug "Passenger is starting a worker process. Starting worker thread."
|
133
|
-
self.class.instance.start_background_worker
|
134
|
-
end
|
135
|
-
# The agent's at_exit hook doesn't run when a Passenger process stops.
|
136
|
-
# This does run when a process stops.
|
137
|
-
PhusionPassenger.on_event(:stopping_worker_process) do
|
138
|
-
logger.debug "Passenger is stopping a worker process, shutting down the agent."
|
139
|
-
ScoutApm::Agent.instance.shutdown
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
def install_unicorn_worker_loop
|
144
|
-
logger.debug "Installing Unicorn worker loop."
|
145
|
-
Unicorn::HttpServer.class_eval do
|
146
|
-
old = instance_method(:worker_loop)
|
147
|
-
define_method(:worker_loop) do |worker|
|
148
|
-
ScoutApm::Agent.instance.start_background_worker
|
149
|
-
old.bind(self).call(worker)
|
150
|
-
end
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
def install_rainbows_worker_loop
|
155
|
-
logger.debug "Installing Rainbows worker loop."
|
156
|
-
Rainbows::HttpServer.class_eval do
|
157
|
-
old = instance_method(:worker_loop)
|
158
|
-
define_method(:worker_loop) do |worker|
|
159
|
-
ScoutApm::Agent.instance.start_background_worker
|
160
|
-
old.bind(self).call(worker)
|
161
|
-
end
|
162
|
-
end
|
163
|
-
end
|
153
|
+
return true if environment.app_server == :thin
|
154
|
+
return true if environment.app_server == :webrick
|
155
|
+
return false if environment.forking?
|
164
156
|
|
165
|
-
|
166
|
-
Puma.cli_config.options[:before_worker_boot] << Proc.new do
|
167
|
-
logger.debug "Installing Puma worker loop."
|
168
|
-
ScoutApm::Agent.instance.start_background_worker
|
169
|
-
end
|
170
|
-
rescue
|
171
|
-
logger.warn "Unable to install Puma worker loop: #{$!.message}"
|
157
|
+
false
|
172
158
|
end
|
173
159
|
|
174
160
|
# Creates the worker thread. The worker thread is a loop that runs continuously. It sleeps for +Agent#period+ and when it wakes,
|
@@ -182,29 +168,6 @@ module ScoutApm
|
|
182
168
|
logger.debug "Done creating worker thread."
|
183
169
|
end
|
184
170
|
|
185
|
-
# Called from #process_metrics, which is run via the background worker.
|
186
|
-
def run_samplers
|
187
|
-
begin
|
188
|
-
cpu_util=@process_cpu.run # returns a hash
|
189
|
-
logger.debug "Process CPU: #{cpu_util.inspect} [#{environment.processors} CPU(s)]"
|
190
|
-
store.track!("CPU/Utilization",cpu_util,:scope => nil) if cpu_util
|
191
|
-
rescue => e
|
192
|
-
logger.info "Error reading ProcessCpu"
|
193
|
-
logger.debug e.message
|
194
|
-
logger.debug e.backtrace.join("\n")
|
195
|
-
end
|
196
|
-
|
197
|
-
begin
|
198
|
-
mem_usage=@process_memory.run # returns a single number, in MB
|
199
|
-
logger.debug "Process Memory: #{mem_usage}MB"
|
200
|
-
store.track!("Memory/Physical",mem_usage,:scope => nil) if mem_usage
|
201
|
-
rescue => e
|
202
|
-
logger.info "Error reading ProcessMemory"
|
203
|
-
logger.debug e.message
|
204
|
-
logger.debug e.backtrace.join("\n")
|
205
|
-
end
|
206
|
-
end
|
207
|
-
|
208
171
|
# Loads the instrumention logic.
|
209
172
|
def load_instruments
|
210
173
|
logger.debug "Installing instrumentation"
|
@@ -223,5 +186,5 @@ module ScoutApm
|
|
223
186
|
logger.warn $!.message
|
224
187
|
logger.warn $!.backtrace
|
225
188
|
end
|
226
|
-
end
|
227
|
-
end
|
189
|
+
end
|
190
|
+
end
|
@@ -2,8 +2,9 @@
|
|
2
2
|
module ScoutApm
|
3
3
|
class Agent
|
4
4
|
module Reporting
|
5
|
-
|
6
|
-
|
5
|
+
def reporter
|
6
|
+
@reporter ||= ScoutApm::Reporter.new(config, logger)
|
7
|
+
end
|
7
8
|
|
8
9
|
# Called in the worker thread. Merges in-memory metrics w/those on disk and reports metrics
|
9
10
|
# to the server.
|
@@ -12,26 +13,35 @@ module ScoutApm
|
|
12
13
|
run_samplers
|
13
14
|
capacity.process
|
14
15
|
payload = layaway.deposit_and_deliver
|
16
|
+
|
15
17
|
metrics = payload[:metrics]
|
16
18
|
slow_transactions = payload[:slow_transactions]
|
19
|
+
|
17
20
|
if payload.any?
|
18
|
-
add_metric_ids(metrics)
|
21
|
+
add_metric_ids(metrics)
|
22
|
+
|
19
23
|
logger.warn "Some data may be lost - metric size is at limit" if metrics.size == ScoutApm::Store::MAX_SIZE
|
20
|
-
# for debugging, count the total number of requests
|
24
|
+
# for debugging, count the total number of requests
|
21
25
|
controller_count = 0
|
26
|
+
|
22
27
|
metrics.each do |meta,stats|
|
23
28
|
if meta.metric_name =~ /\AController/
|
24
29
|
controller_count += stats.call_count
|
25
30
|
end
|
26
31
|
end
|
27
|
-
|
32
|
+
|
33
|
+
logger.debug("Metrics: #{metrics}")
|
34
|
+
logger.debug("SlowTrans: #{slow_transactions}")
|
35
|
+
|
36
|
+
payload = ScoutApm::Serializers::PayloadSerializer.serialize(metrics, slow_transactions)
|
28
37
|
slow_transactions_kb = Marshal.dump(slow_transactions).size/1024 # just for performance debugging
|
29
|
-
logger.debug "#{config.value('name')} Delivering total payload [#{payload.size/1024} KB] for #{controller_count} requests and slow transactions [#{slow_transactions_kb} KB] for #{slow_transactions.size} transactions of durations: #{slow_transactions.map(&:total_call_time).join(',')}."
|
30
|
-
|
31
|
-
|
32
|
-
|
38
|
+
logger.debug "#{config.value('name')} Delivering total payload [#{payload.size/1024} KB] for #{controller_count} requests and slow transactions [#{slow_transactions_kb} KB] for #{slow_transactions.size} transactions of durations: #{slow_transactions.map(&:total_call_time).join(',')}."
|
39
|
+
|
40
|
+
response = reporter.report(payload)
|
41
|
+
|
33
42
|
if response and response.is_a?(Net::HTTPSuccess)
|
34
|
-
directives =
|
43
|
+
directives = ScoutApm::Serializers::DirectiveSerializer.deserialize(response.body)
|
44
|
+
|
35
45
|
self.metric_lookup.merge!(directives[:metric_lookup])
|
36
46
|
if directives[:reset]
|
37
47
|
logger.info "Resetting metric_lookup."
|
@@ -39,16 +49,16 @@ module ScoutApm
|
|
39
49
|
end
|
40
50
|
logger.debug "Metric Cache Size: #{metric_lookup.size}"
|
41
51
|
elsif response
|
42
|
-
logger.warn "Error on checkin to #{
|
52
|
+
logger.warn "Error on checkin to #{reporter.uri.to_s}: #{response.inspect}"
|
43
53
|
end
|
44
54
|
end
|
45
55
|
rescue
|
46
|
-
logger.warn "Error on checkin to #{
|
56
|
+
logger.warn "Error on checkin to #{reporter.uri.to_s}"
|
47
57
|
logger.info $!.message
|
48
58
|
logger.debug $!.backtrace
|
49
59
|
end
|
50
60
|
|
51
|
-
# Before reporting, lookup metric_id for each MetricMeta. This speeds up
|
61
|
+
# Before reporting, lookup metric_id for each MetricMeta. This speeds up
|
52
62
|
# reporting on the server-side.
|
53
63
|
def add_metric_ids(metrics)
|
54
64
|
metrics.each do |meta,stats|
|
@@ -58,57 +68,18 @@ module ScoutApm
|
|
58
68
|
end
|
59
69
|
end
|
60
70
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
response=connection.request(post)
|
73
|
-
end
|
74
|
-
response
|
75
|
-
end
|
76
|
-
|
77
|
-
def request(uri, &connector)
|
78
|
-
response = nil
|
79
|
-
response = http(uri).start(&connector)
|
80
|
-
logger.debug "got response: #{response.inspect}"
|
81
|
-
case response
|
82
|
-
when Net::HTTPSuccess, Net::HTTPNotModified
|
83
|
-
logger.debug "/checkin OK"
|
84
|
-
when Net::HTTPBadRequest
|
85
|
-
logger.warn "/checkin FAILED: The Account Key [#{config.value('key')}] is invalid."
|
86
|
-
else
|
87
|
-
logger.debug "/checkin FAILED: #{response.inspect}"
|
88
|
-
end
|
89
|
-
rescue Exception
|
90
|
-
logger.debug "Exception sending request to server: #{$!.message}\n#{$!.backtrace}"
|
91
|
-
ensure
|
92
|
-
response
|
93
|
-
end
|
94
|
-
|
95
|
-
# Headers passed up with all API requests.
|
96
|
-
def http_headers
|
97
|
-
@http_headers ||= { "Agent-Hostname" => environment.hostname }
|
98
|
-
end
|
99
|
-
|
100
|
-
# Take care of the http proxy, if specified in config.
|
101
|
-
# Given a blank string, the proxy_uri URI instance's host/port/user/pass will be nil.
|
102
|
-
# Net::HTTP::Proxy returns a regular Net::HTTP class if the first argument (host) is nil.
|
103
|
-
def http(url)
|
104
|
-
proxy_uri = URI.parse(config.value('proxy').to_s)
|
105
|
-
http = Net::HTTP::Proxy(proxy_uri.host,proxy_uri.port,proxy_uri.user,proxy_uri.password).new(url.host, url.port)
|
106
|
-
if url.is_a?(URI::HTTPS)
|
107
|
-
http.use_ssl = true
|
108
|
-
http.ca_file = CA_FILE
|
109
|
-
http.verify_mode = VERIFY_MODE
|
71
|
+
# Called from #process_metrics, which is run via the background worker.
|
72
|
+
def run_samplers
|
73
|
+
@samplers.each do |sampler|
|
74
|
+
begin
|
75
|
+
result = sampler.run
|
76
|
+
store.track!(sampler.metric_name, result, scope: nil) if result
|
77
|
+
rescue => e
|
78
|
+
logger.info "Error reading #{sampler.human_name}"
|
79
|
+
logger.debug e.message
|
80
|
+
logger.debug e.backtrace.join("\n")
|
81
|
+
end
|
110
82
|
end
|
111
|
-
http
|
112
83
|
end
|
113
84
|
end # module Reporting
|
114
85
|
include Reporting
|