Class: ManageEngine::APMMetricsParser
- Inherits:
-
Object
- Object
- ManageEngine::APMMetricsParser
- Defined in:
- lib/agent/metrics/am_metricsparser.rb
Instance Method Summary collapse
-
#getDBData(tracker, tdata, exceptionInfo) ⇒ Object
Generates DB metric.
- #getDummyTrace ⇒ Object
- #getTransData(rootTracker, tdata) ⇒ Object
-
#initialize ⇒ APMMetricsParser
constructor
A new instance of APMMetricsParser.
-
#parse(data) ⇒ Object
Invoked by APMWorker in dc.
- #updateComponentData(tracker, tdata) ⇒ Object
- #updateExceptionInfo(exceptionInfo, time, error, message = nil) ⇒ Object
- #updateExceptionMetric(exception, tdata) ⇒ Object
- #updateParsedData(key, tdata, parseddata) ⇒ Object
- #updateTrace(roottracker, trans, exceptionInfo) ⇒ Object
-
#updateTraceData(rootTracker, parseddata, exceptionInfo) ⇒ Object
Generates Trace for the transaction and updates it in ‘parseddata’ hash.
Constructor Details
#initialize ⇒ APMMetricsParser
Returns a new instance of APMMetricsParser.
6 7 8 |
# File 'lib/agent/metrics/am_metricsparser.rb', line 6 def initialize @obj = ManageEngine::APMObjectHolder.instance end |
Instance Method Details
#getDBData(tracker, tdata, exceptionInfo) ⇒ Object
Generates DB metric
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 |
# File 'lib/agent/metrics/am_metricsparser.rb', line 161 def getDBData(tracker, tdata, exceptionInfo) if (tracker != nil) children = tracker.children children.each do |child| tdata["db"] = getDBData(child, tdata, exceptionInfo) if child.kind_of?(ManageEngine::Tracker::DatabaseTracker) if tdata["db"] == nil tdata["db"] = Array.new end queryInfo = child.getQueryInfo sqlStrip = queryInfo[0] + "/" + queryInfo[1] + "/dummydb" ret ={"rt"=>child.duration, "sql"=>child.getRawQuery, "sql-strip"=>sqlStrip, "name"=>child.name, "operation"=>queryInfo[0]} if (child.error?) ret["error"] = true end tdata["db"].push(ret) end ## DBTracker check # updateComponentData(child, tdata) if (child.error?) updateExceptionMetric(child.error, tdata) # <= previously it was 'ret' updateExceptionInfo(exceptionInfo, child.endtime.to_i, child.error) end end #end of children iteration # tdata["db"] = getDBData(tracker.child, tdata, exceptionInfo) # # if tracker.kind_of?(ManageEngine::Tracker::DatabaseTracker) # if tdata["db"] == nil # tdata["db"] = Array.new # end # # queryInfo = tracker.getQueryInfo # sqlStrip = queryInfo[0] + "/" + queryInfo[1] + "/dummydb" # # ret ={"rt"=>tracker.duration, "sql"=>tracker.getRawQuery, # "sql-strip"=>sqlStrip, "name"=>tracker.name, "operation"=>queryInfo[0]} # # if (tracker.error?) # ret["error"] = true # end # # tdata["db"].push(ret) # end ## DBTracker check # # if (tracker.error?) # updateExceptionMetric(tracker.error, tdata) # <= previously it was 'ret' # updateExceptionInfo(exceptionInfo, tracker.endtime.to_i, tracker.error) # end # # tracker = tracker.sibling end ## if tracker nil tdata["db"] end |
#getDummyTrace ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/agent/metrics/am_metricsparser.rb', line 120 def getDummyTrace top = Array.new path = @obj.constants.mf_overflow det = {"thread_name"=>"rorthread","s_time"=>0,"t_name"=>path,"r_time"=>0,"thread_id"=>141} trData = Array.new trData[0] = 0 trData[1] = path trData[2] = "" trData[3] = 0 trData[4] = 0 trData[5] = nil trData[6] = Array.new top[0] = det top[1] = trData return top end |
#getTransData(rootTracker, tdata) ⇒ Object
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/agent/metrics/am_metricsparser.rb', line 137 def getTransData(rootTracker, tdata) ret = nil; begin if(tdata.has_key?("td")) ret = tdata["td"] ret["rt"] = ret["rt"] + rootTracker.duration else ret = {"rt"=> rootTracker.duration, "path"=>rootTracker.getTxnName, "type"=>rootTracker.getTxnType} if (rootTracker.error?) ret["error"] = true end end if (rootTracker.getStatus != nil && rootTracker.getStatus >= 400) ret["status"] = rootTracker.getStatus ret["error"] = true end rescue Exception=>e #@obj.log.logException "Exception in getTranseData: #{e.message}",e raise e end ret end |
#parse(data) ⇒ Object
Invoked by APMWorker in dc
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/agent/metrics/am_metricsparser.rb', line 11 def parse(data) @obj = ManageEngine::APMObjectHolder.instance parseddata = Hash.new begin data.each do |txn_name, seqBag| @obj.log.debug "[Processing started for - #{txn_name} ]" seqBag.each do |seqData| begin tdata = Hash.new #transaction data -> rt, path,.. exceptionInfo = Array.new # data to be sent in trace as 'loginfo' rootTracker = seqData["roottracker"] tdata["td"] = getTransData(rootTracker,tdata) tdata["db"] = getDBData(rootTracker, tdata, exceptionInfo) if (rootTracker.error?) # root tracker will be left out in above flow updateExceptionMetric(rootTracker.error, tdata) # <= previously it was 'ret' updateExceptionInfo(exceptionInfo, rootTracker.endtime.to_i, rootTracker.error) end exceptionBag = seqData["exceptions"] if exceptionBag != nil exceptionBag.each do |exceptionRecord| updateExceptionMetric(exceptionRecord.exception,tdata) updateExceptionInfo(exceptionInfo, exceptionRecord.time, exceptionRecord.exception, exceptionRecord.) end end parseddata = updateParsedData(txn_name, tdata.dup, parseddata) if @obj.config.trans_trace && (rootTracker.duration >= (@obj.config.trans_trace_t.to_f*1000).to_i || rootTracker.error?) parseddata = updateTraceData(rootTracker, parseddata, exceptionInfo) end rescue Exception=>e @obj.log.logException "Exception in Parsing txn #{txn_name}",e end end # do - seqBag @obj.store.removeData txn_name @obj.log.debug "[Processing END for - #{txn_name} ]" end # do-loop rescue Exception=>e @obj.log.info "Exception : #{e}" @obj.log.logException "#{e.}",e end # @obj.log.debug "[PARSER] End" parseddata end |
#updateComponentData(tracker, tdata) ⇒ Object
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 |
# File 'lib/agent/metrics/am_metricsparser.rb', line 220 def updateComponentData (tracker, tdata) begin compData = tdata["comp"] if (compData == nil) compData = Hash.new tdata["comp"] = compData end info = compData[tracker.component] if (info == nil) info = Hash.new compData[tracker.component] = info info[@obj.constants.component_name] = tracker.component info[@obj.constants.component_time] = tracker.duration info[@obj.constants.component_count] = 1 if (tracker.error?) info[@obj.constants.component_error_count] = 1 end else info[@obj.constants.component_time] += tracker.duration info[@obj.constants.component_count] += 1 if (tracker.error?) info[@obj.constants.component_error_count] += 1 end end rescue Exception=>e end end |
#updateExceptionInfo(exceptionInfo, time, error, message = nil) ⇒ Object
62 63 64 65 66 67 68 69 |
# File 'lib/agent/metrics/am_metricsparser.rb', line 62 def updateExceptionInfo (exceptionInfo, time, error, = nil) logInfo = { @obj.constants.mf_loginfo_time => time, @obj.constants.mf_loginfo_level => @obj.constants.mf_loginfo_level_warn, @obj.constants.mf_loginfo_str => != nil ? : error., @obj.constants.mf_loginfo_err_clz => error.class.to_s, @obj.constants.mf_loginfo_st => @obj.util.formatStacktrace(error.backtrace) } exceptionInfo.push(logInfo) end |
#updateExceptionMetric(exception, tdata) ⇒ Object
248 249 250 251 252 253 254 255 256 257 |
# File 'lib/agent/metrics/am_metricsparser.rb', line 248 def updateExceptionMetric (exception, tdata) excData = tdata["exception"] if (excData == nil) excData = Hash.new tdata["exception"] = excData end excData[exception.class.to_s] = excData[exception.class.to_s].to_i + 1 excData[@obj.constants.mf_logmetric_warning] = excData[@obj.constants.mf_logmetric_warning].to_i + 1 end |
#updateParsedData(key, tdata, parseddata) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/agent/metrics/am_metricsparser.rb', line 71 def updateParsedData (key, tdata, parseddata) begin if parseddata.has_key?(key) key = rand # Use a random number end #@obj.log.debug "Update parsed data : #{key} = > #{tdata}" parseddata[key]=tdata rescue Exception=>e @obj.log.info "Exception in updateParsedData: #{e}" @obj.log.logException "#{e.}",e end parseddata end |
#updateTrace(roottracker, trans, exceptionInfo) ⇒ Object
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 |
# File 'lib/agent/metrics/am_metricsparser.rb', line 259 def updateTrace(roottracker, trans, exceptionInfo) # {"thread_name":"http-8080-6","s_time":1326276180289,"t_name":"transaction\/http\/Test-App\/login","r_time":18,"thread_id":141} top = Array.new path = roottracker.getTxnName det = {"s_time"=>trans[0],"t_name"=>path,"r_time"=>trans[3]} det = det.merge(roottracker.getTraceInfo) exception = trans[5] != nil ? trans[5][@obj.constants.mf_exception_st] : nil if (exception != nil) det[@obj.constants.mf_err_st] = exception end if (exceptionInfo.length > 0) det[@obj.constants.mf_loginfo] = exceptionInfo end top[0] = det top[1] = trans top end |
#updateTraceData(rootTracker, parseddata, exceptionInfo) ⇒ Object
Generates Trace for the transaction and updates it in ‘parseddata’ hash
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/agent/metrics/am_metricsparser.rb', line 86 def updateTraceData(rootTracker, parseddata, exceptionInfo) if(parseddata.has_key?("trace-data")) tData = parseddata["trace-data"]; if(tData.length == @obj.config.trace_overflow_t) trac = getDummyTrace tData.push(trac) parseddata["trace-data"]=tData @obj.log.debug "dummy trace added" @obj.log.debug "trace threshold exceeded. Current Size: #{@obj.config.trace_overflow_t}" return parseddata elsif tData.length > @obj.config.trace_overflow_t return parseddata end end begin #trdata = getTrace(rootTracker) trdata = rootTracker.getTrace() trac = updateTrace(rootTracker, trdata, exceptionInfo) if(parseddata.has_key?("trace-data")) traceData = parseddata["trace-data"]; traceData.push(trac); parseddata["trace-data"] = traceData; else traceData = Array.new traceData.push(trac) parseddata["trace-data"] = traceData; end rescue Exception=>e @obj.log.info "Exception in updateTraceData: #{e}" @obj.log.logException "#{e.}",e end parseddata end |