instana 0.8.4 → 0.8.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +5 -2
- data/lib/instana.rb +7 -1
- data/lib/instana/agent.rb +75 -28
- data/lib/instana/collectors/gc.rb +1 -1
- data/lib/instana/collectors/memory.rb +1 -1
- data/lib/instana/collectors/thread.rb +1 -1
- data/lib/instana/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 42faa21829471a9c09aef2c82c1bdf79cee9bb2a
|
4
|
+
data.tar.gz: 7f4d358d30c2bb53b3dc97a39fbcdbfb950a0db5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d1b63875713111313dae3ba16b1374df8d3d70f78074c5617728eead258311d9a65cb537e03b44dc0f2e5a4b15fea7c7a0940f86957f78d91b29fd9bce81e5f9
|
7
|
+
data.tar.gz: 602264940c06d3e4d8ebae06f56e91af16729ead2af6c3bf5add6b434d3b6bd6576d6388dbefdc8d963fe1f4f11e5310fdf4fa9c8a014a7dcd5d0840aadf61bc
|
data/.travis.yml
CHANGED
data/lib/instana.rb
CHANGED
@@ -19,8 +19,14 @@ module Instana
|
|
19
19
|
def start
|
20
20
|
@agent = Instana::Agent.new
|
21
21
|
@collectors = []
|
22
|
+
|
22
23
|
@logger = Logger.new(STDOUT)
|
23
|
-
|
24
|
+
if ENV.key?('INSTANA_GEM_TEST') || ENV.key?('INSTANA_GEM_DEV')
|
25
|
+
@logger.level = Logger::DEBUG
|
26
|
+
else
|
27
|
+
@logger.level = Logger::WARN
|
28
|
+
end
|
29
|
+
@logger.unknown "Stan is on the scene. Starting Instana instrumentation."
|
24
30
|
|
25
31
|
# Store the current pid so we can detect a potential fork
|
26
32
|
# later on
|
data/lib/instana/agent.rb
CHANGED
@@ -25,9 +25,9 @@ module Instana
|
|
25
25
|
# every 10 minutes along side process metrics.
|
26
26
|
@snapshot = take_snapshot
|
27
27
|
|
28
|
-
# Set last snapshot to 10 minutes ago
|
29
|
-
# so we send a snapshot
|
30
|
-
@last_snapshot = Time.now -
|
28
|
+
# Set last snapshot to just under 10 minutes ago
|
29
|
+
# so we send a snapshot sooner than later
|
30
|
+
@last_snapshot = Time.now - 570
|
31
31
|
|
32
32
|
# Timestamp of the last successful response from
|
33
33
|
# entity data reporting.
|
@@ -43,7 +43,23 @@ module Instana
|
|
43
43
|
|
44
44
|
# In case we're running in Docker, have the default gateway available
|
45
45
|
# to check in case we're running in bridged network mode
|
46
|
-
@
|
46
|
+
if @is_linux
|
47
|
+
@default_gateway = `/sbin/ip route | awk '/default/ { print $3 }'`.chomp
|
48
|
+
else
|
49
|
+
@default_gateway = nil
|
50
|
+
end
|
51
|
+
|
52
|
+
# The agent UUID returned from the host agent
|
53
|
+
@agent_uuid = nil
|
54
|
+
|
55
|
+
@process = {}
|
56
|
+
cmdline = ProcTable.ps(Process.pid).cmdline.split("\0")
|
57
|
+
@process[:name] = cmdline.shift
|
58
|
+
@process[:arguments] = cmdline
|
59
|
+
@process[:original_pid] = Process.pid
|
60
|
+
# This is usually Process.pid but in the case of docker, the host agent
|
61
|
+
# will return to us the true host pid in which we use to report data.
|
62
|
+
@process[:report_pid] = nil
|
47
63
|
end
|
48
64
|
|
49
65
|
##
|
@@ -100,23 +116,30 @@ module Instana
|
|
100
116
|
# the host agent.
|
101
117
|
#
|
102
118
|
def announce_sensor
|
103
|
-
process = ProcTable.ps(Process.pid)
|
104
119
|
announce_payload = {}
|
105
|
-
announce_payload[:pid] = Process.pid
|
106
|
-
|
107
|
-
arguments = process.cmdline.split(' ')
|
108
|
-
arguments.shift
|
109
|
-
announce_payload[:args] = arguments
|
120
|
+
announce_payload[:pid] = pid_namespace? ? get_real_pid : Process.pid
|
121
|
+
announce_payload[:args] = @process[:arguments]
|
110
122
|
|
111
123
|
uri = URI.parse("http://#{@host}:#{@port}/#{DISCOVERY_PATH}")
|
112
124
|
req = Net::HTTP::Put.new(uri)
|
113
125
|
req.body = announce_payload.to_json
|
114
126
|
|
127
|
+
# ::Instana.logger.debug "Announce: http://#{@host}:#{@port}/#{DISCOVERY_PATH} - payload: #{req.body}"
|
128
|
+
|
115
129
|
response = make_host_agent_request(req)
|
116
|
-
|
130
|
+
|
131
|
+
if response && (response.code.to_i == 200)
|
132
|
+
data = JSON.parse(response.body)
|
133
|
+
@process[:report_pid] = data['pid']
|
134
|
+
@agent_uuid = data['agentUuid']
|
135
|
+
true
|
136
|
+
else
|
137
|
+
false
|
138
|
+
end
|
117
139
|
rescue => e
|
118
|
-
Instana.logger.
|
140
|
+
Instana.logger.error "#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
|
119
141
|
Instana.logger.debug e.backtrace.join("\r\n")
|
142
|
+
return false
|
120
143
|
end
|
121
144
|
|
122
145
|
##
|
@@ -126,7 +149,7 @@ module Instana
|
|
126
149
|
#
|
127
150
|
def report_entity_data(payload)
|
128
151
|
with_snapshot = false
|
129
|
-
path = "com.instana.plugin.ruby.#{
|
152
|
+
path = "com.instana.plugin.ruby.#{@process[:report_pid]}"
|
130
153
|
uri = URI.parse("http://#{@host}:#{@port}/#{path}")
|
131
154
|
req = Net::HTTP::Post.new(uri)
|
132
155
|
|
@@ -134,6 +157,13 @@ module Instana
|
|
134
157
|
if (Time.now - @last_snapshot) > 600
|
135
158
|
with_snapshot = true
|
136
159
|
payload.merge!(@snapshot)
|
160
|
+
|
161
|
+
# Add in process related that could have changed since
|
162
|
+
# snapshot was taken.
|
163
|
+
p = { :pid => @process[:report_pid] }
|
164
|
+
p[:name] = @process[:name]
|
165
|
+
p[:exec_args] = @process[:arguments]
|
166
|
+
payload.merge!(p)
|
137
167
|
end
|
138
168
|
|
139
169
|
req.body = payload.to_json
|
@@ -142,18 +172,18 @@ module Instana
|
|
142
172
|
if response
|
143
173
|
last_entity_response = response.code.to_i
|
144
174
|
|
175
|
+
#::Instana.logger.debug "entity http://#{@host}:#{@port}/#{path}: response=#{last_entity_response}: #{payload.to_json}"
|
176
|
+
|
145
177
|
if last_entity_response == 200
|
146
178
|
@entity_last_seen = Time.now
|
147
179
|
@last_snapshot = Time.now if with_snapshot
|
148
180
|
|
149
|
-
#::Instana.logger.debug "entity response #{last_entity_response}: #{payload.to_json}"
|
150
181
|
return true
|
151
182
|
end
|
152
|
-
#::Instana.logger.debug "entity response #{last_entity_response}: #{payload.to_json}"
|
153
183
|
end
|
154
184
|
false
|
155
185
|
rescue => e
|
156
|
-
Instana.logger.
|
186
|
+
Instana.logger.error "#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
|
157
187
|
Instana.logger.debug e.backtrace.join("\r\n")
|
158
188
|
end
|
159
189
|
|
@@ -192,7 +222,7 @@ module Instana
|
|
192
222
|
end
|
193
223
|
false
|
194
224
|
rescue => e
|
195
|
-
Instana.logger.
|
225
|
+
Instana.logger.error "#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
|
196
226
|
Instana.logger.debug e.backtrace.join("\r\n")
|
197
227
|
return false
|
198
228
|
end
|
@@ -232,8 +262,8 @@ module Instana
|
|
232
262
|
# of type Net::HTTP::Get|Put|Head
|
233
263
|
#
|
234
264
|
def make_host_agent_request(req)
|
235
|
-
req[
|
236
|
-
req[
|
265
|
+
req['Accept'] = MIME_JSON
|
266
|
+
req['Content-Type'] = MIME_JSON
|
237
267
|
|
238
268
|
response = nil
|
239
269
|
Net::HTTP.start(req.uri.hostname, req.uri.port, :open_timeout => 1, :read_timeout => 1) do |http|
|
@@ -241,13 +271,36 @@ module Instana
|
|
241
271
|
end
|
242
272
|
response
|
243
273
|
rescue Errno::ECONNREFUSED => e
|
244
|
-
Instana.logger.debug "Agent not responding. Connection refused."
|
245
274
|
return nil
|
246
275
|
rescue => e
|
247
|
-
Instana.logger.
|
276
|
+
Instana.logger.error "#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
|
277
|
+
Instana.logger.debug e.backtrace.join("\r\n")
|
248
278
|
return nil
|
249
279
|
end
|
250
280
|
|
281
|
+
##
|
282
|
+
# pid_namespace?
|
283
|
+
#
|
284
|
+
# Indicates whether we are running in a pid namespace (such as
|
285
|
+
# Docker).
|
286
|
+
#
|
287
|
+
def pid_namespace?
|
288
|
+
return false unless @is_linux
|
289
|
+
Process.pid != get_real_pid
|
290
|
+
end
|
291
|
+
|
292
|
+
##
|
293
|
+
# get_real_pid
|
294
|
+
#
|
295
|
+
# Attempts to determine the true process ID by querying the
|
296
|
+
# /proc/<pid>/sched file. This works on linux currently.
|
297
|
+
#
|
298
|
+
def get_real_pid
|
299
|
+
raise RuntimeError.new("Unsupported platform: get_real_pid") unless @is_linux
|
300
|
+
v = File.open("/proc/#{Process.pid}/sched", &:readline)
|
301
|
+
v.match(/\d+/).to_s.to_i
|
302
|
+
end
|
303
|
+
|
251
304
|
##
|
252
305
|
# take_snapshot
|
253
306
|
#
|
@@ -258,14 +311,8 @@ module Instana
|
|
258
311
|
data = {}
|
259
312
|
|
260
313
|
data[:sensorVersion] = ::Instana::VERSION
|
261
|
-
data[:pid] = ::Process.pid
|
262
314
|
data[:ruby_version] = RUBY_VERSION
|
263
315
|
|
264
|
-
process = ::ProcTable.ps(Process.pid)
|
265
|
-
arguments = process.cmdline.split(' ')
|
266
|
-
data[:name] = arguments.shift
|
267
|
-
data[:exec_args] = arguments
|
268
|
-
|
269
316
|
# Since a snapshot is only taken on process boot,
|
270
317
|
# this is ok here.
|
271
318
|
data[:start_time] = Time.now.to_s
|
@@ -289,7 +336,7 @@ module Instana
|
|
289
336
|
|
290
337
|
data
|
291
338
|
rescue => e
|
292
|
-
::Instana.logger.
|
339
|
+
::Instana.logger.error "#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
|
293
340
|
::Instana.logger.debug e.backtrace.join("\r\n")
|
294
341
|
return data
|
295
342
|
end
|
@@ -50,7 +50,7 @@ module Instana
|
|
50
50
|
nil
|
51
51
|
end
|
52
52
|
rescue => e
|
53
|
-
::Instana.logger.
|
53
|
+
::Instana.logger.error "#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
|
54
54
|
::Instana.logger.debug e.backtrace.join("\r\n")
|
55
55
|
end
|
56
56
|
end
|
@@ -28,7 +28,7 @@ module Instana
|
|
28
28
|
nil
|
29
29
|
end
|
30
30
|
rescue => e
|
31
|
-
::Instana.logger.
|
31
|
+
::Instana.logger.error "#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
|
32
32
|
::Instana.logger.debug e.backtrace.join("\r\n")
|
33
33
|
end
|
34
34
|
end
|
@@ -26,7 +26,7 @@ module Instana
|
|
26
26
|
nil
|
27
27
|
end
|
28
28
|
rescue => e
|
29
|
-
::Instana.logger.
|
29
|
+
::Instana.logger.error "#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
|
30
30
|
::Instana.logger.debug e.backtrace.join("\r\n")
|
31
31
|
end
|
32
32
|
end
|
data/lib/instana/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: instana
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Giacomo Lombardo
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-11-
|
11
|
+
date: 2016-11-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|