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,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,277 @@
|
|
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
|
+
if @db.length < @obj.config.metric_overflow_t
|
176
|
+
updatedb dbl,path
|
177
|
+
elsif @db.length == @obj.config.metric_overflow_t
|
178
|
+
#@obj.log.info "metric overflow #{@db.length} for threshold #{@obj.config.metric_overflow_t}"
|
179
|
+
#@obj.log.info "data = #{@db}"
|
180
|
+
of = Hash.new
|
181
|
+
stats = Array.new
|
182
|
+
stats = [0,0,0,0]
|
183
|
+
of["tpath"] = @obj.constants.mf_overflow
|
184
|
+
#of["tpath"] = @obj.constants.mf_transaction + @obj.constants.mf_separator + @obj.constants.mf_overflow #using this for testing purpose
|
185
|
+
of["path"] = @obj.constants.mf_db + @obj.constants.mf_separator + @obj.constants.mf_overflow + @obj.constants.mf_separator + "-" + @obj.constants.mf_separator
|
186
|
+
of["metrics"] = stats
|
187
|
+
@db[@obj.constants.mf_overflow]=of
|
188
|
+
#@obj.log.info "data updated = #{@db}"
|
189
|
+
end
|
190
|
+
end
|
191
|
+
rescue Exception=>e
|
192
|
+
@obj.log.info "#{e.message}"
|
193
|
+
@obj.log.logException "[Format] [ updatetransaction ] #{e.message}",e
|
194
|
+
end
|
195
|
+
# Apmagent::ApmLogger.instance.info "update transaction end"
|
196
|
+
end
|
197
|
+
|
198
|
+
def apxarray apx_stat,rt
|
199
|
+
|
200
|
+
# Apmagent::ApmLogger.instance.info "apxarray : start #{apx_stat}"
|
201
|
+
apx_stat = updatert apx_stat,rt
|
202
|
+
if rt <= @apdex_threshold
|
203
|
+
apx_stat[5] = apx_stat[5] + 1
|
204
|
+
elsif rt > (4 * @apdex_threshold)
|
205
|
+
apx_stat[7] = apx_stat[7] + 1
|
206
|
+
else
|
207
|
+
apx_stat[6] = apx_stat[6] + 1
|
208
|
+
end
|
209
|
+
|
210
|
+
apx_stat[4] = (apx_stat[5].to_f + (apx_stat[6].to_f/2).to_f)/apx_stat[3].to_f
|
211
|
+
# Apmagent::ApmLogger.instance.info "apxarray : end #{apx_stat}"
|
212
|
+
apx_stat
|
213
|
+
end
|
214
|
+
|
215
|
+
def updatert apx_stat,rt
|
216
|
+
# Apmagent::ApmLogger.instance.info "updatert : start"
|
217
|
+
apx_stat[3] = apx_stat[3] +1
|
218
|
+
apx_stat[0] = apx_stat[0] + rt
|
219
|
+
if(rt < apx_stat[1])
|
220
|
+
apx_stat[1] = rt
|
221
|
+
end
|
222
|
+
if(rt > apx_stat[2])
|
223
|
+
apx_stat[2] = rt
|
224
|
+
end
|
225
|
+
#Apmagent::ApmLogger.instance.info "updatert : end"
|
226
|
+
apx_stat
|
227
|
+
end
|
228
|
+
#DBtrans Vs #[rspTime,min rt,max rt,cnt]
|
229
|
+
def updatedb dpl,tpath
|
230
|
+
# Apmagent::ApmLogger.instance.info "updatedb : start"
|
231
|
+
dpl.each do |pl|
|
232
|
+
rt = pl["rt"].round(2)
|
233
|
+
path = pl["sql-strip"]
|
234
|
+
dpath = @obj.constants.mf_db + @obj.constants.mf_separator + path
|
235
|
+
path = tpath + @obj.constants.mf_separator + dpath
|
236
|
+
sql = pl["sql"]
|
237
|
+
stat = nil
|
238
|
+
val = nil
|
239
|
+
if(@db.has_key?(path))
|
240
|
+
val = @db[path]
|
241
|
+
stat = val["metrics"]
|
242
|
+
else
|
243
|
+
val=Hash.new
|
244
|
+
stat = Array.new
|
245
|
+
stat = [rt,rt,rt,0]
|
246
|
+
end
|
247
|
+
stat = updatert stat,rt
|
248
|
+
val["tpath"] = tpath
|
249
|
+
val["path"] = dpath
|
250
|
+
val["metrics"] = stat
|
251
|
+
@db[path] = val
|
252
|
+
updatedboperations rt, pl["operation"]
|
253
|
+
end
|
254
|
+
#Apmagent::ApmLogger.instance.info "updatedb : end"
|
255
|
+
end
|
256
|
+
|
257
|
+
def updatedboperations rt,operation
|
258
|
+
opstats = Array.new;
|
259
|
+
#puts "#{operation} "
|
260
|
+
if(@dboperations.has_key?(operation))
|
261
|
+
opstats = @dboperations[operation]
|
262
|
+
else
|
263
|
+
opstats = [0.0,rt,rt,0]
|
264
|
+
end
|
265
|
+
opstats[0] = opstats[0] + rt
|
266
|
+
if(rt<opstats[1])
|
267
|
+
opstats[1] = rt
|
268
|
+
end
|
269
|
+
if (rt>opstats[2])
|
270
|
+
opstats[2] = rt
|
271
|
+
end
|
272
|
+
opstats[3] = opstats[3] +1
|
273
|
+
@dboperations[operation]=opstats
|
274
|
+
end
|
275
|
+
|
276
|
+
end
|
277
|
+
end
|