apminsight 1.0.1 → 1.8.6
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/apm-agent.gemspec +64 -0
- data/conf/apminsight.conf +15 -24
- data/lib/agent/am_objectholder.rb +25 -19
- data/lib/agent/api/custom_tracker.rb +79 -0
- data/lib/agent/configuration/am_configuration.rb +284 -41
- data/lib/agent/handler/custom_api_handler.rb +40 -0
- data/lib/agent/handler/sequence_book.rb +125 -0
- data/lib/agent/handler/tracker_handler.rb +58 -0
- data/lib/agent/logging/am_logger.rb +20 -11
- data/lib/agent/metrics/am_metricsformatter.rb +117 -59
- data/lib/agent/metrics/am_metricsparser.rb +195 -468
- data/lib/agent/metrics/am_metricstore.rb +7 -6
- data/lib/agent/metrics/exception_record.rb +24 -0
- data/lib/agent/server/am_agent.rb +46 -17
- data/lib/agent/server/am_connector.rb +65 -21
- data/lib/agent/server/instrument/action_view.rb +64 -0
- data/lib/agent/server/instrument/active_record.rb +52 -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 +42 -0
- data/lib/agent/server/instrument/rails.rb +56 -0
- data/lib/agent/server/instrument/sinatra.rb +97 -0
- data/lib/agent/server/worker/am_worker.rb +93 -49
- data/lib/agent/trackers/database_tracker.rb +107 -0
- data/lib/agent/trackers/default_tracker.rb +62 -0
- data/lib/agent/trackers/root_tracker.rb +43 -0
- data/lib/agent/util/am_constants.rb +53 -8
- data/lib/agent/util/am_util.rb +64 -1
- data/lib/agent/util/transaction_util.rb +35 -0
- data/lib/agent/version.rb +13 -0
- data/lib/apminsight.rb +4 -1
- metadata +114 -76
@@ -4,6 +4,8 @@ require "logger"
|
|
4
4
|
module ManageEngine
|
5
5
|
class APMLogger
|
6
6
|
@apmlog=nil;
|
7
|
+
@apmLogPath=nil;
|
8
|
+
|
7
9
|
def initialize
|
8
10
|
@obj=ManageEngine::APMObjectHolder.instance
|
9
11
|
path = getLogsPath
|
@@ -11,20 +13,29 @@ module ManageEngine
|
|
11
13
|
if Dir[path] == []
|
12
14
|
Dir.mkdir(path)
|
13
15
|
end
|
14
|
-
|
16
|
+
@apmLogPath= path + '/apm.log'
|
15
17
|
#puts "#{path}"
|
16
18
|
# file = open(path, File::WRONLY | File::APPEND | File::CREAT)
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
19
|
+
begin
|
20
|
+
@apmlog = Logger.new(@apmLogPath, 10, 5 * 1024 * 1024)
|
21
|
+
@apmlog.level = Logger::INFO
|
22
|
+
rescue Exception => e
|
23
|
+
puts "Unable to create/edit the log file #{@apmLogPath}. Writing agent logs to STDOUT.\nError: #{e.message}"
|
24
|
+
@apmlog = Logger.new(STDOUT)
|
25
|
+
@apmlog.level = Logger::WARN
|
26
|
+
end
|
27
|
+
# @apmlog = Logger.new(file)
|
28
|
+
@apmlog.datetime_format = "%Y-%m-%d %H:%M:%S"
|
21
29
|
@apmlog.formatter = proc do |severity, datetime, progname, msg|
|
22
|
-
"[#{datetime}|#{Process.pid}]:#{msg}\n"
|
30
|
+
"[#{datetime}|#{Process.pid}][#{severity}]:#{msg}\n"
|
23
31
|
end
|
24
32
|
@apmlog.debug("[LOGGER] APM Agent Logging Initialized")
|
25
33
|
|
26
34
|
end
|
27
35
|
|
36
|
+
def getLogFilePath
|
37
|
+
return @apmLogPath
|
38
|
+
end
|
28
39
|
|
29
40
|
def getLogsPath
|
30
41
|
props = {}
|
@@ -53,7 +64,7 @@ module ManageEngine
|
|
53
64
|
if props["apminsight.log.dir"]!=nil
|
54
65
|
return props["apminsight.log.dir"]
|
55
66
|
else
|
56
|
-
return "
|
67
|
+
return @obj.constants.conf_location+"log"
|
57
68
|
end
|
58
69
|
|
59
70
|
end
|
@@ -96,10 +107,8 @@ module ManageEngine
|
|
96
107
|
|
97
108
|
|
98
109
|
def logException(msg,e)
|
99
|
-
@apmlog.
|
100
|
-
@apmlog.
|
101
|
-
@apmlog.debug( "Message : #{msg}\nTrace :\n#{e.backtrace}")
|
102
|
-
@apmlog.debug( "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
|
110
|
+
@apmlog.warn( "#{msg} => #{e.message}")
|
111
|
+
@apmlog.warn( "Message : #{msg}\nTrace :\n#{e.backtrace}")
|
103
112
|
end
|
104
113
|
|
105
114
|
def close
|
@@ -6,8 +6,8 @@ module ManageEngine
|
|
6
6
|
@obj = ManageEngine::APMObjectHolder.instance
|
7
7
|
@apdex_threshold = 0
|
8
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]
|
9
|
+
#trans Vs #[0-rspTime,1-min rt,2-max rt,3-cnt,4-apdx,5-stat,6-toler,7-frustating,8-error_count]
|
10
|
+
#DBtrans Vs #[rspTime,min rt,max rt,cnt,error_count]
|
11
11
|
#trace
|
12
12
|
|
13
13
|
def format d
|
@@ -95,34 +95,41 @@ module ManageEngine
|
|
95
95
|
end
|
96
96
|
|
97
97
|
def updateinstance
|
98
|
-
ins_apdx =
|
99
|
-
|
100
|
-
rt = 0;
|
101
|
-
s=0;
|
102
|
-
t=0;
|
103
|
-
f=0;
|
104
|
-
min = -1;
|
105
|
-
max = 0;
|
98
|
+
ins_apdx = [0,-1,-1,0,0,0,0,0,0]
|
99
|
+
logmetric = Hash.new
|
106
100
|
@transaction.each do |key,value|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
101
|
+
apdexValue = value[0]
|
102
|
+
ins_apdx[0] += apdexValue[0]
|
103
|
+
if ins_apdx[1] == -1
|
104
|
+
ins_apdx[1] = apdexValue[1]
|
105
|
+
ins_apdx[2] = apdexValue[2]
|
106
|
+
else
|
107
|
+
if(apdexValue[1]<ins_apdx[1])
|
108
|
+
ins_apdx[1] = apdexValue[1]
|
109
|
+
end
|
110
|
+
if (apdexValue[2]>ins_apdx[2])
|
111
|
+
ins_apdx[2] = apdexValue[2]
|
112
|
+
end
|
117
113
|
end
|
118
|
-
|
114
|
+
ins_apdx[3] += apdexValue[3]
|
119
115
|
|
120
|
-
|
121
|
-
|
122
|
-
|
116
|
+
ins_apdx[5] += apdexValue[5]
|
117
|
+
ins_apdx[6] += apdexValue[6]
|
118
|
+
ins_apdx[7] += apdexValue[7]
|
119
|
+
ins_apdx[8] += apdexValue[8]
|
120
|
+
|
121
|
+
exceptions = value[1][@obj.constants.mf_logmetric]
|
122
|
+
if (exceptions != nil)
|
123
|
+
exceptions.each do |name, count|
|
124
|
+
logmetric[name] = logmetric[name].to_i + count
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
if (ins_apdx[3] > 0)
|
129
|
+
ins_apdx[4] = (ins_apdx[5].to_f + (ins_apdx[6]/2).to_f).to_f/ins_apdx[3].to_f
|
130
|
+
ins_apdx[0] = ins_apdx[0].round(2)
|
123
131
|
end
|
124
|
-
|
125
|
-
@instance[":apdex"]=[rt.round(2),min,max,cnt,apx,s,t,f]
|
132
|
+
@instance[":apdex"]=[ins_apdx, {@obj.constants.mf_logmetric=>logmetric}]
|
126
133
|
end
|
127
134
|
|
128
135
|
def updatedbinstance
|
@@ -130,6 +137,7 @@ module ManageEngine
|
|
130
137
|
rt = 0;
|
131
138
|
min = -1;
|
132
139
|
max = 0;
|
140
|
+
error_count = 0;
|
133
141
|
if(@db.length>0)
|
134
142
|
@db.each do |key,val|
|
135
143
|
value = val["metrics"]
|
@@ -145,8 +153,9 @@ module ManageEngine
|
|
145
153
|
max = value[2]
|
146
154
|
end
|
147
155
|
cnt = cnt + value[3]
|
156
|
+
error_count += value[4]
|
148
157
|
end
|
149
|
-
@dbinstance[":apdex"]=[rt.round(2),min,max,cnt]
|
158
|
+
@dbinstance[":apdex"]=[rt.round(2),min,max,cnt,error_count]
|
150
159
|
end
|
151
160
|
end
|
152
161
|
|
@@ -154,25 +163,61 @@ module ManageEngine
|
|
154
163
|
begin
|
155
164
|
pl = d["td"]
|
156
165
|
dbl = d["db"]
|
166
|
+
exc = d["exception"]
|
157
167
|
|
158
168
|
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
|
169
|
+
path = @obj.constants.mf_transaction + @obj.constants.mf_separator + pl["path"]
|
163
170
|
|
164
171
|
|
165
172
|
apx_stat = nil
|
173
|
+
additionalInfo = nil
|
166
174
|
if(@transaction.has_key?(path))
|
167
|
-
apx_stat = @transaction[path]
|
175
|
+
apx_stat = @transaction[path][0]
|
176
|
+
additionalInfo = @transaction[path][1]
|
168
177
|
else
|
178
|
+
if @transaction.length == @obj.config.metric_overflow_t
|
179
|
+
@obj.log.debug "Metricstore overflow. Current Size: #{@obj.config.metric_overflow_t} #{path}"
|
180
|
+
return
|
181
|
+
end
|
169
182
|
apx_stat = Array.new
|
170
|
-
apx_stat = [0,
|
183
|
+
apx_stat = [0,0,0,0,0,0,0,0,0]
|
184
|
+
additionalInfo = Hash.new
|
171
185
|
end
|
172
|
-
|
173
|
-
|
186
|
+
|
187
|
+
if (pl.has_key?("error"))
|
188
|
+
apx_stat[8] += 1
|
189
|
+
else
|
190
|
+
apx_stat = apxarray apx_stat,rt
|
191
|
+
end
|
192
|
+
|
193
|
+
if (exc != nil)
|
194
|
+
logmetric = additionalInfo[@obj.constants.mf_logmetric]
|
195
|
+
if (logmetric == nil)
|
196
|
+
additionalInfo[@obj.constants.mf_logmetric] = exc
|
197
|
+
else
|
198
|
+
exc.each do |name, count|
|
199
|
+
logmetric[name] = logmetric[name].to_i + count
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
@transaction[path] = [apx_stat, additionalInfo]
|
174
205
|
if(dbl!=nil)
|
175
|
-
|
206
|
+
if @db.length < @obj.config.dbmetric_overflow_t
|
207
|
+
updatedb dbl,path
|
208
|
+
elsif @db.length == @obj.config.dbmetric_overflow_t
|
209
|
+
@obj.log.debug "DB metric overflow. Current Size: #{@obj.config.dbmetric_overflow_t} #{path}"
|
210
|
+
#@obj.log.info "data = #{@db}"
|
211
|
+
of = Hash.new
|
212
|
+
stats = Array.new
|
213
|
+
stats = [0,0,0,0,0]
|
214
|
+
of["tpath"] = @obj.constants.mf_overflow
|
215
|
+
#of["tpath"] = @obj.constants.mf_transaction + @obj.constants.mf_separator + @obj.constants.mf_overflow #using this for testing purpose
|
216
|
+
of["path"] = @obj.constants.mf_db + @obj.constants.mf_separator + @obj.constants.mf_overflow + @obj.constants.mf_separator + "-" + @obj.constants.mf_separator
|
217
|
+
of["metrics"] = stats
|
218
|
+
@db[@obj.constants.mf_overflow]=of
|
219
|
+
#@obj.log.info "data updated = #{@db}"
|
220
|
+
end
|
176
221
|
end
|
177
222
|
rescue Exception=>e
|
178
223
|
@obj.log.info "#{e.message}"
|
@@ -181,6 +226,7 @@ module ManageEngine
|
|
181
226
|
# Apmagent::ApmLogger.instance.info "update transaction end"
|
182
227
|
end
|
183
228
|
|
229
|
+
# Updates apdex score and increases statisfied, tolerating, frustrated count accordingly
|
184
230
|
def apxarray apx_stat,rt
|
185
231
|
|
186
232
|
# Apmagent::ApmLogger.instance.info "apxarray : start #{apx_stat}"
|
@@ -193,16 +239,19 @@ module ManageEngine
|
|
193
239
|
apx_stat[6] = apx_stat[6] + 1
|
194
240
|
end
|
195
241
|
|
196
|
-
|
242
|
+
if (apx_stat[3] > 0)
|
243
|
+
apx_stat[4] = (apx_stat[5].to_f + (apx_stat[6].to_f/2).to_f)/apx_stat[3].to_f
|
244
|
+
end
|
197
245
|
# Apmagent::ApmLogger.instance.info "apxarray : end #{apx_stat}"
|
198
246
|
apx_stat
|
199
247
|
end
|
200
248
|
|
249
|
+
# Updates resp time, min rt and max rt in apdex metric
|
201
250
|
def updatert apx_stat,rt
|
202
251
|
# Apmagent::ApmLogger.instance.info "updatert : start"
|
203
|
-
apx_stat[3] = apx_stat[3] +1
|
252
|
+
apx_stat[3] = apx_stat[3] + 1
|
204
253
|
apx_stat[0] = apx_stat[0] + rt
|
205
|
-
if(rt < apx_stat[1])
|
254
|
+
if(apx_stat[1] == 0 || rt < apx_stat[1])
|
206
255
|
apx_stat[1] = rt
|
207
256
|
end
|
208
257
|
if(rt > apx_stat[2])
|
@@ -211,7 +260,8 @@ module ManageEngine
|
|
211
260
|
#Apmagent::ApmLogger.instance.info "updatert : end"
|
212
261
|
apx_stat
|
213
262
|
end
|
214
|
-
|
263
|
+
|
264
|
+
#DBtrans Vs #[rspTime,min rt,max rt,cnt,error_count]
|
215
265
|
def updatedb dpl,tpath
|
216
266
|
# Apmagent::ApmLogger.instance.info "updatedb : start"
|
217
267
|
dpl.each do |pl|
|
@@ -227,37 +277,45 @@ module ManageEngine
|
|
227
277
|
stat = val["metrics"]
|
228
278
|
else
|
229
279
|
val=Hash.new
|
280
|
+
val["tpath"] = tpath
|
281
|
+
val["path"] = dpath
|
230
282
|
stat = Array.new
|
231
|
-
stat = [
|
283
|
+
stat = [0,rt,rt,0,0]
|
284
|
+
end
|
285
|
+
if (pl.has_key?("error"))
|
286
|
+
stat[4] += 1
|
287
|
+
else
|
288
|
+
stat = updatert stat,rt
|
232
289
|
end
|
233
|
-
stat = updatert stat,rt
|
234
|
-
val["tpath"] = tpath
|
235
|
-
val["path"] = dpath
|
236
290
|
val["metrics"] = stat
|
237
291
|
@db[path] = val
|
238
|
-
updatedboperations rt, pl["operation"]
|
292
|
+
updatedboperations rt, pl["operation"], pl["error"]
|
239
293
|
end
|
240
294
|
#Apmagent::ApmLogger.instance.info "updatedb : end"
|
241
295
|
end
|
242
296
|
|
243
|
-
def updatedboperations rt,operation
|
244
|
-
opstats = Array.new;
|
245
|
-
#puts "#{operation} "
|
297
|
+
def updatedboperations rt, operation, isError
|
246
298
|
if(@dboperations.has_key?(operation))
|
247
299
|
opstats = @dboperations[operation]
|
248
300
|
else
|
249
|
-
|
250
|
-
|
251
|
-
opstats[0] = opstats[0] + rt
|
252
|
-
if(rt<opstats[1])
|
253
|
-
opstats[1] = rt
|
301
|
+
opstats = Array.new;
|
302
|
+
opstats = [0.0,rt,rt,0,0]
|
254
303
|
end
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
304
|
+
|
305
|
+
if (isError)
|
306
|
+
opstats[4] += 1
|
307
|
+
else
|
308
|
+
opstats[0] = opstats[0] + rt
|
309
|
+
if(rt<opstats[1])
|
310
|
+
opstats[1] = rt
|
311
|
+
end
|
312
|
+
if (rt>opstats[2])
|
313
|
+
opstats[2] = rt
|
314
|
+
end
|
315
|
+
opstats[3] = opstats[3] +1
|
316
|
+
end
|
259
317
|
@dboperations[operation]=opstats
|
260
318
|
end
|
261
319
|
|
262
|
-
end
|
263
|
-
end
|
320
|
+
end#class
|
321
|
+
end#module
|