site24x7_apminsight 1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE.txt +60 -0
- data/README.rdoc +67 -0
- data/Rakefile +63 -0
- data/VERSION +1 -0
- data/conf/apminsight.conf +96 -0
- data/lib/agent/am_objectholder.rb +66 -0
- data/lib/agent/configuration/am_configuration.rb +268 -0
- data/lib/agent/logging/am_logger.rb +109 -0
- data/lib/agent/metrics/am_metricscollector.rb +30 -0
- data/lib/agent/metrics/am_metricsformatter.rb +277 -0
- data/lib/agent/metrics/am_metricsparser.rb +569 -0
- data/lib/agent/metrics/am_metricstore.rb +29 -0
- data/lib/agent/server/am_agent.rb +116 -0
- data/lib/agent/server/am_connector.rb +242 -0
- data/lib/agent/server/instrument/am_apm.rb +99 -0
- data/lib/agent/server/instrument/am_instrumenter.rb +43 -0
- data/lib/agent/server/worker/am_worker.rb +271 -0
- data/lib/agent/util/am_constants.rb +80 -0
- data/lib/agent/util/am_util.rb +130 -0
- data/lib/site24x7_apminsight.rb +5 -0
- metadata +131 -0
@@ -0,0 +1,569 @@
|
|
1
|
+
require 'agent/am_objectholder'
|
2
|
+
|
3
|
+
module ManageEngine
|
4
|
+
class APMMetricsParser
|
5
|
+
def initialize
|
6
|
+
@obj = ManageEngine::APMObjectHolder.instance
|
7
|
+
end
|
8
|
+
def parse(data)
|
9
|
+
@obj = ManageEngine::APMObjectHolder.instance
|
10
|
+
parseddata = Hash.new
|
11
|
+
begin
|
12
|
+
data.each do |key,val|
|
13
|
+
@obj.log.debug "[Processing started for - #{key} ]"
|
14
|
+
#lastHash = val.last
|
15
|
+
#name = lastHash["name"]
|
16
|
+
keyForTrans = key
|
17
|
+
# if(name=="process_action.action_controller")
|
18
|
+
#Transaction completed
|
19
|
+
tdata = Hash.new
|
20
|
+
trdbdata = Array.new
|
21
|
+
trdata = Array.new
|
22
|
+
started = false
|
23
|
+
redirect=false
|
24
|
+
ended =false;
|
25
|
+
start_index = 0;
|
26
|
+
val.each do |arr|
|
27
|
+
#@obj.log.debug "Processing : #{arr["name"]}"
|
28
|
+
if(started || arr["name"]==("start_processing.action_controller") )
|
29
|
+
|
30
|
+
if(arr["name"]=="sql.active_record" && @obj.config.sql_capture)
|
31
|
+
dbd = getDBData(arr)
|
32
|
+
if tdata.has_key?("db")
|
33
|
+
tdata["db"].push(dbd)
|
34
|
+
else
|
35
|
+
temp = Array.new
|
36
|
+
temp.push(dbd)
|
37
|
+
tdata["db"]=temp
|
38
|
+
end
|
39
|
+
#trdbdata.push(updateDBTrace(arr,dbd))
|
40
|
+
#@obj.log.debug "TRANS DBBB TRACE : #{dbd}"
|
41
|
+
elsif (arr["name"]=="process_action.action_controller")
|
42
|
+
|
43
|
+
tdata["td"]=getTransData(arr,tdata)
|
44
|
+
#if redirect
|
45
|
+
# started = false
|
46
|
+
# redirect=false
|
47
|
+
# ended =false;
|
48
|
+
#else
|
49
|
+
ended = true
|
50
|
+
started = false
|
51
|
+
redirect=false
|
52
|
+
parseddata = updateParsedData key,tdata.dup,parseddata
|
53
|
+
#@obj.log.info "TRACE #{@obj.config.trans_trace}"
|
54
|
+
if @obj.config.trans_trace
|
55
|
+
ret = tdata["td"]
|
56
|
+
#@obj.log.info "TRACE COMPARE : #{ret["rt"]} > #{(@obj.config.trans_trace_t.to_f*1000).to_i}"
|
57
|
+
if (ret["rt"]).to_i > (@obj.config.trans_trace_t.to_f* 1000).to_i
|
58
|
+
tval = val[(start_index)..val.index(arr)]
|
59
|
+
#@obj.log.debug "Gng To Trace : #{start_index} to #{val.index(arr)}"
|
60
|
+
parseddata =updateTraceData tval,parseddata
|
61
|
+
end
|
62
|
+
end
|
63
|
+
key = key + start_index.to_s
|
64
|
+
tdata=Hash.new
|
65
|
+
start_index = val.index(arr)
|
66
|
+
#end
|
67
|
+
#trdata = updateTransTrace(arr,trdbdata,trdata);
|
68
|
+
#@obj.log.info "TRANS TRACE : #{trdata}"
|
69
|
+
#elsif(arr["name"]==("!render_template.action_view")
|
70
|
+
#Render Action
|
71
|
+
#elsif(arr["name"]==("render_template.action_view")
|
72
|
+
#Render Action data not in use
|
73
|
+
elsif(arr["name"]==("start_processing.action_controller"))
|
74
|
+
ended =false;
|
75
|
+
started=true
|
76
|
+
#trdata = updateStartTrace(arr,trdata);
|
77
|
+
#Render Action data not in use
|
78
|
+
elsif(arr["name"]==("redirect_to.action_controller"))
|
79
|
+
redirect = true;
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
if !ended
|
86
|
+
@obj.log.debug "Transactions in Thread Continues - so drop data in mem-store #{keyForTrans} -- #{start_index}"
|
87
|
+
if parseddata.has_key?(keyForTrans)
|
88
|
+
#@obj.log.info "BEFORE : #{parseddata.keys}"
|
89
|
+
value = parseddata.delete(keyForTrans)
|
90
|
+
parseddata[key+"_dup"] = value
|
91
|
+
|
92
|
+
#@obj.log.info "AFTER : #{parseddata.keys}"
|
93
|
+
end
|
94
|
+
end
|
95
|
+
#@obj.log.info "BEFORE METRICS - #{@obj.store.metrics}"
|
96
|
+
@obj.store.removeData key,0,start_index
|
97
|
+
#@obj.log.info "AFTER METRICS - #{@obj.store.metrics}"
|
98
|
+
@obj.log.debug "[Processing END for - #{key} ]"
|
99
|
+
#end
|
100
|
+
end
|
101
|
+
rescue Exception=>e
|
102
|
+
@obj.log.info "Exception : #{e}"
|
103
|
+
@obj.log.logException "#{e.message}",e
|
104
|
+
end
|
105
|
+
# @obj.log.debug "[PARSER] End"
|
106
|
+
parseddata
|
107
|
+
end
|
108
|
+
|
109
|
+
def updateParsedData key , tdata, parseddata
|
110
|
+
begin
|
111
|
+
if parseddata.has_key?(key)
|
112
|
+
key = @obj.util.currenttimemillis
|
113
|
+
end
|
114
|
+
#@obj.log.debug "Update parsed data : #{key} = > #{tdata}"
|
115
|
+
parseddata[key]=tdata
|
116
|
+
rescue Exception=>e
|
117
|
+
@obj.log.info "Exception in updateParsedData: #{e}"
|
118
|
+
@obj.log.logException "#{e.message}",e
|
119
|
+
end
|
120
|
+
parseddata
|
121
|
+
end
|
122
|
+
def updateTraceData val,parseddata
|
123
|
+
if(parseddata.has_key?("trace-data"))
|
124
|
+
tData = parseddata["trace-data"];
|
125
|
+
if(tData.length == @obj.config.trace_overflow_t)
|
126
|
+
trac = getDummyTrace
|
127
|
+
tData.push(trac)
|
128
|
+
parseddata["trace-data"]=tData
|
129
|
+
@obj.log.debug "dummy trace added"
|
130
|
+
return parseddata
|
131
|
+
elsif tData.length > @obj.config.trace_overflow_t
|
132
|
+
@obj.log.debug "trace threshold exceeded"
|
133
|
+
return parseddata
|
134
|
+
end
|
135
|
+
end
|
136
|
+
begin
|
137
|
+
trdata = getTrace val
|
138
|
+
trac = updateTrace(trdata)
|
139
|
+
if(parseddata.has_key?("trace-data"))
|
140
|
+
traceData = parseddata["trace-data"];
|
141
|
+
traceData.push(trac);
|
142
|
+
parseddata["trace-data"] = traceData;
|
143
|
+
else
|
144
|
+
traceData = Array.new
|
145
|
+
traceData.push(trac)
|
146
|
+
parseddata["trace-data"] = traceData;
|
147
|
+
end
|
148
|
+
rescue Exception=>e
|
149
|
+
@obj.log.info "Exception in updateTraceData: #{e}"
|
150
|
+
@obj.log.logException "#{e.message}",e
|
151
|
+
end
|
152
|
+
parseddata
|
153
|
+
end
|
154
|
+
|
155
|
+
def getDummyTrace
|
156
|
+
top = Array.new
|
157
|
+
path = @obj.constants.mf_overflow
|
158
|
+
det = {"thread_name"=>"rorthread","s_time"=>0,"t_name"=>path,"r_time"=>0,"thread_id"=>141}
|
159
|
+
trData = Array.new
|
160
|
+
trData[0] = 0
|
161
|
+
trData[1] = path
|
162
|
+
trData[2] = ""
|
163
|
+
trData[3] = 0
|
164
|
+
trData[4] = 0
|
165
|
+
trData[5] = nil
|
166
|
+
trData[6] = Array.new
|
167
|
+
top[0] = det
|
168
|
+
top[1] = trData
|
169
|
+
return top
|
170
|
+
end
|
171
|
+
|
172
|
+
def getTransData(d,tdata)
|
173
|
+
pl = d["payload"]
|
174
|
+
ret = nil;
|
175
|
+
begin
|
176
|
+
if(tdata.has_key?("td"))
|
177
|
+
ret = tdata["td"]
|
178
|
+
ret["rt"] = ret["rt"] + (d["end"] - d["start"]).to_i
|
179
|
+
else
|
180
|
+
rt = (d["end"] - d["start"]).to_i
|
181
|
+
path=pl[:path]
|
182
|
+
#path=pl["path"]
|
183
|
+
controller=pl[:controller]
|
184
|
+
#controller=pl["controller"]
|
185
|
+
action = pl[:action]
|
186
|
+
#action = pl["action"]
|
187
|
+
ret ={"rt"=>rt,"path"=>path,"name"=>controller+"#"+action}
|
188
|
+
end
|
189
|
+
rescue Exception=>e
|
190
|
+
@obj.log.info "Exception in getTranseData: #{e}"
|
191
|
+
@obj.log.logException "#{e.message}",e
|
192
|
+
end
|
193
|
+
ret
|
194
|
+
end
|
195
|
+
|
196
|
+
|
197
|
+
def getDBData(d)
|
198
|
+
pl = d["payload"]
|
199
|
+
rt = (d["end"] - d["start"])
|
200
|
+
sql = pl[:sql]
|
201
|
+
#sql = pl["sql"]
|
202
|
+
sql.strip!
|
203
|
+
sql.downcase!
|
204
|
+
sqlArr = sql.split(" ")
|
205
|
+
sqlStrip="";
|
206
|
+
tr_name="";
|
207
|
+
begin
|
208
|
+
sqlStrip = getSqlStrip sqlArr,false
|
209
|
+
rescue Exception=>e
|
210
|
+
@obj.log.logException "#{e.message}",e
|
211
|
+
sqlStrip = sqlArr[0]+"/-/dummydb"
|
212
|
+
end
|
213
|
+
|
214
|
+
name=pl[:name]
|
215
|
+
#name=pl["name"]
|
216
|
+
ret ={"rt"=>rt,"sql"=>format(sql),"sql-strip"=>sqlStrip,"name"=>name,"operation"=>sqlArr[0]}
|
217
|
+
ret
|
218
|
+
end
|
219
|
+
|
220
|
+
def getSqlStrip sqlArr ,trace
|
221
|
+
sqlStrip =""
|
222
|
+
begin
|
223
|
+
sqlStrip = case sqlArr[0]
|
224
|
+
when "select" then sqlArr[sqlArr.index("from")+1]
|
225
|
+
when "insert" then sqlArr[sqlArr.index("into")+1]
|
226
|
+
when "update" then sqlArr[1]
|
227
|
+
when "delete" then sqlArr[sqlArr.index("from")+1]
|
228
|
+
when "create" then sqlArr[1] + sqlArr[2]
|
229
|
+
when "alter" then sqlArr[1] + sqlArr[2]
|
230
|
+
when "drop" then sqlArr[1] + sqlArr[2]
|
231
|
+
when "show" then sqlArr[1]
|
232
|
+
when "describe" then sqlArr[1]
|
233
|
+
else "-"
|
234
|
+
end
|
235
|
+
|
236
|
+
if trace
|
237
|
+
sqlStrip = format(sqlArr[0]) +" - " + format(sqlStrip)
|
238
|
+
else
|
239
|
+
sqlStrip = format(sqlArr[0]) +"/" + format(sqlStrip) +"/dummydb"
|
240
|
+
end
|
241
|
+
|
242
|
+
rescue Exception=>e
|
243
|
+
@obj.log.logException "#{e.message}",e
|
244
|
+
if trace
|
245
|
+
sqlStrip = format(sqlArr[0])
|
246
|
+
else
|
247
|
+
sqlStrip = sqlArr[0]+"/-/dummydb"
|
248
|
+
end
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
252
|
+
def updateDBTrace(d)
|
253
|
+
pl = d["payload"]
|
254
|
+
rt = (d["end"] - d["start"])
|
255
|
+
sql = pl[:sql]
|
256
|
+
#sql = pl["sql"]
|
257
|
+
sql.strip!
|
258
|
+
sql.downcase!
|
259
|
+
sql = format(sql)
|
260
|
+
sqlArr = sql.split(" ")
|
261
|
+
|
262
|
+
trData = Array.new
|
263
|
+
#trData[0] = (d["start"].to_f * 1000 ).to_i
|
264
|
+
trData[0] = d["ctime"]
|
265
|
+
trData[1] = getSqlStrip sqlArr,true
|
266
|
+
trData[2] = ""
|
267
|
+
trData[3] = rt.to_i
|
268
|
+
trData[4] = rt.to_i
|
269
|
+
trData[5] = {"query"=>sql}
|
270
|
+
trData[6] = Array.new
|
271
|
+
if(!@obj.config.sql_capture_params)
|
272
|
+
trData[5] = updateQueryParams(d,sql,pl[:binds],rt)
|
273
|
+
#trData[5] = updateQueryParams(d,sql,pl["binds"],rt)
|
274
|
+
else
|
275
|
+
sql = @obj.util.parametrizeQuery sql
|
276
|
+
trData[5] = {"query"=>sql}
|
277
|
+
end
|
278
|
+
|
279
|
+
|
280
|
+
|
281
|
+
trData
|
282
|
+
end
|
283
|
+
|
284
|
+
def updateQueryParams d,sql,binds,rt
|
285
|
+
ret = {"query"=>sql}
|
286
|
+
begin
|
287
|
+
args = "";
|
288
|
+
if binds!=nil && binds.size()>0
|
289
|
+
binds.each do |ar|
|
290
|
+
#args = args + ar.last + ","
|
291
|
+
if sql!=nil && sql.index("?")!=nil
|
292
|
+
sql["?"]=ar.last
|
293
|
+
end
|
294
|
+
end
|
295
|
+
end
|
296
|
+
if args.length>0
|
297
|
+
sql = sql + "\\nPARAMS - ["+args+ "]"
|
298
|
+
end
|
299
|
+
ret = {"query"=>sql}
|
300
|
+
rescue Exception=>exe
|
301
|
+
@obj.log.logException "Not severe -#{exe.message}",exe
|
302
|
+
ret = {"query"=>sql}
|
303
|
+
end
|
304
|
+
|
305
|
+
begin
|
306
|
+
if(rt.to_i > (@obj.config.sql_trace_t.to_f * "1000".to_f ).to_i && d.has_key?("trace") )
|
307
|
+
t = updateSQLStackTrace(d["trace"])
|
308
|
+
ret["stacktrace"] =t
|
309
|
+
end
|
310
|
+
rescue Exception=>e
|
311
|
+
@obj.log.logException "#{e.message}",e
|
312
|
+
end
|
313
|
+
|
314
|
+
ret
|
315
|
+
end
|
316
|
+
|
317
|
+
def updateSQLStackTrace(d)
|
318
|
+
trace = Array.new;
|
319
|
+
started = false;
|
320
|
+
ended = false;
|
321
|
+
begin
|
322
|
+
#@obj.log.debug "STACKTRACE STARTS"
|
323
|
+
d.each do |arr|
|
324
|
+
|
325
|
+
if started
|
326
|
+
|
327
|
+
end_ind = arr.index("`send_action'")
|
328
|
+
if end_ind != nil && end_ind >0
|
329
|
+
ended = true
|
330
|
+
break;
|
331
|
+
end
|
332
|
+
#trArr = arr.split(/:[0-1,in]/);
|
333
|
+
#if trArr[0].length>30
|
334
|
+
# len = trArr.length
|
335
|
+
# trArr[0] = "..."+trArr[(len-30),len]
|
336
|
+
# end
|
337
|
+
inx=arr.index("`instrument'")
|
338
|
+
if inx!=nil && inx>0
|
339
|
+
#skip instrumet data
|
340
|
+
else
|
341
|
+
temp = Array.new
|
342
|
+
temp[0]=arr
|
343
|
+
temp[1]=""
|
344
|
+
temp[2]=""
|
345
|
+
temp[3]=""
|
346
|
+
trace.push(temp)
|
347
|
+
end
|
348
|
+
end
|
349
|
+
|
350
|
+
if started==false
|
351
|
+
ind = arr.index("`instrument'")
|
352
|
+
if ind != nil && ind >0
|
353
|
+
started = true
|
354
|
+
end
|
355
|
+
end
|
356
|
+
|
357
|
+
|
358
|
+
end
|
359
|
+
#@obj.log.debug "STACKTRACE ENDS"
|
360
|
+
|
361
|
+
trace.shift
|
362
|
+
rescue Exception=>e
|
363
|
+
@obj.log.logException "#{e.message}",e
|
364
|
+
end
|
365
|
+
trace
|
366
|
+
end
|
367
|
+
|
368
|
+
def updateOtherTrace d
|
369
|
+
pl = d["payload"]
|
370
|
+
rt = (d["end"] - d["start"])
|
371
|
+
name = d["name"]
|
372
|
+
if pl.has_key?(:identifier)
|
373
|
+
#if pl.has_key?("identifier")
|
374
|
+
name = pl[:identifier]
|
375
|
+
#name = pl["identifier"]
|
376
|
+
end
|
377
|
+
trData = Array.new
|
378
|
+
#trData[0] = (d["start"].to_f * 1000 ).to_i
|
379
|
+
trData[0] = d["ctime"]
|
380
|
+
trData[1] = name
|
381
|
+
trData[2] = ""
|
382
|
+
trData[3] = rt.to_i
|
383
|
+
trData[4] = rt.to_i
|
384
|
+
trData[5] = nil
|
385
|
+
trData[6] = Array.new
|
386
|
+
trData
|
387
|
+
end
|
388
|
+
|
389
|
+
def updateTransTrace(d,trData)
|
390
|
+
|
391
|
+
#trData = Array.new
|
392
|
+
#trData[0] = ((d["start"]).to_f * 1000).to_i
|
393
|
+
pl = d["payload"]
|
394
|
+
trData[1] = pl[:path] + " " +pl[:controller] + "#" + pl[:action]
|
395
|
+
#trData[1] = pl["path"] + " " +pl["controller"] + "#" + pl["action"]
|
396
|
+
trData[2] = ""
|
397
|
+
trData[3] = (d["end"] - trData[0]).to_i
|
398
|
+
trData[4] = (d["end"] - trData[0]).to_i
|
399
|
+
trData[5] = nil
|
400
|
+
#trData[6] = Array.new
|
401
|
+
#dbTime = 0
|
402
|
+
#trdbdata.each do |dbData|
|
403
|
+
# dbTime = dbTime + dbData[3]
|
404
|
+
#end
|
405
|
+
#trData[4] = ((trData[3]).to_f - (dbTime.to_f )).to_i
|
406
|
+
# if(pl[:db_runtime]!=nil)
|
407
|
+
# trData[4] = ((trData[3]).to_f - (pl[:db_runtime].to_f )).to_i
|
408
|
+
# end
|
409
|
+
trData
|
410
|
+
end
|
411
|
+
|
412
|
+
def updateMethodTrace(d,trData)
|
413
|
+
|
414
|
+
#trData = Array.new
|
415
|
+
#trData[0] = ((d["start"]).to_f * 1000).to_i
|
416
|
+
pl = d["payload"]
|
417
|
+
trData[1] = pl[:method]
|
418
|
+
#trData[1] = pl["method"]
|
419
|
+
trData[2] = ""
|
420
|
+
trData[3] = (d["end"] - trData[0]).to_i
|
421
|
+
trData[4] = (d["end"] - trData[0]).to_i
|
422
|
+
trData[5] = nil
|
423
|
+
#trData[6] = Array.new
|
424
|
+
#dbTime = 0
|
425
|
+
#trdbdata.each do |dbData|
|
426
|
+
# dbTime = dbTime + dbData[3]
|
427
|
+
#end
|
428
|
+
#trData[4] = ((trData[3]).to_f - (dbTime.to_f )).to_i
|
429
|
+
# if(pl[:db_runtime]!=nil)
|
430
|
+
# trData[4] = ((trData[3]).to_f - (pl[:db_runtime].to_f )).to_i
|
431
|
+
# end
|
432
|
+
trData
|
433
|
+
end
|
434
|
+
|
435
|
+
def updateStartTrace(d)
|
436
|
+
trData = Array.new
|
437
|
+
#trData[0] = ((d["start"]).to_f * 1000).to_i
|
438
|
+
trData[0] = d["ctime"]
|
439
|
+
trData[1] =""
|
440
|
+
trData[2] =""
|
441
|
+
trData[3] =0
|
442
|
+
trData[4] =0
|
443
|
+
trData[5] =nil
|
444
|
+
trData[6] =Array.new
|
445
|
+
|
446
|
+
trData
|
447
|
+
end
|
448
|
+
|
449
|
+
def updateTrace(trans)
|
450
|
+
# {"thread_name":"http-8080-6","s_time":1326276180289,"t_name":"transaction\/http\/Test-App\/login","r_time":18,"thread_id":141}
|
451
|
+
top = Array.new
|
452
|
+
path = @obj.constants.mf_transaction + @obj.constants.mf_separator + trans[1]
|
453
|
+
det = {"thread_name"=>"rorthread","s_time"=>trans[0],"t_name"=>path,"r_time"=>trans[3],"thread_id"=>141}
|
454
|
+
#trans[6] = db;
|
455
|
+
top[0] = det
|
456
|
+
top[1] = trans
|
457
|
+
top
|
458
|
+
end
|
459
|
+
|
460
|
+
def format s
|
461
|
+
s.gsub!("\"", '')
|
462
|
+
s.gsub!("\n", '')
|
463
|
+
s
|
464
|
+
end
|
465
|
+
|
466
|
+
|
467
|
+
def getTrace data
|
468
|
+
index = 0
|
469
|
+
data.each do |arr|
|
470
|
+
|
471
|
+
if(arr["name"]=="start_processing.action_controller")
|
472
|
+
index = data.index(arr)
|
473
|
+
break;
|
474
|
+
end
|
475
|
+
end
|
476
|
+
data = data.drop(index)
|
477
|
+
tdata =traceDetails data,Array.new,0
|
478
|
+
tdata = updateExclusiveTrace(tdata[0])
|
479
|
+
tdata
|
480
|
+
end
|
481
|
+
|
482
|
+
def traceDetails valo,stack,indx
|
483
|
+
if(valo.size>indx)
|
484
|
+
arr = valo[indx]
|
485
|
+
indx = indx+1
|
486
|
+
if(arr["name"]=="start_processing.action_controller")
|
487
|
+
traceArr = updateStartTrace arr
|
488
|
+
traceArr[6] = Array.new #childs
|
489
|
+
if stack.size()>0
|
490
|
+
cur = stack[stack.size()-1]
|
491
|
+
c = cur[6]
|
492
|
+
c.push(traceArr)
|
493
|
+
cur[6] = c
|
494
|
+
end
|
495
|
+
stack.push(traceArr)
|
496
|
+
|
497
|
+
|
498
|
+
traceDetails valo,stack,indx
|
499
|
+
|
500
|
+
elsif(arr["name"]=="sql.active_record" && @obj.config.sql_capture )
|
501
|
+
|
502
|
+
temp = updateDBTrace arr
|
503
|
+
|
504
|
+
cur = stack[stack.size()-1]
|
505
|
+
c = cur[6]
|
506
|
+
c.push(temp)
|
507
|
+
cur[6] = c
|
508
|
+
traceDetails valo,stack,indx
|
509
|
+
elsif(arr["name"]=="apm.methodstart")
|
510
|
+
temp = updateStartTrace arr
|
511
|
+
cur = stack[stack.size()-1]
|
512
|
+
c = cur[6]
|
513
|
+
c.push(temp)
|
514
|
+
cur[6] = c
|
515
|
+
stack.push(temp)
|
516
|
+
traceDetails valo,stack,indx
|
517
|
+
elsif(arr["name"]=="apm.methodend")
|
518
|
+
updateMethodTrace(arr,stack[stack.size()-1])
|
519
|
+
stack.delete(stack[stack.size()-1])
|
520
|
+
traceDetails valo,stack,indx
|
521
|
+
elsif(arr["name"]=="process_action.action_controller")
|
522
|
+
updateTransTrace(arr,stack[stack.size()-1])
|
523
|
+
if(valo.size()>(indx+1))
|
524
|
+
#Redirection Data
|
525
|
+
arr = valo[indx]
|
526
|
+
while (arr["name"]!="start_processing.action_controller") do
|
527
|
+
indx = indx + 1
|
528
|
+
arr = valo[indx]
|
529
|
+
end
|
530
|
+
end
|
531
|
+
(stack[0])[3] = (arr["end"] - ((stack[0])[0])).to_i
|
532
|
+
(stack[0])[4] = (arr["end"] - ((stack[0])[0])).to_i
|
533
|
+
|
534
|
+
|
535
|
+
traceDetails valo,stack,indx
|
536
|
+
#parent[4] = parent[4] - traceArr[4]
|
537
|
+
elsif (arr["name"]=="render_template.action_view")
|
538
|
+
temp = updateOtherTrace arr
|
539
|
+
|
540
|
+
cur = stack[stack.size()-1]
|
541
|
+
c = cur[6]
|
542
|
+
c.push(temp)
|
543
|
+
cur[6] = c
|
544
|
+
#traceArr[6] = c
|
545
|
+
#parent[4] = parent[4] - temp[4]
|
546
|
+
traceDetails valo,stack,indx
|
547
|
+
else
|
548
|
+
traceDetails valo,stack,indx
|
549
|
+
|
550
|
+
end
|
551
|
+
|
552
|
+
stack
|
553
|
+
else
|
554
|
+
#Nothing todo
|
555
|
+
end
|
556
|
+
end
|
557
|
+
|
558
|
+
|
559
|
+
def updateExclusiveTrace data
|
560
|
+
childs = data[6]
|
561
|
+
childs.each do |arr|
|
562
|
+
data[4] = data[4] - (updateExclusiveTrace arr)[3]
|
563
|
+
end
|
564
|
+
data
|
565
|
+
end
|
566
|
+
|
567
|
+
|
568
|
+
end
|
569
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'agent/am_objectholder'
|
2
|
+
|
3
|
+
module ManageEngine
|
4
|
+
class APMMetricsStore
|
5
|
+
attr_accessor :metrics
|
6
|
+
def initialize
|
7
|
+
@metrics = Hash.new
|
8
|
+
end
|
9
|
+
|
10
|
+
def remove keys
|
11
|
+
if keys!=nil
|
12
|
+
keys.each {|key| @metrics.delete("#{key}")}
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def metrics_dup
|
17
|
+
@metrics.dup
|
18
|
+
end
|
19
|
+
|
20
|
+
def removeData key, strt_indx,end_indx
|
21
|
+
if @metrics.has_key?(key)
|
22
|
+
val = @metrics[key]
|
23
|
+
val = val.drop(end_indx)
|
24
|
+
@metrics[key]=val
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
require "agent/am_objectholder"
|
2
|
+
require "agent/server/worker/am_worker"
|
3
|
+
|
4
|
+
require 'socket'
|
5
|
+
|
6
|
+
module ManageEngine
|
7
|
+
class APMAgent
|
8
|
+
def initialize
|
9
|
+
@obj = ManageEngine::APMObjectHolder.instance
|
10
|
+
@obj.log.debug "Agent Initialization - START"
|
11
|
+
doConnect
|
12
|
+
|
13
|
+
if !@obj.shutdown && @obj.agent_initialized
|
14
|
+
@obj.log.info "Agent Initialization - DONE"
|
15
|
+
@obj.instrumenter.doSubscribe
|
16
|
+
doDispatcherActions
|
17
|
+
doCollect
|
18
|
+
puts "APM Insight Ruby Agent Started"
|
19
|
+
else
|
20
|
+
@obj.log.info "Agent Initialization Failed - Going to shutdown"
|
21
|
+
@obj.instrumenter.doSubscribe
|
22
|
+
@obj.shutdownagent
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
def doConnect
|
29
|
+
begin
|
30
|
+
if @obj.shutdown
|
31
|
+
@obj.log.info "[ Problem in Agent Startup ]"
|
32
|
+
else
|
33
|
+
agentInfo = @obj.config.getAgentInfo
|
34
|
+
resp = nil
|
35
|
+
if @obj.config.alreadyconnected
|
36
|
+
@obj.log.debug "[doConnect] Already Connected - Make Contact - Instance id = #{@obj.config.instance_id}"
|
37
|
+
if @obj.config.site24x7
|
38
|
+
resp = startConnect "?license.key="+@obj.config.license_key+"&instance_id="+@obj.config.instance_id,agentInfo
|
39
|
+
else
|
40
|
+
resp = startConnect "?instance_id="+@obj.config.instance_id,agentInfo
|
41
|
+
end
|
42
|
+
else
|
43
|
+
@obj.log.debug "[doConnect] Going to connect - New "
|
44
|
+
if @obj.config.site24x7
|
45
|
+
resp = startConnect "?license.key="+@obj.config.license_key,agentInfo
|
46
|
+
else
|
47
|
+
resp = startConnect "",agentInfo
|
48
|
+
end
|
49
|
+
if resp.has_key?("instance-info")
|
50
|
+
aData = resp["instance-info"]
|
51
|
+
aData["agent.id"]=aData.delete("instanceid")
|
52
|
+
aData["agent.enabled"]=true
|
53
|
+
@obj.config.updateAgentInfoFile(aData)
|
54
|
+
@obj.log.debug "[doConnect] Connected - InstanceID : #{@obj.config.instance_id}"
|
55
|
+
else
|
56
|
+
@obj.log.info "[doConnect] [ Problem in connecting server] [ Going to shutdown ]"
|
57
|
+
@obj.shutdown=true
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
if resp==nil
|
62
|
+
@obj.log.info "[doConnect] [ Error in Response while connecting Server . [ Going to shutdown ]"
|
63
|
+
@obj.shutdown= true
|
64
|
+
end
|
65
|
+
|
66
|
+
if(!@obj.shutdown)
|
67
|
+
@obj.agent_initialized=true
|
68
|
+
end
|
69
|
+
end
|
70
|
+
rescue Exception=>e
|
71
|
+
@obj.shutdown = true
|
72
|
+
@obj.log.logException "[doConnect] Exception while connecting server. [ Going to shutdown ] ",e
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
|
77
|
+
def doCollect
|
78
|
+
@obj.log.info "[doCollect] Starts - Wait time : #{@obj.config.connect_interval} seconds "
|
79
|
+
begin
|
80
|
+
ManageEngine::APMWorker.getInstance.start
|
81
|
+
rescue Exception=>e
|
82
|
+
@obj.log.logException "[doCollect] Exception during worker startup #{e.message}",e
|
83
|
+
@obj.shutdown=true
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
|
88
|
+
def startConnect uri,data
|
89
|
+
resp = @obj.connector.post @obj.constants.connect_uri+uri,data
|
90
|
+
end
|
91
|
+
|
92
|
+
def doDispatcherActions
|
93
|
+
case @obj.config.app_dispatcher
|
94
|
+
when 'passenger'
|
95
|
+
#starting a new process
|
96
|
+
PhusionPassenger.on_event(:starting_worker_process) do |forked|
|
97
|
+
if forked
|
98
|
+
@obj.log.info "starting_worker_process : Process ID :#{Process.pid} : Creating new apm worker"
|
99
|
+
doCollect
|
100
|
+
else
|
101
|
+
doCollect
|
102
|
+
@obj.log.info "starting_worker_process : Conservative Process ID :#{Process.pid} - No new worker"
|
103
|
+
end
|
104
|
+
end
|
105
|
+
# shutting down a process.
|
106
|
+
PhusionPassenger.on_event(:stopping_worker_process) do
|
107
|
+
ManageEngine::APMWorker.getInstance.stop
|
108
|
+
@obj.log.info "stopping_worker_process :Process ID :#{Process.pid} ----> #$$ "
|
109
|
+
end
|
110
|
+
else#case
|
111
|
+
|
112
|
+
end#case
|
113
|
+
end
|
114
|
+
end#c
|
115
|
+
end#m
|
116
|
+
|