site24x7_apminsight 1.4 → 1.5
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/conf/apminsight.conf +0 -15
- data/lib/agent/am_objectholder.rb +4 -4
- data/lib/agent/configuration/am_configuration.rb +5 -5
- data/lib/agent/metrics/am_metricsformatter.rb +1 -4
- data/lib/agent/metrics/am_metricsparser.rb +139 -509
- data/lib/agent/metrics/am_metricstore.rb +7 -6
- data/lib/agent/server/am_agent.rb +3 -1
- data/lib/agent/server/am_connector.rb +5 -8
- data/lib/agent/server/instrument/active_record.rb +50 -0
- data/lib/agent/server/instrument/am_apm.rb +107 -97
- data/lib/agent/server/instrument/am_instrumenter.rb +54 -42
- data/lib/agent/server/instrument/environment.rb +29 -0
- data/lib/agent/server/instrument/rails.rb +56 -0
- data/lib/agent/server/instrument/sinatra.rb +96 -0
- data/lib/agent/trackers/database_tracker.rb +107 -0
- data/lib/agent/trackers/default_tracker.rb +49 -0
- data/lib/agent/trackers/root_tracker.rb +46 -0
- data/lib/agent/util/am_constants.rb +2 -1
- data/lib/agent/util/am_util.rb +21 -0
- data/lib/agent/util/transaction_util.rb +35 -0
- data/lib/version.rb +2 -2
- data/site24x7-agent.gemspec +12 -23
- metadata +26 -18
@@ -17,12 +17,13 @@ module ManageEngine
|
|
17
17
|
@metrics.dup
|
18
18
|
end
|
19
19
|
|
20
|
-
def removeData key
|
21
|
-
if @metrics.has_key?(key)
|
22
|
-
val = @metrics[key]
|
23
|
-
val = val.drop(end_indx)
|
24
|
-
@metrics[key]=val
|
25
|
-
end
|
20
|
+
def removeData key
|
21
|
+
# if @metrics.has_key?(key)
|
22
|
+
# val = @metrics[key]
|
23
|
+
# val = val.drop(end_indx)
|
24
|
+
# @metrics[key]=val
|
25
|
+
# end
|
26
|
+
@metrics.delete(key)
|
26
27
|
end
|
27
28
|
|
28
29
|
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require "agent/am_objectholder"
|
2
2
|
require "agent/server/worker/am_worker"
|
3
|
+
require "agent/server/instrument/environment"
|
3
4
|
|
4
5
|
require 'socket'
|
5
6
|
|
@@ -12,7 +13,8 @@ module ManageEngine
|
|
12
13
|
|
13
14
|
if !@obj.shutdown && @obj.agent_initialized
|
14
15
|
@obj.log.info "Agent Initialization - DONE"
|
15
|
-
|
16
|
+
ManageEngine::Environment.new.detect_and_instrument
|
17
|
+
|
16
18
|
doDispatcherActions
|
17
19
|
doCollect
|
18
20
|
puts "APM Insight Ruby Agent Started"
|
@@ -146,8 +146,11 @@ module ManageEngine
|
|
146
146
|
response_action srCode
|
147
147
|
end
|
148
148
|
if data.has_key?(@obj.constants.custom_config_info)
|
149
|
-
|
150
|
-
|
149
|
+
config_info = data[@obj.constants.custom_config_info]
|
150
|
+
if data.has_key?(@obj.constants.agent_specific_info)
|
151
|
+
config_info = config_info.merge(data[@obj.constants.agent_specific_info])
|
152
|
+
end
|
153
|
+
update_config config_info
|
151
154
|
end
|
152
155
|
end
|
153
156
|
return data
|
@@ -207,9 +210,6 @@ module ManageEngine
|
|
207
210
|
end
|
208
211
|
|
209
212
|
def unManage
|
210
|
-
@obj.instrumenter.doUnSubscribe
|
211
|
-
@obj.instrumenter =nil
|
212
|
-
@obj.instrumenter = ManageEngine::APMInstrumenter.new
|
213
213
|
uManage = Hash.new
|
214
214
|
uManage["agent.id"]=@obj.config.instance_id
|
215
215
|
uManage["agent.enabled"]=false
|
@@ -217,7 +217,6 @@ module ManageEngine
|
|
217
217
|
end
|
218
218
|
|
219
219
|
def manage
|
220
|
-
@obj.instrumenter.doSubscribe
|
221
220
|
uManage = Hash.new
|
222
221
|
uManage["agent.id"]=@obj.config.instance_id
|
223
222
|
uManage["agent.enabled"]=true
|
@@ -225,8 +224,6 @@ module ManageEngine
|
|
225
224
|
end
|
226
225
|
|
227
226
|
def deleteAgent
|
228
|
-
@obj.instrumenter.doUnSubscribe
|
229
|
-
@obj.instrumenter =nil
|
230
227
|
uManage = Hash.new
|
231
228
|
uManage["agent.id"]=@obj.config.instance_id
|
232
229
|
uManage["agent.enabled"]=false
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'agent/am_objectholder'
|
2
|
+
require 'agent/trackers/database_tracker'
|
3
|
+
|
4
|
+
module ManageEngine
|
5
|
+
module Instrumentation
|
6
|
+
class ActiveRecordSQL
|
7
|
+
|
8
|
+
def present?
|
9
|
+
defined?(::ActiveRecord::Base) && defined?(::ActiveSupport::Notifications)
|
10
|
+
end
|
11
|
+
|
12
|
+
def name
|
13
|
+
'ActiveRecord'
|
14
|
+
end
|
15
|
+
|
16
|
+
def instrument
|
17
|
+
@obj = ManageEngine::APMObjectHolder.instance
|
18
|
+
@obj.log.info "Instrumenting ActiveRecord"
|
19
|
+
|
20
|
+
ActiveSupport::Notifications.subscribe('sql.active_record') do |name, start, finish, id, payload|
|
21
|
+
begin
|
22
|
+
if @obj.config.agent_enabled && @obj.config.sql_capture && payload[:name] != "SCHEMA" # Dropping internal schema related queries
|
23
|
+
tracker = Thread.current[:apminsight]
|
24
|
+
if tracker != nil
|
25
|
+
dbTracker = ManageEngine::Tracker::DatabaseTracker.new(payload[:name], start.to_f * 1000)
|
26
|
+
dbTracker.sql(payload[:sql])
|
27
|
+
dbTracker.params(payload[:binds])
|
28
|
+
dbTracker.finish(finish.to_f * 1000)
|
29
|
+
|
30
|
+
if dbTracker.duration >= @obj.config.sql_trace_t.to_f
|
31
|
+
dbTracker.sqlBacktrace(caller(10))
|
32
|
+
end
|
33
|
+
|
34
|
+
exception = payload[:exception_object]
|
35
|
+
if exception != nil
|
36
|
+
dbTracker.setError(exception)
|
37
|
+
end
|
38
|
+
|
39
|
+
tracker.addChild(dbTracker)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
rescue Exception => e
|
43
|
+
@obj.log.logException("Error processing #{name} payload", e)
|
44
|
+
end
|
45
|
+
end #subscribe
|
46
|
+
end #def instrument
|
47
|
+
|
48
|
+
end #class ActiveRecordSQL
|
49
|
+
end
|
50
|
+
end
|
@@ -1,99 +1,109 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
class Class
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
begin
|
8
|
-
if(block==nil || block=="")
|
9
|
-
result = old_new(*args)
|
10
|
-
elsif
|
11
|
-
result = old_new(*args,&block)
|
12
|
-
end
|
13
|
-
rescue Exception=>exe
|
14
|
-
raise exe
|
15
|
-
result = self
|
16
|
-
end
|
17
|
-
me_apm_injector(self,result)
|
18
|
-
|
19
|
-
return result
|
20
|
-
end
|
21
|
-
end
|
1
|
+
##
|
2
|
+
##
|
3
|
+
# Currently disabling this class, since it will be called for every class's instance creation (Class.new is aliased here)
|
4
|
+
# This can be used for custom instrumentation.
|
5
|
+
##
|
6
|
+
##
|
22
7
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
#require 'agent/am_objectholder'
|
12
|
+
#@obj = ManageEngine::APMObjectHolder.instance
|
13
|
+
#class Class
|
14
|
+
# alias old_new new
|
15
|
+
# def new(*args, &block)
|
16
|
+
# result =nil;
|
17
|
+
# begin
|
18
|
+
# if(block==nil || block=="")
|
19
|
+
# result = old_new(*args)
|
20
|
+
# elsif
|
21
|
+
# result = old_new(*args,&block)
|
22
|
+
# end
|
23
|
+
# rescue Exception=>exe
|
24
|
+
# raise exe
|
25
|
+
# result = self
|
26
|
+
# end
|
27
|
+
# me_apm_injector(self,result)
|
28
|
+
#
|
29
|
+
# return result
|
30
|
+
# end
|
31
|
+
# end
|
32
|
+
#
|
33
|
+
#def me_apm_injector(s,result)
|
34
|
+
# begin
|
35
|
+
# if(ManageEngine::APMObjectHolder.instance.config.include_packages.index(s.name)!=nil)
|
36
|
+
# ms =s.instance_methods(false)
|
37
|
+
# cms = s.methods(false)
|
38
|
+
# begin
|
39
|
+
# ms.each do |m|
|
40
|
+
# if( m.to_s.index("APMTEST"))
|
41
|
+
# return;
|
42
|
+
# end
|
43
|
+
# end
|
44
|
+
# cms.each do |m|
|
45
|
+
# if( m.to_s.index("APMTEST"))
|
46
|
+
# return;
|
47
|
+
# end
|
48
|
+
# end
|
49
|
+
# rescue Exception=>e
|
50
|
+
# return;
|
51
|
+
# end
|
52
|
+
# ManageEngine::APMObjectHolder.instance.log.debug "Injection Method : #{ms} "
|
53
|
+
# ManageEngine::APMObjectHolder.instance.log.debug "Injection Class Method : #{cms} "
|
54
|
+
# ms.each do |m|
|
55
|
+
# mn = m.to_s
|
56
|
+
# #ManageEngine::APMObjectHolder.instance.log.info "ManageEngine Monitor Method : #{s.name} # #{m.to_s}"
|
57
|
+
# omn = "APMTEST"+mn+"APMTEST"
|
58
|
+
# s.class_eval %{
|
59
|
+
# alias_method :#{omn}, :#{mn}
|
60
|
+
# def #{mn} *args, &block
|
61
|
+
# begin
|
62
|
+
# ActiveSupport::Notifications.instrument("apm.methodstart", {:method=>"#{mn}",:args=>args})
|
63
|
+
# res = #{omn} *args, &block
|
64
|
+
# ActiveSupport::Notifications.instrument("apm.methodend", {:method=>"#{mn}",:args=>args})
|
65
|
+
# return res
|
66
|
+
# rescue Exception => exe
|
67
|
+
# puts "error in calling method"
|
68
|
+
# raise exe
|
69
|
+
# ensure
|
70
|
+
# end
|
71
|
+
# end
|
72
|
+
# }
|
73
|
+
# end#do
|
74
|
+
# default_methods = Array.new
|
75
|
+
# default_methods.push("_helpers");
|
76
|
+
# default_methods.push("middleware_stack");
|
77
|
+
# default_methods.push("helpers_path");
|
78
|
+
# default_methods.push("_wrapper_options");
|
79
|
+
# cms.each do |m|
|
80
|
+
# if(default_methods.index(m.to_s)==nil)
|
81
|
+
# mn = m.to_s
|
82
|
+
# #ManageEngine::APMObjectHolder.instance.log.debug "ManageEngine Monitor Singleton Method : #{s.name} ---> #{m.to_s}"
|
83
|
+
# omn = "APMTEST"+mn+"APMTEST"
|
84
|
+
# s.instance_eval %{
|
85
|
+
# class << self
|
86
|
+
# alias_method :#{omn}, :#{mn}
|
87
|
+
# end
|
88
|
+
# def self.#{mn} *args, &block
|
89
|
+
# begin
|
90
|
+
# ActiveSupport::Notifications.instrument("apm.methodstart", {:method=>"#{mn}",:args=>args})
|
91
|
+
# res = #{omn} *args, &block
|
92
|
+
# ActiveSupport::Notifications.instrument("apm.methodend", {:method=>"#{mn}",:args=>args})
|
93
|
+
# return res
|
94
|
+
# rescue Exception=>exe
|
95
|
+
# puts "Instrument : error in calling class method"
|
96
|
+
# raise exe
|
97
|
+
# ensure
|
98
|
+
# end
|
99
|
+
# end
|
100
|
+
# }
|
101
|
+
# end
|
102
|
+
# end#do
|
103
|
+
# end#if
|
104
|
+
# rescue Exception=>e
|
105
|
+
# puts "Exception in instrument : #{e}"
|
106
|
+
# ensure
|
107
|
+
# end
|
108
|
+
#end
|
99
109
|
|
@@ -1,43 +1,55 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
class APMInstrumenter
|
5
|
-
@t =nil;
|
6
|
-
def initialize
|
7
|
-
@obj=ManageEngine::APMObjectHolder.instance
|
8
|
-
end
|
1
|
+
##
|
2
|
+
## This is Rails framework specific tracking mechanism, they are moved to multiple files for separate tracking
|
3
|
+
##
|
9
4
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
5
|
+
#require 'agent/am_objectholder'
|
6
|
+
#require 'socket'
|
7
|
+
#module ManageEngine
|
8
|
+
# class APMInstrumenter
|
9
|
+
# @t =nil;
|
10
|
+
# def initialize
|
11
|
+
# @obj=ManageEngine::APMObjectHolder.instance
|
12
|
+
# end
|
13
|
+
#
|
14
|
+
# def doSubscribe
|
15
|
+
# @obj=ManageEngine::APMObjectHolder.instance
|
16
|
+
# @obj.log.debug "[ instrumenter ] [ Subscriber for Agent ]"
|
17
|
+
# @subscriber = ActiveSupport::Notifications.subscribe do |name, start, finish, id, payload|
|
18
|
+
# if(ManageEngine::APMObjectHolder.instance.config.agent_enabled)
|
19
|
+
# #rt = (finish-start).to_i
|
20
|
+
# ManageEngine::APMWorker.getInstance.start
|
21
|
+
# ManageEngine::APMObjectHolder.instance.log.debug "[ Notifications for Agent ] #{Thread.current} #{id} #{name} - #{payload[:path]}"
|
22
|
+
# #trace= caller;
|
23
|
+
# #puts ">>> Threadlocal var : #{Thread.current[:apminsight]}"
|
24
|
+
# if name=="sql.active_record"
|
25
|
+
# #Thread.current[:apminsight] = "#{Thread.current[:apminsight]} + #{payload[:sql]}"
|
26
|
+
# if payload[:name] != "SCHEMA"
|
27
|
+
# @obj.log.debug ">>>>>>>> SQL: #{payload[:sql]}"
|
28
|
+
# end
|
29
|
+
# @obj.log.debug "~~~~~ SQL Payload: #{payload}"
|
30
|
+
# end
|
31
|
+
# id = "#{Thread.current}"
|
32
|
+
# stats = Hash.new
|
33
|
+
# stats["name"] = name;
|
34
|
+
# stats["start"] = start.to_f * 1000;
|
35
|
+
# stats["end"] = finish.to_f * 1000;
|
36
|
+
# stats["id"] = id;
|
37
|
+
# stats["payload"] = payload;
|
38
|
+
# if (name=="sql.active_record" && (finish.to_f - start.to_f)>=(ManageEngine::APMObjectHolder.instance.config.sql_trace_t).to_f)
|
39
|
+
# stats["trace"] = caller(20); # Taking stacktrace of depth 20
|
40
|
+
# end
|
41
|
+
# stats["ctime"] =ManageEngine::APMObjectHolder.instance.util.currenttimemillis;
|
42
|
+
# ManageEngine::APMObjectHolder.instance.collector.updateTransaction(id,stats);
|
43
|
+
# else
|
44
|
+
# ActiveSupport::Notifications.unsubscribe @subscriber
|
45
|
+
# @obj.log.info "[ instrumenter ] [ RETURNING NO METRICS] "
|
46
|
+
# end
|
47
|
+
# end
|
48
|
+
# end
|
49
|
+
#
|
50
|
+
# def doUnSubscribe
|
51
|
+
# ActiveSupport::Notifications.unsubscribe @subscriber
|
52
|
+
# end
|
53
|
+
#
|
54
|
+
#end #class
|
55
|
+
#end#module
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'agent/server/instrument/rails'
|
2
|
+
require 'agent/server/instrument/sinatra'
|
3
|
+
require 'agent/server/instrument/active_record'
|
4
|
+
|
5
|
+
module ManageEngine
|
6
|
+
class Environment
|
7
|
+
|
8
|
+
SUPPORTED_FRAMEWORKS = [
|
9
|
+
ManageEngine::Instrumentation::RailsFramework.new,
|
10
|
+
ManageEngine::Instrumentation::SinatraFramework.new
|
11
|
+
]
|
12
|
+
|
13
|
+
DATABASE_INTERCEPTORS = [
|
14
|
+
ManageEngine::Instrumentation::ActiveRecordSQL.new
|
15
|
+
]
|
16
|
+
|
17
|
+
def detect_and_instrument
|
18
|
+
@framework ||= SUPPORTED_FRAMEWORKS.detect{ |framework| framework.present? }
|
19
|
+
@framework.instrument
|
20
|
+
|
21
|
+
DATABASE_INTERCEPTORS.each do |interceptor|
|
22
|
+
if (interceptor.present?)
|
23
|
+
interceptor.instrument
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|