site24x7_apminsight 1.4 → 1.5

Sign up to get free protection for your applications and to get access to all the features.
data/conf/apminsight.conf CHANGED
@@ -71,24 +71,9 @@ transaction.trace.sql.parametrize=true
71
71
  #default value: 3 (second)
72
72
  transaction.trace.sql.stacktrace.threshold=3
73
73
 
74
- #Capture HTTP request input parameters, if enabled.
75
- #To skip recording specific request parameters use webtrasnaction.trace.input.params.ignore key.
76
- #default value: false
77
- webtransaction.trace.input.params.record=false
78
-
79
- #Skip recording confidential request parameters like password, authKey, etc.
80
- #Use comma (,) as parameter names separator.
81
- #If no value is specified all parameters will be recorded.
82
- #Value(s) specified for this key are case sensitive.
83
- webtransaction.trace.input.params.ignore=password, pswd, pass, authKey, parentId, parentID, resourceId, resourceID, id, ID
84
-
85
74
  #Stop listening transactions with specified URL pattern.
86
75
  transaction.skip.listening=*.css, *.js, *.gif, *.jpg, *.jpeg, *.bmp, *.png, *.ico
87
76
 
88
- #Sampling counter. Say for example when you specify the value as 20, agent will track one in 20 transactions.
89
- #default value: 1 (transaction)
90
- transaction.tracking.request.interval=1
91
-
92
77
  #Directory where agent logs information separately.
93
78
  #Defaults to the directory where apminsight-javaagent.jar is installed.
94
79
  #Use forward slash(/) as path separator.
@@ -9,13 +9,13 @@ require "agent/metrics/am_metricscollector"
9
9
  require "agent/metrics/am_metricstore"
10
10
  require "agent/metrics/am_metricsformatter"
11
11
  require "agent/metrics/am_metricsparser"
12
- require "agent/server/instrument/am_instrumenter"
12
+ require "agent/util/transaction_util"
13
13
 
14
14
  module ManageEngine
15
15
 
16
16
  class APMObjectHolder
17
- attr_reader :config,:log,:util,:constants,:shutdown,:connector,:agent,:collector
18
- attr_accessor :shutdown,:agent_initialized,:last_dispatch_time,:instrumenter,:store,:formatter,:parser
17
+ attr_reader :config,:log,:util,:constants,:shutdown,:connector,:agent,:collector, :txn_util
18
+ attr_accessor :shutdown,:agent_initialized,:last_dispatch_time,:store,:formatter,:parser
19
19
  @@objects = nil
20
20
  #Don't Change the Order of Initialize
21
21
  def initializeObjects
@@ -29,7 +29,7 @@ module ManageEngine
29
29
  @connector = ManageEngine::APMConnector.new
30
30
  @store = ManageEngine::APMMetricsStore.new
31
31
  @collector = ManageEngine::APMMetricsCollector.new
32
- @instrumenter = ManageEngine::APMInstrumenter.new
32
+ @txn_util = ManageEngine::TransactionUtil.new
33
33
  @formatter = ManageEngine::APMMetricsFormatter.new
34
34
  @parser = ManageEngine::APMMetricsParser.new
35
35
  @agent = ManageEngine::APMAgent.new
@@ -1,7 +1,7 @@
1
1
  require 'rubygems'
2
2
  require 'json'
3
3
  require 'socket'
4
- require 'rails'
4
+ #require 'rails'
5
5
  require 'agent/am_objectholder'
6
6
  require 'version'
7
7
 
@@ -9,7 +9,7 @@ module ManageEngine
9
9
  class APMConfig
10
10
  attr_reader :agenthost,:agentport,:instance_id,:alreadyconnected,:apmhost,:apmport,:license_key,:site24x7, :site24x7url
11
11
  attr_reader :appname,:proxyneeded, :apdex_t, :trans_trace, :trans_trace_t, :sql_capture, :sql_capture_params, :sql_trace_t,:proxy_user,:proxy_pass, :metric_overflow_t, :trace_overflow_t
12
- attr_reader :proxy_host,:proxy_port ,:is_secured, :logs_dir ,:connection_retry,:agent_enabled,:connect_interval,:db_operations,:include_packages, :url_merge_pattern
12
+ attr_reader :proxy_host,:proxy_port ,:is_secured, :logs_dir ,:connection_retry,:agent_enabled,:connect_interval,:db_operations,:txn_skip_listen, :url_merge_pattern
13
13
  attr_accessor :app_db,:app_dispatcher,:lastupdatedtime
14
14
  def initialize
15
15
  @obj = ManageEngine::APMObjectHolder.instance
@@ -151,7 +151,7 @@ module ManageEngine
151
151
  @connection_retry = 0
152
152
  @connect_interval = 60
153
153
  @apdex_t=0.5
154
- @include_packages=Array.new
154
+ @txn_skip_listen=Array.new
155
155
  @trans_trace_t=2
156
156
  @sql_trace_t=3
157
157
  @metric_overflow_t=250
@@ -190,7 +190,7 @@ module ManageEngine
190
190
  when "apminsight.log.dir" then @logs_dir=value
191
191
  when "agent.connection.retry" then @connection_retry=value #Not in Conf - yet to come
192
192
  when "agent.connection.interval" then @connect_interval=value#Not in Conf - yet to come
193
- when "include.packages" then @include_packages=@obj.util.getArray value,","
193
+ when "transaction.skip.listening" then @txn_skip_listen=@obj.util.getArray value.gsub("\s", ""),","
194
194
  end
195
195
  end
196
196
  end
@@ -221,7 +221,7 @@ module ManageEngine
221
221
  ENV.to_hash.each do |key, value|
222
222
  env[key] = value
223
223
  end
224
- env["Application Path"]="#{Rails.root}"
224
+ #env["Application Path"]="#{Rails.root}"
225
225
  rescue Exception=>e
226
226
  end
227
227
  env
@@ -165,10 +165,7 @@ module ManageEngine
165
165
  dbl = d["db"]
166
166
 
167
167
  rt = pl["rt"].round(2)
168
- path = pl["path"]
169
- name = pl["name"]
170
-
171
- path = @obj.constants.mf_transaction + @obj.constants.mf_separator + path + " " +name
168
+ path = @obj.constants.mf_transaction + @obj.constants.mf_separator + pl["path"]
172
169
 
173
170
 
174
171
  apx_stat = nil
@@ -12,114 +12,40 @@ module ManageEngine
12
12
  @obj = ManageEngine::APMObjectHolder.instance
13
13
  parseddata = Hash.new
14
14
  begin
15
- data.each do |key,val|
16
- @obj.log.debug "[Processing started for - #{key} ]"
17
- #lastHash = val.last
18
- #name = lastHash["name"]
19
- keyForTrans = key
20
- # if(name=="process_action.action_controller")
21
- #Transaction completed
22
- tdata = Hash.new #transaction data -> rt, path,..
23
- trdbdata = Array.new #db data -> sql, operation, rt,..
24
- exceptionData = Hash.new #exception data -> clz name, count
25
- exceptionInfo = Array.new # data to be sent in trace as 'loginfo'
26
- trdata = Array.new #trace data
27
- started = false
28
- redirect=false
29
- ended =false;
30
- start_index = 0;
31
- val.each do |arr|
32
- #@obj.log.debug "Processing : #{arr["name"]}"
33
- if(started || arr["name"]==("start_processing.action_controller") )
34
-
35
- exception = arr["payload"][:exception] #[0-exception clz, 1-exception msg]
36
- if (exception != nil)
37
- exceptionData[exception[0]] = exceptionData[exception[0]].to_i + 1
38
- exceptionData[@obj.constants.mf_logmetric_warning] = exceptionData[@obj.constants.mf_logmetric_warning].to_i + 1
39
- logInfo = {@obj.constants.mf_loginfo_time=>arr["end"].to_i,
40
- @obj.constants.mf_loginfo_level=>@obj.constants.mf_loginfo_level_warn,
41
- @obj.constants.mf_loginfo_str=>exception[1],
42
- @obj.constants.mf_loginfo_err_clz=>exception[0],
43
- @obj.constants.mf_loginfo_st=>arr["payload"][:exception_object] != nil ?
44
- formatStacktrace(arr["payload"][:exception_object].backtrace) : nil}
45
- exceptionInfo.push(logInfo)
46
- end
47
-
48
- if(arr["name"]=="sql.active_record" && @obj.config.sql_capture)
49
- dbd = getDBData(arr)
50
- if tdata.has_key?("db")
51
- tdata["db"].push(dbd)
52
- else
53
- temp = Array.new
54
- temp.push(dbd)
55
- tdata["db"]=temp
56
- end
57
- #trdbdata.push(updateDBTrace(arr,dbd))
58
- #@obj.log.debug "TRANS DBBB TRACE : #{dbd}"
59
- elsif (arr["name"]=="process_action.action_controller")
60
-
61
- tdata["td"]=getTransData(arr,tdata)
62
-
63
- if (exception != nil)
64
- tdata["td"]["error"] = true
65
- end
66
- tdata["td"]["exception"]=exceptionData
67
- #if redirect
68
- # started = false
69
- # redirect=false
70
- # ended =false;
71
- #else
72
- ended = true
73
- started = false
74
- redirect=false
75
- parseddata = updateParsedData key,tdata.dup,parseddata
76
- #@obj.log.info "TRACE #{@obj.config.trans_trace}"
77
- if @obj.config.trans_trace
78
- ret = tdata["td"]
79
- #@obj.log.info "TRACE COMPARE : #{ret["rt"]} > #{(@obj.config.trans_trace_t.to_f*1000).to_i}"
80
- if (ret["rt"]).to_i > (@obj.config.trans_trace_t.to_f* 1000).to_i
81
- tval = val[(start_index)..val.index(arr)]
82
- #@obj.log.debug "Gng To Trace : #{start_index} to #{val.index(arr)}"
83
- parseddata =updateTraceData tval,parseddata,exceptionInfo
84
- end
85
- end
86
- key = key + start_index.to_s
87
- tdata=Hash.new
88
- start_index = val.index(arr)
89
- #end
90
- #trdata = updateTransTrace(arr,trdbdata,trdata);
91
- #@obj.log.info "TRANS TRACE : #{trdata}"
92
- #elsif(arr["name"]==("!render_template.action_view")
93
- #Render Action
94
- #elsif(arr["name"]==("render_template.action_view")
95
- #Render Action data not in use
96
- elsif(arr["name"]==("start_processing.action_controller"))
97
- ended =false;
98
- started=true
99
- #trdata = updateStartTrace(arr,trdata);
100
- #Render Action data not in use
101
- elsif(arr["name"]==("redirect_to.action_controller"))
102
- redirect = true;
103
- end
104
- end
105
-
106
- end # events - do-loop
15
+ data.each do |txn_name, trackers|
16
+ @obj.log.debug "[Processing started for - #{txn_name} ]"
107
17
 
108
- if !ended
109
- @obj.log.debug "Transactions in Thread Continues - so drop data in mem-store #{keyForTrans} -- #{start_index}"
110
- if parseddata.has_key?(keyForTrans)
111
- #@obj.log.info "BEFORE : #{parseddata.keys}"
112
- value = parseddata.delete(keyForTrans)
113
- parseddata[key+"_dup"] = value
114
-
115
- #@obj.log.info "AFTER : #{parseddata.keys}"
116
- end
117
- end
118
- #@obj.log.info "BEFORE METRICS - #{@obj.store.metrics}"
119
- @obj.store.removeData key,0,start_index
120
- #@obj.log.info "AFTER METRICS - #{@obj.store.metrics}"
121
- @obj.log.debug "[Processing END for - #{key} ]"
122
- #end
18
+ trackers.each do |tracker|
19
+
20
+ tdata = Hash.new #transaction data -> rt, path,..
21
+ exceptionInfo = Array.new # data to be sent in trace as 'loginfo'
22
+
23
+ tdata["td"] = getTransData(tracker,tdata)
24
+
25
+ children = tracker.children
26
+ if (children != nil)
27
+ children.each do |child|
28
+
29
+ if child.kind_of?(ManageEngine::Tracker::DatabaseTracker)
30
+ tdata["db"] = getDBData(child, tdata)
31
+ end
32
+
33
+ updateExceptionInfo(child,exceptionInfo)
34
+ end # do - children
35
+ end
36
+
37
+ updateExceptionInfo(tracker, exceptionInfo) # Updating roottracker exception, if any
38
+
39
+ parseddata = updateParsedData(txn_name, tdata.dup, parseddata)
40
+
41
+ if @obj.config.trans_trace && (tracker.duration >= (@obj.config.trans_trace_t.to_f*1000).to_i || tracker.error?)
42
+ parseddata = updateTraceData(tracker, parseddata, exceptionInfo)
43
+ end
44
+
45
+ end # do - trackers
46
+
47
+ @obj.store.removeData txn_name
48
+ @obj.log.debug "[Processing END for - #{txn_name} ]"
123
49
  end # do-loop
124
50
  rescue Exception=>e
125
51
  @obj.log.info "Exception : #{e}"
@@ -130,10 +56,21 @@ module ManageEngine
130
56
  parseddata
131
57
  end
132
58
 
133
- def updateParsedData key , tdata, parseddata
59
+ def updateExceptionInfo (tracker, exceptionInfo)
60
+ if tracker.error?
61
+ logInfo = { @obj.constants.mf_loginfo_time => tracker.endtime.to_i,
62
+ @obj.constants.mf_loginfo_level => @obj.constants.mf_loginfo_level_warn,
63
+ @obj.constants.mf_loginfo_str => tracker.error.message,
64
+ @obj.constants.mf_loginfo_err_clz => tracker.error.class.to_s,
65
+ @obj.constants.mf_loginfo_st => @obj.util.formatStacktrace(tracker.error.backtrace) }
66
+ exceptionInfo.push(logInfo)
67
+ end
68
+ end
69
+
70
+ def updateParsedData (key, tdata, parseddata)
134
71
  begin
135
72
  if parseddata.has_key?(key)
136
- key = @obj.util.currenttimemillis
73
+ key = rand # Use a random number
137
74
  end
138
75
  #@obj.log.debug "Update parsed data : #{key} = > #{tdata}"
139
76
  parseddata[key]=tdata
@@ -145,7 +82,7 @@ module ManageEngine
145
82
  end
146
83
 
147
84
  # Generates Trace for the transaction and updates it in 'parseddata' hash
148
- def updateTraceData val,parseddata,exceptionInfo
85
+ def updateTraceData(rootTracker, parseddata, exceptionInfo)
149
86
  if(parseddata.has_key?("trace-data"))
150
87
  tData = parseddata["trace-data"];
151
88
  if(tData.length == @obj.config.trace_overflow_t)
@@ -160,17 +97,17 @@ module ManageEngine
160
97
  end
161
98
  end
162
99
  begin
163
- trdata = getTrace val
164
- trac = updateTrace(trdata, exceptionInfo)
165
- if(parseddata.has_key?("trace-data"))
166
- traceData = parseddata["trace-data"];
167
- traceData.push(trac);
168
- parseddata["trace-data"] = traceData;
169
- else
170
- traceData = Array.new
171
- traceData.push(trac)
172
- parseddata["trace-data"] = traceData;
173
- end
100
+ trdata = getTrace(rootTracker)
101
+ trac = updateTrace(trdata, exceptionInfo)
102
+ if(parseddata.has_key?("trace-data"))
103
+ traceData = parseddata["trace-data"];
104
+ traceData.push(trac);
105
+ parseddata["trace-data"] = traceData;
106
+ else
107
+ traceData = Array.new
108
+ traceData.push(trac)
109
+ parseddata["trace-data"] = traceData;
110
+ end
174
111
  rescue Exception=>e
175
112
  @obj.log.info "Exception in updateTraceData: #{e}"
176
113
  @obj.log.logException "#{e.message}",e
@@ -195,31 +132,19 @@ module ManageEngine
195
132
  return top
196
133
  end
197
134
 
198
- def getTransData(d,tdata)
199
- pl = d["payload"]
135
+ def getTransData(rootTracker, tdata)
200
136
  ret = nil;
201
137
  begin
202
- if(tdata.has_key?("td"))
203
- ret = tdata["td"]
204
- ret["rt"] = ret["rt"] + (d["end"] - d["start"]).to_i
205
- else
206
- rt = (d["end"] - d["start"]).to_i
207
- path=pl[:path]
208
- #path=pl["path"]
209
-
210
- @obj.config.url_merge_pattern.each do |key, val|
211
- if (path.match(key) != nil)
212
- path=val
213
- break
214
- end
215
- end
216
-
217
- controller=pl[:controller]
218
- #controller=pl["controller"]
219
- action = pl[:action]
220
- #action = pl["action"]
221
- ret ={"rt"=>rt,"path"=>path,"name"=>controller+"#"+action}
222
- end
138
+ if(tdata.has_key?("td"))
139
+ ret = tdata["td"]
140
+ ret["rt"] = ret["rt"] + rootTracker.duration
141
+ else
142
+ ret = {"rt"=> rootTracker.duration, "path"=>rootTracker.name}
143
+ if (rootTracker.error?)
144
+ ret["error"] = true
145
+ updateExceptionMetric(rootTracker.error, ret)
146
+ end
147
+ end
223
148
  rescue Exception=>e
224
149
  @obj.log.info "Exception in getTranseData: #{e}"
225
150
  @obj.log.logException "#{e.message}",e
@@ -228,290 +153,72 @@ module ManageEngine
228
153
  end
229
154
 
230
155
  # Generates DB metric
231
- def getDBData(d)
232
- pl = d["payload"]
233
- rt = (d["end"] - d["start"])
234
- sql = pl[:sql]
235
- #sql = pl["sql"]
236
- sql.strip!
237
- sql.downcase!
238
- sqlArr = sql.split(" ")
239
- sqlStrip="";
240
- tr_name="";
241
- begin
242
- sqlStrip = getSqlStrip sqlArr,false
243
- rescue Exception=>e
244
- @obj.log.logException "#{e.message}",e
245
- sqlStrip = sqlArr[0]+"/-/dummydb"
246
- end
156
+ def getDBData(databaseTracker, tdata)
157
+ dbData = tdata["db"]
158
+ if dbData == nil
159
+ dbData = Array.new
160
+ end
161
+
162
+ queryInfo = databaseTracker.getQueryInfo
163
+ sqlStrip = queryInfo[0] + "/" + queryInfo[1] + "/dummydb"
247
164
 
248
- name=pl[:name]
249
- #name=pl["name"]
250
- ret ={"rt"=>rt,"sql"=>format(sql),"sql-strip"=>sqlStrip,"name"=>name,"operation"=>sqlArr[0]}
165
+ ret ={"rt"=>databaseTracker.duration, "sql"=>databaseTracker.getRawQuery,
166
+ "sql-strip"=>sqlStrip, "name"=>databaseTracker.name, "operation"=>queryInfo[0]}
251
167
 
252
- if (pl[:exception] != nil)
168
+ if (databaseTracker.error?)
253
169
  ret["error"] = true
170
+ updateExceptionMetric(databaseTracker.error, ret)
254
171
  end
255
- ret
256
- end
257
-
258
- def getSqlStrip sqlArr ,trace
259
- sqlStrip =""
260
- begin
261
- sqlStrip = case sqlArr[0]
262
- when "select" then sqlArr[sqlArr.index("from")+1]
263
- when "insert" then sqlArr[sqlArr.index("into")+1]
264
- when "update" then sqlArr[1]
265
- when "delete" then sqlArr[sqlArr.index("from")+1]
266
- when "create" then sqlArr[1] + sqlArr[2]
267
- when "alter" then sqlArr[1] + sqlArr[2]
268
- when "drop" then sqlArr[1] + sqlArr[2]
269
- when "show" then sqlArr[1]
270
- when "describe" then sqlArr[1]
271
- else "-"
272
- end
273
-
274
- if trace
275
- sqlStrip = format(sqlArr[0]) +" - " + format(sqlStrip)
276
- else
277
- sqlStrip = format(sqlArr[0]) +"/" + format(sqlStrip) +"/dummydb"
278
- end
279
-
280
- rescue Exception=>e
281
- @obj.log.logException "#{e.message}",e
282
- if trace
283
- sqlStrip = format(sqlArr[0])
284
- else
285
- sqlStrip = sqlArr[0]+"/-/dummydb"
286
- end
287
- end
288
- end
289
-
290
- def updateDBTrace(d)
291
- pl = d["payload"]
292
- rt = (d["end"] - d["start"])
293
- sql = pl[:sql]
294
- #sql = pl["sql"]
295
- sql.strip!
296
- sql.downcase!
297
- sql = format(sql)
298
- sqlArr = sql.split(" ")
299
172
 
300
- trData = Array.new
301
- #trData[0] = (d["start"].to_f * 1000 ).to_i
302
- trData[0] = d["ctime"]
303
- trData[1] = getSqlStrip sqlArr,true
304
- trData[2] = ""
305
- trData[3] = rt.to_i
306
- trData[4] = rt.to_i
307
- trData[5] = {"query"=>sql}
308
- trData[6] = Array.new
309
- if(!@obj.config.sql_capture_params)
310
- trData[5] = updateQueryParams(d,sql,pl[:binds],rt)
311
- #trData[5] = updateQueryParams(d,sql,pl["binds"],rt)
312
- else
313
- sql = @obj.util.parametrizeQuery sql
314
- trData[5] = {"query"=>sql}
315
- end
316
- trData
173
+ dbData.push(ret)
174
+ dbData
317
175
  end
318
176
 
319
- def updateQueryParams d,sql,binds,rt
320
- ret = {"query"=>sql}
321
- begin
322
- #args = "";
323
- if binds!=nil && binds.size()>0
324
- binds.each do |ar|
325
- #args = args + ar.last + ","
326
- if sql!=nil && sql.index("?")!=nil
327
- sql["?"]=ar.value.to_s
328
- end
329
- end
330
- end
331
- #if args.length>0
332
- # sql = sql + "\\nPARAMS - ["+args+ "]"
333
- #end
334
- ret = {"query"=>sql}
335
- rescue Exception=>exe
336
- @obj.log.logException "Not severe -#{exe.message}",exe
337
- ret = {"query"=>sql}
338
- end
339
-
340
- begin
341
- if(rt.to_i > (@obj.config.sql_trace_t.to_f * "1000".to_f ).to_i && d.has_key?("trace") )
342
- t = updateSQLStackTrace(d["trace"])
343
- ret["stacktrace"] =t
344
- end
345
- rescue Exception=>e
346
- @obj.log.logException "#{e.message}",e
347
- end
348
-
349
- ret
350
- end
351
-
352
- def formatStacktrace(stacktrace)
353
- strace = Array.new;
354
- begin
355
- stacktrace = Rails.backtrace_cleaner.clean(stacktrace)
356
- stacktrace.each do |stackelement|
357
- temp = Array.new
358
- temp[0] = stackelement
359
- temp[1] = ""
360
- temp[2] = ""
361
- temp[3] = ""
362
- strace.push(temp)
363
- if (strace.size == 20)
364
- break;
365
- end
366
- end
367
- rescue Exception=>e
368
- @obj.log.logException "Error while formatting stack trace. #{e.message}", e
369
- end
177
+ def updateExceptionMetric (exception, tdata)
178
+ excData = tdata["exception"]
179
+ if (excData == nil)
180
+ excData = Hash.new
181
+ tdata["exception"] = excData
182
+ end
370
183
 
371
- strace
184
+ excData[exception.class.to_s] = excData[exception.class.to_s].to_i + 1
185
+ excData[@obj.constants.mf_logmetric_warning] = excData[@obj.constants.mf_logmetric_warning].to_i + 1
372
186
  end
373
187
 
374
- def updateSQLStackTrace(d)
375
- trace = Array.new;
376
- started = false;
377
- ended = false;
378
- begin
379
- #@obj.log.debug "STACKTRACE STARTS"
380
- d.each do |arr|
381
-
382
- if started
383
-
384
- end_ind = arr.index("`send_action'")
385
- if end_ind != nil && end_ind >0
386
- ended = true
387
- break;
388
- end
389
- #trArr = arr.split(/:[0-1,in]/);
390
- #if trArr[0].length>30
391
- # len = trArr.length
392
- # trArr[0] = "..."+trArr[(len-30),len]
393
- # end
394
- inx=arr.index("`instrument'")
395
- if inx!=nil && inx>0
396
- #skip instrumet data
397
- else
398
- temp = Array.new
399
- temp[0]=arr
400
- temp[1]=""
401
- temp[2]=""
402
- temp[3]=""
403
- trace.push(temp)
404
- end
405
- end
406
-
407
- if started==false
408
- ind = arr.index("`instrument'")
409
- if ind != nil && ind >0
410
- started = true
411
- end
412
- end
413
-
414
-
415
- end
416
- #@obj.log.debug "STACKTRACE ENDS"
417
-
418
- trace.shift
419
- rescue Exception=>e
420
- @obj.log.logException "#{e.message}",e
421
- end
422
- trace
423
- end
424
-
425
- def updateOtherTrace d
426
- pl = d["payload"]
427
- rt = (d["end"] - d["start"])
428
- name = d["name"]
429
- if pl.has_key?(:identifier)
430
- #if pl.has_key?("identifier")
431
- name = pl[:identifier]
432
- #name = pl["identifier"]
433
- end
188
+ def updateDBTrace(dbTracker)
434
189
  trData = Array.new
435
- #trData[0] = (d["start"].to_f * 1000 ).to_i
436
- trData[0] = d["ctime"]
437
- trData[1] = name
438
- trData[2] = ""
439
- trData[3] = rt.to_i
440
- trData[4] = rt.to_i
441
- trData[5] = nil
442
- trData[6] = Array.new
443
- trData
444
- end
445
-
446
- def updateTransTrace(d,trData)
447
-
448
- #trData = Array.new
449
- #trData[0] = ((d["start"]).to_f * 1000).to_i
450
- pl = d["payload"]
451
- path = pl[:path]
452
- @obj.config.url_merge_pattern.each do |key, val|
453
- if (path.match(key) != nil)
454
- path=val
455
- break
456
- end
457
- end
458
- trData[1] = path + " " +pl[:controller] + "#" + pl[:action]
459
- #trData[1] = pl["path"] + " " +pl["controller"] + "#" + pl["action"]
190
+ trData[0] = dbTracker.starttime
191
+ queryInfo = dbTracker.getQueryInfo
192
+ trData[1] = queryInfo[0] + " - " + queryInfo[1]
460
193
  trData[2] = ""
461
- trData[3] = (d["end"] - trData[0]).to_i
462
- trData[4] = (d["end"] - trData[0]).to_i
463
- # trData[5] = nil
464
- exception = pl[:exception_object]
465
- if (exception != nil)
466
- trData[5] = {@obj.constants.mf_exception_st=>formatStacktrace(exception.backtrace)}
467
- else
468
- trData[5] = nil
469
- end
470
- #trData[6] = Array.new
471
- #dbTime = 0
472
- #trdbdata.each do |dbData|
473
- # dbTime = dbTime + dbData[3]
474
- #end
475
- #trData[4] = ((trData[3]).to_f - (dbTime.to_f )).to_i
476
- # if(pl[:db_runtime]!=nil)
477
- # trData[4] = ((trData[3]).to_f - (pl[:db_runtime].to_f )).to_i
478
- # end
194
+ trData[3] = dbTracker.duration.to_i
195
+ trData[4] = trData[3]
196
+ trData[5] = dbTracker.getAdditionalInfo
197
+ trData[6] = Array.new
479
198
  trData
480
199
  end
481
200
 
482
- def updateMethodTrace(d,trData)
483
-
484
- #trData = Array.new
485
- #trData[0] = ((d["start"]).to_f * 1000).to_i
486
- pl = d["payload"]
487
- trData[1] = pl[:method]
488
- #trData[1] = pl["method"]
489
- trData[2] = ""
490
- trData[3] = (d["end"] - trData[0]).to_i
491
- trData[4] = (d["end"] - trData[0]).to_i
492
- trData[5] = nil
493
- #trData[6] = Array.new
494
- #dbTime = 0
495
- #trdbdata.each do |dbData|
496
- # dbTime = dbTime + dbData[3]
497
- #end
498
- #trData[4] = ((trData[3]).to_f - (dbTime.to_f )).to_i
499
- # if(pl[:db_runtime]!=nil)
500
- # trData[4] = ((trData[3]).to_f - (pl[:db_runtime].to_f )).to_i
501
- # end
201
+ def updateOtherTrace(tracker)
202
+ trData = Array.new
203
+ trData[0] = tracker.starttime
204
+ trData[1] = tracker.name
205
+ trData[2] = ""
206
+ trData[3] = tracker.duration
207
+ trData[4] = tracker.duration
208
+ trData[5] = tracker.getAdditionalInfo
209
+ trData[6] = Array.new
502
210
  trData
503
211
  end
504
212
 
505
- def updateStartTrace(d)
213
+ def updateStartTrace(rootTracker)
506
214
  trData = Array.new
507
- #trData[0] = ((d["start"]).to_f * 1000).to_i
508
- trData[0] = d["ctime"]
509
- trData[1] =""
510
- trData[2] =""
511
- trData[3] =0
512
- trData[4] =0
513
- trData[5] =nil
514
- trData[6] =Array.new
215
+ trData[0] = rootTracker.starttime
216
+ trData[1] = rootTracker.name # tracker name
217
+ trData[2] = "" # component
218
+ trData[3] = rootTracker.duration # total time
219
+ trData[4] = trData[3] # exclusive time
220
+ trData[5] = rootTracker.getAdditionalInfo # additional info
221
+ trData[6] = Array.new # children
515
222
 
516
223
  trData
517
224
  end
@@ -535,110 +242,33 @@ module ManageEngine
535
242
  top[1] = trans
536
243
  top
537
244
  end
538
-
539
- def format s
540
- s.gsub!("\"", '')
541
- s.gsub!("\n", '')
542
- s
543
- end
544
-
545
245
 
546
- def getTrace data
547
- index = 0
548
- data.each do |arr|
549
-
550
- if(arr["name"]=="start_processing.action_controller")
551
- index = data.index(arr)
552
- break;
553
- end
554
- end
555
- data = data.drop(index)
556
- tdata =traceDetails data,Array.new,0
557
- tdata = updateExclusiveTrace(tdata[0])
246
+ def getTrace(rootTracker)
247
+ tdata = traceDetails(rootTracker)
248
+ tdata = updateExclusiveTrace(tdata)
558
249
  tdata
559
250
  end
560
251
 
561
- def traceDetails valo,stack,indx
562
- if(valo.size>indx)
563
- arr = valo[indx]
564
- indx = indx+1
565
- if(arr["name"]=="start_processing.action_controller")
566
- traceArr = updateStartTrace arr
567
- traceArr[6] = Array.new #childs
568
- # if stack.size()>0
569
- # cur = stack[stack.size()-1]
570
- # c = cur[6]
571
- # c.push(traceArr)
572
- # cur[6] = c
573
- # end
574
- # stack.push(traceArr)
575
-
576
- # Incase there are multiple "start_processing" event consider only the last notification
577
- if stack.size == 0
578
- stack.push(traceArr)
579
- else
580
- stack[stack.size()-1] = traceArr
581
- end
582
-
583
- traceDetails valo,stack,indx
584
-
585
- elsif(arr["name"]=="sql.active_record" && @obj.config.sql_capture )
586
-
587
- temp = updateDBTrace arr
588
-
589
- cur = stack[stack.size()-1]
590
- c = cur[6]
591
- c.push(temp)
592
- cur[6] = c
593
- traceDetails valo,stack,indx
594
- elsif(arr["name"]=="apm.methodstart")
595
- temp = updateStartTrace arr
596
- cur = stack[stack.size()-1]
597
- c = cur[6]
598
- c.push(temp)
599
- cur[6] = c
600
- stack.push(temp)
601
- traceDetails valo,stack,indx
602
- elsif(arr["name"]=="apm.methodend")
603
- updateMethodTrace(arr,stack[stack.size()-1])
604
- stack.delete(stack[stack.size()-1])
605
- traceDetails valo,stack,indx
606
- elsif(arr["name"]=="process_action.action_controller")
607
- updateTransTrace(arr,stack[stack.size()-1])
608
- if(valo.size()>(indx+1))
609
- #Redirection Data
610
- #Skipping all the "start_processing" event after "process_action" event
611
- arr = valo[indx]
612
- while (arr["name"]!="start_processing.action_controller") do
613
- indx = indx + 1
614
- arr = valo[indx]
615
- end
616
- end
617
- (stack[0])[3] = (arr["end"] - ((stack[0])[0])).to_i
618
- (stack[0])[4] = (arr["end"] - ((stack[0])[0])).to_i
619
-
620
-
621
- traceDetails valo,stack,indx
622
- #parent[4] = parent[4] - traceArr[4]
623
- elsif (arr["name"]=="render_template.action_view")
624
- temp = updateOtherTrace arr
625
-
626
- cur = stack[stack.size()-1]
627
- c = cur[6]
628
- c.push(temp)
629
- cur[6] = c
630
- #traceArr[6] = c
631
- #parent[4] = parent[4] - temp[4]
632
- traceDetails valo,stack,indx
633
- else
634
- traceDetails valo,stack,indx
635
-
636
- end
637
-
638
- stack
639
- else
640
- #Nothing todo
641
- end
252
+ def traceDetails rootTracker
253
+
254
+ traceArr = updateStartTrace(rootTracker)
255
+
256
+ children = rootTracker.children
257
+ if (children != nil)
258
+ children.each do |child|
259
+
260
+ if child.kind_of?(ManageEngine::Tracker::DatabaseTracker)
261
+ dbTrace = updateDBTrace(child)
262
+ traceArr[6].push(dbTrace)
263
+ else
264
+ trace = updateOtherTrace(child)
265
+ traceArr[6].push(trace)
266
+ end
267
+
268
+ end # do - children
269
+ end # if children
270
+
271
+ traceArr
642
272
  end
643
273
 
644
274