apminsight 0.0.3
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 +69 -0
- data/Rakefile +63 -0
- data/VERSION +1 -0
- data/conf/apminsight.conf +105 -0
- data/lib/agent/am_objectholder.rb +66 -0
- data/lib/agent/configuration/am_configuration.rb +190 -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 +263 -0
- data/lib/agent/metrics/am_metricsparser.rb +540 -0
- data/lib/agent/metrics/am_metricstore.rb +29 -0
- data/lib/agent/server/am_agent.rb +108 -0
- data/lib/agent/server/am_connector.rb +195 -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 +254 -0
- data/lib/agent/util/am_constants.rb +64 -0
- data/lib/agent/util/am_util.rb +130 -0
- data/lib/apminsight.rb +5 -0
- metadata +134 -0
@@ -0,0 +1,109 @@
|
|
1
|
+
|
2
|
+
require "logger"
|
3
|
+
|
4
|
+
module ManageEngine
|
5
|
+
class APMLogger
|
6
|
+
@apmlog=nil;
|
7
|
+
def initialize
|
8
|
+
@obj=ManageEngine::APMObjectHolder.instance
|
9
|
+
path = getLogsPath
|
10
|
+
#puts "#{path}"
|
11
|
+
if Dir[path] == []
|
12
|
+
Dir.mkdir(path)
|
13
|
+
end
|
14
|
+
path= path + '/apm.log'
|
15
|
+
#puts "#{path}"
|
16
|
+
# file = open(path, File::WRONLY | File::APPEND | File::CREAT)
|
17
|
+
@apmlog = Logger.new(path, 10, 100 * 1024 * 1024)
|
18
|
+
# @apmlog = Logger.new(file)
|
19
|
+
@apmlog.level = Logger::INFO
|
20
|
+
@apmlog.datetime_format = "%Y-%m-%d %H:%M:%S"
|
21
|
+
@apmlog.formatter = proc do |severity, datetime, progname, msg|
|
22
|
+
"[#{datetime}|#{Process.pid}]:#{msg}\n"
|
23
|
+
end
|
24
|
+
@apmlog.debug("[LOGGER] APM Agent Logging Initialized")
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
def getLogsPath
|
30
|
+
props = {}
|
31
|
+
begin
|
32
|
+
if FileTest.exists?(@obj.constants.apm_conf)
|
33
|
+
propsFile=File.open(@obj.constants.apm_conf, 'r')
|
34
|
+
propsFile.read.each_line do |line|
|
35
|
+
line.strip!
|
36
|
+
if (line[0] != ?# and line[0] != ?=)
|
37
|
+
i = line.index('=')
|
38
|
+
if (i)
|
39
|
+
props[line[0..i - 1].strip] = line[i + 1..-1].strip
|
40
|
+
else
|
41
|
+
props[line] = ''
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
else
|
46
|
+
puts "ManageEngine Ruby Agent Configuration File Not exist in #{@obj.constants.apm_conf}.\n Duplicate file will be available in <Gems Folder>/apm-agent/lib/config "
|
47
|
+
end
|
48
|
+
rescue Exception=>e
|
49
|
+
puts "Problem in Reading Property File : \n #{e.message} \n #{e.backtrace}"
|
50
|
+
ensure
|
51
|
+
#
|
52
|
+
end
|
53
|
+
if props["apminsight.log.dir"]!=nil
|
54
|
+
return props["apminsight.log.dir"]
|
55
|
+
else
|
56
|
+
return "./log"
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
def setLevel level
|
62
|
+
level = level.upcase
|
63
|
+
case level.upcase
|
64
|
+
when "INFO" then @apmlog.level = Logger::INFO
|
65
|
+
when "DEBUG" then @apmlog.level = Logger::DEBUG
|
66
|
+
when "WARN" then @apmlog.level = Logger::WARN
|
67
|
+
when "ERROR" then @apmlog.level = Logger::ERROR
|
68
|
+
when "FATAL" then @apmlog.level = Logger::FATAL
|
69
|
+
when "FINE" then @apmlog.level = Logger::DEBUG
|
70
|
+
when "SEVERE" then @apmlog.level = Logger::ERROR
|
71
|
+
when "WARNING" then @apmlog.level = Logger::WARN
|
72
|
+
else
|
73
|
+
@apmlog.level = Logger::DEBUG
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def info(msg)
|
78
|
+
@apmlog.info(msg)
|
79
|
+
end
|
80
|
+
|
81
|
+
def debug(msg)
|
82
|
+
@apmlog.debug(msg)
|
83
|
+
end
|
84
|
+
|
85
|
+
def warn(msg)
|
86
|
+
@apmlog.warn(msg)
|
87
|
+
end
|
88
|
+
|
89
|
+
def error(msg)
|
90
|
+
@apmlog.error(msg)
|
91
|
+
end
|
92
|
+
|
93
|
+
def fatal(msg)
|
94
|
+
@apmlog.fatal(msg)
|
95
|
+
end
|
96
|
+
|
97
|
+
|
98
|
+
def logException(msg,e)
|
99
|
+
@apmlog.info( "#{msg} => #{e.message}")
|
100
|
+
@apmlog.debug( "!!!!!!!!!!!!!!!!!!!!!!EXCEPTION !!!!!!!!!!!!!!!!!!!!!!!!!!!!")
|
101
|
+
@apmlog.debug( "Message : #{msg}\nTrace :\n#{e.backtrace}")
|
102
|
+
@apmlog.debug( "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
|
103
|
+
end
|
104
|
+
|
105
|
+
def close
|
106
|
+
@apmlog.close
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'agent/am_objectholder'
|
2
|
+
|
3
|
+
|
4
|
+
module ManageEngine
|
5
|
+
class APMMetricsCollector
|
6
|
+
def initialize
|
7
|
+
@obj = ManageEngine::APMObjectHolder.instance
|
8
|
+
end
|
9
|
+
|
10
|
+
def getTransactions
|
11
|
+
@obj.store.metrics_dup
|
12
|
+
end
|
13
|
+
|
14
|
+
def updateTransaction( id ,values)
|
15
|
+
if(@obj.store.metrics.has_key?(id))
|
16
|
+
temp = @obj.store.metrics[id]
|
17
|
+
temp.push(values);
|
18
|
+
else
|
19
|
+
temp = Array.new
|
20
|
+
temp.push(values);
|
21
|
+
@obj.store.metrics[id]=temp
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def transactionmetricskeys
|
26
|
+
@obj.store.keys
|
27
|
+
end
|
28
|
+
|
29
|
+
end#class
|
30
|
+
end#module
|
@@ -0,0 +1,263 @@
|
|
1
|
+
require 'agent/am_objectholder'
|
2
|
+
module ManageEngine
|
3
|
+
class APMMetricsFormatter
|
4
|
+
|
5
|
+
def intialize
|
6
|
+
@obj = ManageEngine::APMObjectHolder.instance
|
7
|
+
@apdex_threshold = 0
|
8
|
+
end
|
9
|
+
#trans Vs #[0-rspTime,1-min rt,2-max rt,3-cnt,4-apdx,5-stat,6-toler,7-frustating]
|
10
|
+
#DBtrans Vs #[rspTime,min rt,max rt,cnt]
|
11
|
+
#trace
|
12
|
+
|
13
|
+
def format d
|
14
|
+
result = Array.new
|
15
|
+
@obj = ManageEngine::APMObjectHolder.instance
|
16
|
+
begin
|
17
|
+
@apdex_threshold = @obj.config.apdex_t * 1000
|
18
|
+
#@obj.log.info "[FORMAT]"
|
19
|
+
@transaction = Hash.new
|
20
|
+
@db = Hash.new
|
21
|
+
@instance = Hash.new
|
22
|
+
@dbinstance = Hash.new
|
23
|
+
@dboperations = Hash.new
|
24
|
+
@keystoremove = Array.new
|
25
|
+
d.each do |key,value|
|
26
|
+
@keystoremove.push(key)
|
27
|
+
updatetransaction value
|
28
|
+
end
|
29
|
+
updateinstance
|
30
|
+
updatedbinstance
|
31
|
+
|
32
|
+
@transaction.each do |key,value|
|
33
|
+
res = Hash.new
|
34
|
+
res[@obj.constants.mf_namespace] = key
|
35
|
+
res[@obj.constants.mf_name] = @obj.constants.mf_apdex
|
36
|
+
valArr= Array.new
|
37
|
+
valArr[0] =res
|
38
|
+
valArr[1] =value
|
39
|
+
result.push(valArr)
|
40
|
+
end
|
41
|
+
|
42
|
+
@db.each do |key,value|
|
43
|
+
#puts "#{key} == #{value}"
|
44
|
+
res = Hash.new
|
45
|
+
res[@obj.constants.mf_namespace] = value["tpath"]
|
46
|
+
res[@obj.constants.mf_name] = value["path"]
|
47
|
+
valArr= Array.new
|
48
|
+
valArr[0] =res
|
49
|
+
valArr[1] =value["metrics"]
|
50
|
+
result.push(valArr)
|
51
|
+
end
|
52
|
+
@instance.each do |key,value|
|
53
|
+
res = Hash.new
|
54
|
+
res[@obj.constants.mf_namespace] = ""
|
55
|
+
res[@obj.constants.mf_name] = @obj.constants.mf_apdex
|
56
|
+
valArr= Array.new
|
57
|
+
valArr[0] =res
|
58
|
+
valArr[1] =value
|
59
|
+
result.push(valArr)
|
60
|
+
end
|
61
|
+
@dbinstance.each do |key,value|
|
62
|
+
res = Hash.new
|
63
|
+
res[@obj.constants.mf_namespace] = ""
|
64
|
+
res[@obj.constants.mf_name] = @obj.constants.mf_db + @obj.constants.mf_separator + @obj.constants.mf_all + @obj.constants.mf_separator + @obj.constants.mf_all + @obj.constants.mf_separator + @obj.config.app_db # "db/all/all/dummydb"
|
65
|
+
valArr= Array.new
|
66
|
+
valArr[0] =res
|
67
|
+
valArr[1] =value
|
68
|
+
result.push(valArr)
|
69
|
+
end
|
70
|
+
@dboperations.each do |key,value|
|
71
|
+
ind = @obj.config.db_operations.index(key)
|
72
|
+
if (ind!=nil)
|
73
|
+
res = Hash.new
|
74
|
+
res[@obj.constants.mf_namespace] = ""
|
75
|
+
res[@obj.constants.mf_name] = @obj.constants.mf_db + @obj.constants.mf_separator + "#{key}" + @obj.constants.mf_separator + @obj.constants.mf_all + @obj.constants.mf_separator + @obj.config.app_db # "db/"+key+"/all/dummydb"
|
76
|
+
valArr= Array.new
|
77
|
+
valArr[0] =res
|
78
|
+
valArr[1] =value
|
79
|
+
result.push(valArr)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
#@obj.log.info "[FORMAT] COMPLETED"
|
84
|
+
rescue Exception=>e
|
85
|
+
@obj.log.logException "[FORMAT]#{e.message}",e
|
86
|
+
end
|
87
|
+
@transaction.clear
|
88
|
+
@db.clear
|
89
|
+
@instance.clear
|
90
|
+
result
|
91
|
+
end
|
92
|
+
|
93
|
+
def keysToRemove
|
94
|
+
@keystoremove
|
95
|
+
end
|
96
|
+
|
97
|
+
def updateinstance
|
98
|
+
ins_apdx = Array.new
|
99
|
+
cnt = 0;
|
100
|
+
rt = 0;
|
101
|
+
s=0;
|
102
|
+
t=0;
|
103
|
+
f=0;
|
104
|
+
min = -1;
|
105
|
+
max = 0;
|
106
|
+
@transaction.each do |key,value|
|
107
|
+
rt = rt + value[0]
|
108
|
+
if min == -1
|
109
|
+
min = value[1]
|
110
|
+
max = value[2]
|
111
|
+
end
|
112
|
+
if(value[1]<min)
|
113
|
+
min = value[1]
|
114
|
+
end
|
115
|
+
if (value[2]>max)
|
116
|
+
max = value[2]
|
117
|
+
end
|
118
|
+
cnt = cnt + value[3]
|
119
|
+
|
120
|
+
s = s + value[5]
|
121
|
+
t = t + value[6]
|
122
|
+
f = f + value[7]
|
123
|
+
end
|
124
|
+
apx = (s.to_f + (t/2).to_f).to_f/cnt.to_f
|
125
|
+
@instance[":apdex"]=[rt.round(2),min,max,cnt,apx,s,t,f]
|
126
|
+
end
|
127
|
+
|
128
|
+
def updatedbinstance
|
129
|
+
cnt = 0;
|
130
|
+
rt = 0;
|
131
|
+
min = -1;
|
132
|
+
max = 0;
|
133
|
+
if(@db.length>0)
|
134
|
+
@db.each do |key,val|
|
135
|
+
value = val["metrics"]
|
136
|
+
rt = rt + value[0]
|
137
|
+
if min == -1
|
138
|
+
min = value[1]
|
139
|
+
max = value[2]
|
140
|
+
end
|
141
|
+
if(value[1]<min)
|
142
|
+
min = value[1]
|
143
|
+
end
|
144
|
+
if (value[2]>max)
|
145
|
+
max = value[2]
|
146
|
+
end
|
147
|
+
cnt = cnt + value[3]
|
148
|
+
end
|
149
|
+
@dbinstance[":apdex"]=[rt.round(2),min,max,cnt]
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
def updatetransaction d
|
154
|
+
begin
|
155
|
+
pl = d["td"]
|
156
|
+
dbl = d["db"]
|
157
|
+
|
158
|
+
rt = pl["rt"].round(2)
|
159
|
+
path = pl["path"]
|
160
|
+
name = pl["name"]
|
161
|
+
|
162
|
+
path = @obj.constants.mf_transaction + @obj.constants.mf_separator + path + " " +name
|
163
|
+
|
164
|
+
|
165
|
+
apx_stat = nil
|
166
|
+
if(@transaction.has_key?(path))
|
167
|
+
apx_stat = @transaction[path]
|
168
|
+
else
|
169
|
+
apx_stat = Array.new
|
170
|
+
apx_stat = [0,rt,rt,0,0,0,0,0]
|
171
|
+
end
|
172
|
+
apx_stat = apxarray apx_stat,rt
|
173
|
+
@transaction[path] = apx_stat
|
174
|
+
if(dbl!=nil)
|
175
|
+
updatedb dbl,path
|
176
|
+
end
|
177
|
+
rescue Exception=>e
|
178
|
+
@obj.log.info "#{e.message}"
|
179
|
+
@obj.log.logException "[Format] [ updatetransaction ] #{e.message}",e
|
180
|
+
end
|
181
|
+
# Apmagent::ApmLogger.instance.info "update transaction end"
|
182
|
+
end
|
183
|
+
|
184
|
+
def apxarray apx_stat,rt
|
185
|
+
|
186
|
+
# Apmagent::ApmLogger.instance.info "apxarray : start #{apx_stat}"
|
187
|
+
apx_stat = updatert apx_stat,rt
|
188
|
+
if rt <= @apdex_threshold
|
189
|
+
apx_stat[5] = apx_stat[5] + 1
|
190
|
+
elsif rt > (4 * @apdex_threshold)
|
191
|
+
apx_stat[7] = apx_stat[7] + 1
|
192
|
+
else
|
193
|
+
apx_stat[6] = apx_stat[6] + 1
|
194
|
+
end
|
195
|
+
|
196
|
+
apx_stat[4] = (apx_stat[5].to_f + (apx_stat[6].to_f/2).to_f)/apx_stat[3].to_f
|
197
|
+
# Apmagent::ApmLogger.instance.info "apxarray : end #{apx_stat}"
|
198
|
+
apx_stat
|
199
|
+
end
|
200
|
+
|
201
|
+
def updatert apx_stat,rt
|
202
|
+
# Apmagent::ApmLogger.instance.info "updatert : start"
|
203
|
+
apx_stat[3] = apx_stat[3] +1
|
204
|
+
apx_stat[0] = apx_stat[0] + rt
|
205
|
+
if(rt < apx_stat[1])
|
206
|
+
apx_stat[1] = rt
|
207
|
+
end
|
208
|
+
if(rt > apx_stat[2])
|
209
|
+
apx_stat[2] = rt
|
210
|
+
end
|
211
|
+
#Apmagent::ApmLogger.instance.info "updatert : end"
|
212
|
+
apx_stat
|
213
|
+
end
|
214
|
+
#DBtrans Vs #[rspTime,min rt,max rt,cnt]
|
215
|
+
def updatedb dpl,tpath
|
216
|
+
# Apmagent::ApmLogger.instance.info "updatedb : start"
|
217
|
+
dpl.each do |pl|
|
218
|
+
rt = pl["rt"].round(2)
|
219
|
+
path = pl["sql-strip"]
|
220
|
+
dpath = @obj.constants.mf_db + @obj.constants.mf_separator + path
|
221
|
+
path = tpath + @obj.constants.mf_separator + dpath
|
222
|
+
sql = pl["sql"]
|
223
|
+
stat = nil
|
224
|
+
val = nil
|
225
|
+
if(@db.has_key?(path))
|
226
|
+
val = @db[path]
|
227
|
+
stat = val["metrics"]
|
228
|
+
else
|
229
|
+
val=Hash.new
|
230
|
+
stat = Array.new
|
231
|
+
stat = [rt,rt,rt,0]
|
232
|
+
end
|
233
|
+
stat = updatert stat,rt
|
234
|
+
val["tpath"] = tpath
|
235
|
+
val["path"] = dpath
|
236
|
+
val["metrics"] = stat
|
237
|
+
@db[path] = val
|
238
|
+
updatedboperations rt, pl["operation"]
|
239
|
+
end
|
240
|
+
#Apmagent::ApmLogger.instance.info "updatedb : end"
|
241
|
+
end
|
242
|
+
|
243
|
+
def updatedboperations rt,operation
|
244
|
+
opstats = Array.new;
|
245
|
+
#puts "#{operation} "
|
246
|
+
if(@dboperations.has_key?(operation))
|
247
|
+
opstats = @dboperations[operation]
|
248
|
+
else
|
249
|
+
opstats = [0.0,rt,rt,0]
|
250
|
+
end
|
251
|
+
opstats[0] = opstats[0] + rt
|
252
|
+
if(rt<opstats[1])
|
253
|
+
opstats[1] = rt
|
254
|
+
end
|
255
|
+
if (rt>opstats[2])
|
256
|
+
opstats[2] = rt
|
257
|
+
end
|
258
|
+
opstats[3] = opstats[3] +1
|
259
|
+
@dboperations[operation]=opstats
|
260
|
+
end
|
261
|
+
|
262
|
+
end
|
263
|
+
end
|
@@ -0,0 +1,540 @@
|
|
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
|
+
begin
|
124
|
+
trdata = getTrace val
|
125
|
+
trac = updateTrace(trdata)
|
126
|
+
if(parseddata.has_key?("trace-data"))
|
127
|
+
traceData = parseddata["trace-data"];
|
128
|
+
traceData.push(trac);
|
129
|
+
parseddata["trace-data"] = traceData;
|
130
|
+
else
|
131
|
+
traceData = Array.new
|
132
|
+
traceData.push(trac)
|
133
|
+
parseddata["trace-data"] = traceData;
|
134
|
+
end
|
135
|
+
rescue Exception=>e
|
136
|
+
@obj.log.info "Exception in updateTraceData: #{e}"
|
137
|
+
@obj.log.logException "#{e.message}",e
|
138
|
+
end
|
139
|
+
parseddata
|
140
|
+
end
|
141
|
+
|
142
|
+
def getTransData(d,tdata)
|
143
|
+
pl = d["payload"]
|
144
|
+
ret = nil;
|
145
|
+
begin
|
146
|
+
if(tdata.has_key?("td"))
|
147
|
+
ret = tdata["td"]
|
148
|
+
ret["rt"] = ret["rt"] + (d["end"] - d["start"]).to_i
|
149
|
+
else
|
150
|
+
rt = (d["end"] - d["start"]).to_i
|
151
|
+
path=pl[:path]
|
152
|
+
#path=pl["path"]
|
153
|
+
controller=pl[:controller]
|
154
|
+
#controller=pl["controller"]
|
155
|
+
action = pl[:action]
|
156
|
+
#action = pl["action"]
|
157
|
+
ret ={"rt"=>rt,"path"=>path,"name"=>controller+"#"+action}
|
158
|
+
end
|
159
|
+
rescue Exception=>e
|
160
|
+
@obj.log.info "Exception in getTranseData: #{e}"
|
161
|
+
@obj.log.logException "#{e.message}",e
|
162
|
+
end
|
163
|
+
ret
|
164
|
+
end
|
165
|
+
|
166
|
+
|
167
|
+
def getDBData(d)
|
168
|
+
pl = d["payload"]
|
169
|
+
rt = (d["end"] - d["start"])
|
170
|
+
sql = pl[:sql]
|
171
|
+
#sql = pl["sql"]
|
172
|
+
sql.strip!
|
173
|
+
sql.downcase!
|
174
|
+
sqlArr = sql.split(" ")
|
175
|
+
sqlStrip="";
|
176
|
+
tr_name="";
|
177
|
+
begin
|
178
|
+
sqlStrip = getSqlStrip sqlArr,false
|
179
|
+
rescue Exception=>e
|
180
|
+
@obj.log.logException "#{e.message}",e
|
181
|
+
sqlStrip = sqlArr[0]+"/-/dummydb"
|
182
|
+
end
|
183
|
+
|
184
|
+
name=pl[:name]
|
185
|
+
#name=pl["name"]
|
186
|
+
ret ={"rt"=>rt,"sql"=>format(sql),"sql-strip"=>sqlStrip,"name"=>name,"operation"=>sqlArr[0]}
|
187
|
+
ret
|
188
|
+
end
|
189
|
+
|
190
|
+
def getSqlStrip sqlArr ,trace
|
191
|
+
sqlStrip =""
|
192
|
+
begin
|
193
|
+
sqlStrip = case sqlArr[0]
|
194
|
+
when "select" then sqlArr[sqlArr.index("from")+1]
|
195
|
+
when "insert" then sqlArr[sqlArr.index("into")+1]
|
196
|
+
when "update" then sqlArr[1]
|
197
|
+
when "delete" then sqlArr[sqlArr.index("from")+1]
|
198
|
+
when "create" then sqlArr[1] + sqlArr[2]
|
199
|
+
when "alter" then sqlArr[1] + sqlArr[2]
|
200
|
+
when "drop" then sqlArr[1] + sqlArr[2]
|
201
|
+
when "show" then sqlArr[1]
|
202
|
+
when "describe" then sqlArr[1]
|
203
|
+
else "-"
|
204
|
+
end
|
205
|
+
|
206
|
+
if trace
|
207
|
+
sqlStrip = format(sqlArr[0]) +" - " + format(sqlStrip)
|
208
|
+
else
|
209
|
+
sqlStrip = format(sqlArr[0]) +"/" + format(sqlStrip) +"/dummydb"
|
210
|
+
end
|
211
|
+
|
212
|
+
rescue Exception=>e
|
213
|
+
@obj.log.logException "#{e.message}",e
|
214
|
+
if trace
|
215
|
+
sqlStrip = format(sqlArr[0])
|
216
|
+
else
|
217
|
+
sqlStrip = sqlArr[0]+"/-/dummydb"
|
218
|
+
end
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
def updateDBTrace(d)
|
223
|
+
pl = d["payload"]
|
224
|
+
rt = (d["end"] - d["start"])
|
225
|
+
sql = pl[:sql]
|
226
|
+
#sql = pl["sql"]
|
227
|
+
sql.strip!
|
228
|
+
sql.downcase!
|
229
|
+
sql = format(sql)
|
230
|
+
sqlArr = sql.split(" ")
|
231
|
+
|
232
|
+
trData = Array.new
|
233
|
+
#trData[0] = (d["start"].to_f * 1000 ).to_i
|
234
|
+
trData[0] = d["ctime"]
|
235
|
+
trData[1] = getSqlStrip sqlArr,true
|
236
|
+
trData[2] = ""
|
237
|
+
trData[3] = rt.to_i
|
238
|
+
trData[4] = rt.to_i
|
239
|
+
trData[5] = {"query"=>sql}
|
240
|
+
trData[6] = Array.new
|
241
|
+
if(!@obj.config.sql_capture_params)
|
242
|
+
trData[5] = updateQueryParams(d,sql,pl[:binds],rt)
|
243
|
+
#trData[5] = updateQueryParams(d,sql,pl["binds"],rt)
|
244
|
+
else
|
245
|
+
sql = @obj.util.parametrizeQuery sql
|
246
|
+
trData[5] = {"query"=>sql}
|
247
|
+
end
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
trData
|
252
|
+
end
|
253
|
+
|
254
|
+
def updateQueryParams d,sql,binds,rt
|
255
|
+
ret = {"query"=>sql}
|
256
|
+
begin
|
257
|
+
args = "";
|
258
|
+
if binds!=nil && binds.size()>0
|
259
|
+
binds.each do |ar|
|
260
|
+
#args = args + ar.last + ","
|
261
|
+
if sql!=nil && sql.index("?")!=nil
|
262
|
+
sql["?"]=ar.last
|
263
|
+
end
|
264
|
+
end
|
265
|
+
end
|
266
|
+
if args.length>0
|
267
|
+
sql = sql + "\\nPARAMS - ["+args+ "]"
|
268
|
+
end
|
269
|
+
ret = {"query"=>sql}
|
270
|
+
rescue Exception=>exe
|
271
|
+
@obj.log.logException "Not severe -#{exe.message}",exe
|
272
|
+
ret = {"query"=>sql}
|
273
|
+
end
|
274
|
+
|
275
|
+
begin
|
276
|
+
if(rt.to_i > (@obj.config.sql_trace_t.to_f * "1000".to_f ).to_i && d.has_key?("trace") )
|
277
|
+
t = updateSQLStackTrace(d["trace"])
|
278
|
+
ret["stacktrace"] =t
|
279
|
+
end
|
280
|
+
rescue Exception=>e
|
281
|
+
@obj.log.logException "#{e.message}",e
|
282
|
+
end
|
283
|
+
|
284
|
+
ret
|
285
|
+
end
|
286
|
+
|
287
|
+
def updateSQLStackTrace(d)
|
288
|
+
trace = Array.new;
|
289
|
+
started = false;
|
290
|
+
ended = false;
|
291
|
+
begin
|
292
|
+
#@obj.log.debug "STACKTRACE STARTS"
|
293
|
+
d.each do |arr|
|
294
|
+
|
295
|
+
if started
|
296
|
+
|
297
|
+
end_ind = arr.index("`send_action'")
|
298
|
+
if end_ind != nil && end_ind >0
|
299
|
+
ended = true
|
300
|
+
break;
|
301
|
+
end
|
302
|
+
#trArr = arr.split(/:[0-1,in]/);
|
303
|
+
#if trArr[0].length>30
|
304
|
+
# len = trArr.length
|
305
|
+
# trArr[0] = "..."+trArr[(len-30),len]
|
306
|
+
# end
|
307
|
+
inx=arr.index("`instrument'")
|
308
|
+
if inx!=nil && inx>0
|
309
|
+
#skip instrumet data
|
310
|
+
else
|
311
|
+
temp = Array.new
|
312
|
+
temp[0]=arr
|
313
|
+
temp[1]=""
|
314
|
+
temp[2]=""
|
315
|
+
temp[3]=""
|
316
|
+
trace.push(temp)
|
317
|
+
end
|
318
|
+
end
|
319
|
+
|
320
|
+
if started==false
|
321
|
+
ind = arr.index("`instrument'")
|
322
|
+
if ind != nil && ind >0
|
323
|
+
started = true
|
324
|
+
end
|
325
|
+
end
|
326
|
+
|
327
|
+
|
328
|
+
end
|
329
|
+
#@obj.log.debug "STACKTRACE ENDS"
|
330
|
+
|
331
|
+
trace.shift
|
332
|
+
rescue Exception=>e
|
333
|
+
@obj.log.logException "#{e.message}",e
|
334
|
+
end
|
335
|
+
trace
|
336
|
+
end
|
337
|
+
|
338
|
+
def updateOtherTrace d
|
339
|
+
pl = d["payload"]
|
340
|
+
rt = (d["end"] - d["start"])
|
341
|
+
name = d["name"]
|
342
|
+
if pl.has_key?(:identifier)
|
343
|
+
#if pl.has_key?("identifier")
|
344
|
+
name = pl[:identifier]
|
345
|
+
#name = pl["identifier"]
|
346
|
+
end
|
347
|
+
trData = Array.new
|
348
|
+
#trData[0] = (d["start"].to_f * 1000 ).to_i
|
349
|
+
trData[0] = d["ctime"]
|
350
|
+
trData[1] = name
|
351
|
+
trData[2] = ""
|
352
|
+
trData[3] = rt.to_i
|
353
|
+
trData[4] = rt.to_i
|
354
|
+
trData[5] = nil
|
355
|
+
trData[6] = Array.new
|
356
|
+
trData
|
357
|
+
end
|
358
|
+
|
359
|
+
def updateTransTrace(d,trData)
|
360
|
+
|
361
|
+
#trData = Array.new
|
362
|
+
#trData[0] = ((d["start"]).to_f * 1000).to_i
|
363
|
+
pl = d["payload"]
|
364
|
+
trData[1] = pl[:path] + " " +pl[:controller] + "#" + pl[:action]
|
365
|
+
#trData[1] = pl["path"] + " " +pl["controller"] + "#" + pl["action"]
|
366
|
+
trData[2] = ""
|
367
|
+
trData[3] = (d["end"] - trData[0]).to_i
|
368
|
+
trData[4] = (d["end"] - trData[0]).to_i
|
369
|
+
trData[5] = nil
|
370
|
+
#trData[6] = Array.new
|
371
|
+
#dbTime = 0
|
372
|
+
#trdbdata.each do |dbData|
|
373
|
+
# dbTime = dbTime + dbData[3]
|
374
|
+
#end
|
375
|
+
#trData[4] = ((trData[3]).to_f - (dbTime.to_f )).to_i
|
376
|
+
# if(pl[:db_runtime]!=nil)
|
377
|
+
# trData[4] = ((trData[3]).to_f - (pl[:db_runtime].to_f )).to_i
|
378
|
+
# end
|
379
|
+
trData
|
380
|
+
end
|
381
|
+
|
382
|
+
def updateMethodTrace(d,trData)
|
383
|
+
|
384
|
+
#trData = Array.new
|
385
|
+
#trData[0] = ((d["start"]).to_f * 1000).to_i
|
386
|
+
pl = d["payload"]
|
387
|
+
trData[1] = pl[:method]
|
388
|
+
#trData[1] = pl["method"]
|
389
|
+
trData[2] = ""
|
390
|
+
trData[3] = (d["end"] - trData[0]).to_i
|
391
|
+
trData[4] = (d["end"] - trData[0]).to_i
|
392
|
+
trData[5] = nil
|
393
|
+
#trData[6] = Array.new
|
394
|
+
#dbTime = 0
|
395
|
+
#trdbdata.each do |dbData|
|
396
|
+
# dbTime = dbTime + dbData[3]
|
397
|
+
#end
|
398
|
+
#trData[4] = ((trData[3]).to_f - (dbTime.to_f )).to_i
|
399
|
+
# if(pl[:db_runtime]!=nil)
|
400
|
+
# trData[4] = ((trData[3]).to_f - (pl[:db_runtime].to_f )).to_i
|
401
|
+
# end
|
402
|
+
trData
|
403
|
+
end
|
404
|
+
|
405
|
+
def updateStartTrace(d)
|
406
|
+
trData = Array.new
|
407
|
+
#trData[0] = ((d["start"]).to_f * 1000).to_i
|
408
|
+
trData[0] = d["ctime"]
|
409
|
+
trData[1] =""
|
410
|
+
trData[2] =""
|
411
|
+
trData[3] =0
|
412
|
+
trData[4] =0
|
413
|
+
trData[5] =nil
|
414
|
+
trData[6] =Array.new
|
415
|
+
|
416
|
+
trData
|
417
|
+
end
|
418
|
+
|
419
|
+
def updateTrace(trans)
|
420
|
+
# {"thread_name":"http-8080-6","s_time":1326276180289,"t_name":"transaction\/http\/Test-App\/login","r_time":18,"thread_id":141}
|
421
|
+
top = Array.new
|
422
|
+
path = @obj.constants.mf_transaction + @obj.constants.mf_separator + trans[1]
|
423
|
+
det = {"thread_name"=>"rorthread","s_time"=>trans[0],"t_name"=>path,"r_time"=>trans[3],"thread_id"=>141}
|
424
|
+
#trans[6] = db;
|
425
|
+
top[0] = det
|
426
|
+
top[1] = trans
|
427
|
+
top
|
428
|
+
end
|
429
|
+
|
430
|
+
def format s
|
431
|
+
s.gsub!("\"", '')
|
432
|
+
s.gsub!("\n", '')
|
433
|
+
s
|
434
|
+
end
|
435
|
+
|
436
|
+
|
437
|
+
def getTrace data
|
438
|
+
index = 0
|
439
|
+
data.each do |arr|
|
440
|
+
|
441
|
+
if(arr["name"]=="start_processing.action_controller")
|
442
|
+
index = data.index(arr)
|
443
|
+
break;
|
444
|
+
end
|
445
|
+
end
|
446
|
+
data = data.drop(index)
|
447
|
+
tdata =traceDetails data,Array.new,0
|
448
|
+
tdata = updateExclusiveTrace(tdata[0])
|
449
|
+
tdata
|
450
|
+
end
|
451
|
+
|
452
|
+
def traceDetails valo,stack,indx
|
453
|
+
if(valo.size>indx)
|
454
|
+
arr = valo[indx]
|
455
|
+
indx = indx+1
|
456
|
+
if(arr["name"]=="start_processing.action_controller")
|
457
|
+
traceArr = updateStartTrace arr
|
458
|
+
traceArr[6] = Array.new #childs
|
459
|
+
if stack.size()>0
|
460
|
+
cur = stack[stack.size()-1]
|
461
|
+
c = cur[6]
|
462
|
+
c.push(traceArr)
|
463
|
+
cur[6] = c
|
464
|
+
end
|
465
|
+
stack.push(traceArr)
|
466
|
+
|
467
|
+
|
468
|
+
traceDetails valo,stack,indx
|
469
|
+
|
470
|
+
elsif(arr["name"]=="sql.active_record" && @obj.config.sql_capture )
|
471
|
+
|
472
|
+
temp = updateDBTrace arr
|
473
|
+
|
474
|
+
cur = stack[stack.size()-1]
|
475
|
+
c = cur[6]
|
476
|
+
c.push(temp)
|
477
|
+
cur[6] = c
|
478
|
+
traceDetails valo,stack,indx
|
479
|
+
elsif(arr["name"]=="apm.methodstart")
|
480
|
+
temp = updateStartTrace arr
|
481
|
+
cur = stack[stack.size()-1]
|
482
|
+
c = cur[6]
|
483
|
+
c.push(temp)
|
484
|
+
cur[6] = c
|
485
|
+
stack.push(temp)
|
486
|
+
traceDetails valo,stack,indx
|
487
|
+
elsif(arr["name"]=="apm.methodend")
|
488
|
+
updateMethodTrace(arr,stack[stack.size()-1])
|
489
|
+
stack.delete(stack[stack.size()-1])
|
490
|
+
traceDetails valo,stack,indx
|
491
|
+
elsif(arr["name"]=="process_action.action_controller")
|
492
|
+
updateTransTrace(arr,stack[stack.size()-1])
|
493
|
+
if(valo.size()>(indx+1))
|
494
|
+
#Redirection Data
|
495
|
+
arr = valo[indx]
|
496
|
+
while (arr["name"]!="start_processing.action_controller") do
|
497
|
+
indx = indx + 1
|
498
|
+
arr = valo[indx]
|
499
|
+
end
|
500
|
+
end
|
501
|
+
(stack[0])[3] = (arr["end"] - ((stack[0])[0])).to_i
|
502
|
+
(stack[0])[4] = (arr["end"] - ((stack[0])[0])).to_i
|
503
|
+
|
504
|
+
|
505
|
+
traceDetails valo,stack,indx
|
506
|
+
#parent[4] = parent[4] - traceArr[4]
|
507
|
+
elsif (arr["name"]=="render_template.action_view")
|
508
|
+
temp = updateOtherTrace arr
|
509
|
+
|
510
|
+
cur = stack[stack.size()-1]
|
511
|
+
c = cur[6]
|
512
|
+
c.push(temp)
|
513
|
+
cur[6] = c
|
514
|
+
#traceArr[6] = c
|
515
|
+
#parent[4] = parent[4] - temp[4]
|
516
|
+
traceDetails valo,stack,indx
|
517
|
+
else
|
518
|
+
traceDetails valo,stack,indx
|
519
|
+
|
520
|
+
end
|
521
|
+
|
522
|
+
stack
|
523
|
+
else
|
524
|
+
#Nothing todo
|
525
|
+
end
|
526
|
+
end
|
527
|
+
|
528
|
+
|
529
|
+
def updateExclusiveTrace data
|
530
|
+
childs = data[6]
|
531
|
+
childs.each do |arr|
|
532
|
+
data[4] = data[4] - (updateExclusiveTrace arr)[3]
|
533
|
+
end
|
534
|
+
data
|
535
|
+
end
|
536
|
+
|
537
|
+
|
538
|
+
end
|
539
|
+
end
|
540
|
+
|