Class: ManageEngine::APMMetricsFormatter
- Inherits:
-
Object
- Object
- ManageEngine::APMMetricsFormatter
- Defined in:
- lib/agent/metrics/am_metricsformatter.rb
Instance Method Summary collapse
-
#apxarray(apx_stat, rt) ⇒ Object
Updates apdex score and increases statisfied, tolerating, frustrated count accordingly.
-
#format(d) ⇒ Object
trans Vs #[0-rspTime,1-min rt,2-max rt,3-cnt,4-apdx,5-stat,6-toler,7-frustating,8-error_count] DBtrans Vs #[rspTime,min rt,max rt,cnt,error_count] trace.
- #intialize ⇒ Object
- #keysToRemove ⇒ Object
-
#updatedb(dpl, tpath) ⇒ Object
DBtrans Vs #[rspTime,min rt,max rt,cnt,error_count].
- #updatedbinstance ⇒ Object
- #updatedboperations(rt, operation, isError) ⇒ Object
- #updateinstance ⇒ Object
-
#updatert(apx_stat, rt) ⇒ Object
Updates resp time, min rt and max rt in apdex metric.
- #updatetransaction(d) ⇒ Object
Instance Method Details
#apxarray(apx_stat, rt) ⇒ Object
Updates apdex score and increases statisfied, tolerating, frustrated count accordingly
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 |
# File 'lib/agent/metrics/am_metricsformatter.rb', line 230 def apxarray apx_stat,rt # Apmagent::ApmLogger.instance.info "apxarray : start #{apx_stat}" apx_stat = updatert apx_stat,rt if rt <= @apdex_threshold apx_stat[5] = apx_stat[5] + 1 elsif rt > (4 * @apdex_threshold) apx_stat[7] = apx_stat[7] + 1 else apx_stat[6] = apx_stat[6] + 1 end if (apx_stat[3] > 0) apx_stat[4] = (apx_stat[5].to_f + (apx_stat[6].to_f/2).to_f)/apx_stat[3].to_f end # Apmagent::ApmLogger.instance.info "apxarray : end #{apx_stat}" apx_stat end |
#format(d) ⇒ Object
trans Vs #[0-rspTime,1-min rt,2-max rt,3-cnt,4-apdx,5-stat,6-toler,7-frustating,8-error_count] DBtrans Vs #[rspTime,min rt,max rt,cnt,error_count] trace
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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/agent/metrics/am_metricsformatter.rb', line 13 def format d result = Array.new @obj = ManageEngine::APMObjectHolder.instance begin @apdex_threshold = @obj.config.apdex_t * 1000 #@obj.log.info "[FORMAT]" @transaction = Hash.new @db = Hash.new @instance = Hash.new @dbinstance = Hash.new @dboperations = Hash.new @keystoremove = Array.new d.each do |key,value| @keystoremove.push(key) updatetransaction value end updateinstance updatedbinstance @transaction.each do |key,value| res = Hash.new res[@obj.constants.mf_namespace] = key res[@obj.constants.mf_name] = @obj.constants.mf_apdex valArr= Array.new valArr[0] =res valArr[1] =value result.push(valArr) end @db.each do |key,value| #puts "#{key} == #{value}" res = Hash.new res[@obj.constants.mf_namespace] = value["tpath"] res[@obj.constants.mf_name] = value["path"] valArr= Array.new valArr[0] =res valArr[1] =value["metrics"] result.push(valArr) end @instance.each do |key,value| res = Hash.new res[@obj.constants.mf_namespace] = "" res[@obj.constants.mf_name] = @obj.constants.mf_apdex valArr= Array.new valArr[0] =res valArr[1] =value result.push(valArr) end @dbinstance.each do |key,value| res = Hash.new res[@obj.constants.mf_namespace] = "" 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" valArr= Array.new valArr[0] =res valArr[1] =value result.push(valArr) end @dboperations.each do |key,value| ind = @obj.config.db_operations.index(key) if (ind!=nil) res = Hash.new res[@obj.constants.mf_namespace] = "" 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" valArr= Array.new valArr[0] =res valArr[1] =value result.push(valArr) end end #@obj.log.info "[FORMAT] COMPLETED" rescue Exception=>e @obj.log.logException "[FORMAT]#{e.}",e end @transaction.clear @db.clear @instance.clear result end |
#intialize ⇒ Object
5 6 7 8 |
# File 'lib/agent/metrics/am_metricsformatter.rb', line 5 def intialize @obj = ManageEngine::APMObjectHolder.instance @apdex_threshold = 0 end |
#keysToRemove ⇒ Object
93 94 95 |
# File 'lib/agent/metrics/am_metricsformatter.rb', line 93 def keysToRemove @keystoremove end |
#updatedb(dpl, tpath) ⇒ Object
DBtrans Vs #[rspTime,min rt,max rt,cnt,error_count]
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 |
# File 'lib/agent/metrics/am_metricsformatter.rb', line 265 def updatedb dpl,tpath # Apmagent::ApmLogger.instance.info "updatedb : start" dpl.each do |pl| rt = pl["rt"].round(2) path = pl["sql-strip"] dpath = @obj.constants.mf_db + @obj.constants.mf_separator + path path = tpath + @obj.constants.mf_separator + dpath sql = pl["sql"] stat = nil val = nil if(@db.has_key?(path)) val = @db[path] stat = val["metrics"] else val=Hash.new val["tpath"] = tpath val["path"] = dpath stat = Array.new stat = [0,rt,rt,0,0] end if (pl.has_key?("error")) stat[4] += 1 else stat = updatert stat,rt end val["metrics"] = stat @db[path] = val updatedboperations rt, pl["operation"], pl["error"] end #Apmagent::ApmLogger.instance.info "updatedb : end" end |
#updatedbinstance ⇒ Object
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/agent/metrics/am_metricsformatter.rb', line 135 def updatedbinstance cnt = 0; rt = 0; min = -1; max = 0; error_count = 0; if(@db.length>0) @db.each do |key,val| value = val["metrics"] rt = rt + value[0] if min == -1 min = value[1] max = value[2] end if(value[1]<min) min = value[1] end if (value[2]>max) max = value[2] end cnt = cnt + value[3] error_count += value[4] end @dbinstance[":apdex"]=[rt.round(2),min,max,cnt,error_count] end end |
#updatedboperations(rt, operation, isError) ⇒ Object
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 |
# File 'lib/agent/metrics/am_metricsformatter.rb', line 297 def updatedboperations rt, operation, isError if(@dboperations.has_key?(operation)) opstats = @dboperations[operation] else opstats = Array.new; opstats = [0.0,rt,rt,0,0] end if (isError) opstats[4] += 1 else opstats[0] = opstats[0] + rt if(rt<opstats[1]) opstats[1] = rt end if (rt>opstats[2]) opstats[2] = rt end opstats[3] = opstats[3] +1 end @dboperations[operation]=opstats end |
#updateinstance ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/agent/metrics/am_metricsformatter.rb', line 97 def updateinstance ins_apdx = [0,-1,-1,0,0,0,0,0,0] logmetric = Hash.new @transaction.each do |key,value| apdexValue = value[0] ins_apdx[0] += apdexValue[0] if ins_apdx[1] == -1 ins_apdx[1] = apdexValue[1] ins_apdx[2] = apdexValue[2] else if(apdexValue[1]<ins_apdx[1]) ins_apdx[1] = apdexValue[1] end if (apdexValue[2]>ins_apdx[2]) ins_apdx[2] = apdexValue[2] end end ins_apdx[3] += apdexValue[3] ins_apdx[5] += apdexValue[5] ins_apdx[6] += apdexValue[6] ins_apdx[7] += apdexValue[7] ins_apdx[8] += apdexValue[8] exceptions = value[1][@obj.constants.mf_logmetric] if (exceptions != nil) exceptions.each do |name, count| logmetric[name] = logmetric[name].to_i + count end end end if (ins_apdx[3] > 0) ins_apdx[4] = (ins_apdx[5].to_f + (ins_apdx[6]/2).to_f).to_f/ins_apdx[3].to_f ins_apdx[0] = ins_apdx[0].round(2) end @instance[":apdex"]=[ins_apdx, {@obj.constants.mf_logmetric=>logmetric}] end |
#updatert(apx_stat, rt) ⇒ Object
Updates resp time, min rt and max rt in apdex metric
250 251 252 253 254 255 256 257 258 259 260 261 262 |
# File 'lib/agent/metrics/am_metricsformatter.rb', line 250 def updatert apx_stat,rt # Apmagent::ApmLogger.instance.info "updatert : start" apx_stat[3] = apx_stat[3] + 1 apx_stat[0] = apx_stat[0] + rt if(apx_stat[1] == 0 || rt < apx_stat[1]) apx_stat[1] = rt end if(rt > apx_stat[2]) apx_stat[2] = rt end #Apmagent::ApmLogger.instance.info "updatert : end" apx_stat end |
#updatetransaction(d) ⇒ Object
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 219 220 221 222 223 224 225 226 227 |
# File 'lib/agent/metrics/am_metricsformatter.rb', line 162 def updatetransaction d begin pl = d["td"] dbl = d["db"] exc = d["exception"] rt = pl["rt"].round(2) path = @obj.constants.mf_transaction + @obj.constants.mf_separator + pl["path"] apx_stat = nil additionalInfo = nil if(@transaction.has_key?(path)) apx_stat = @transaction[path][0] additionalInfo = @transaction[path][1] else if @transaction.length == @obj.config.metric_overflow_t @obj.log.debug "Metricstore overflow. Current Size: #{@obj.config.metric_overflow_t} #{path}" return end apx_stat = Array.new apx_stat = [0,0,0,0,0,0,0,0,0] additionalInfo = Hash.new end if (pl.has_key?("error")) apx_stat[8] += 1 else apx_stat = apxarray apx_stat,rt end if (exc != nil) logmetric = additionalInfo[@obj.constants.mf_logmetric] if (logmetric == nil) additionalInfo[@obj.constants.mf_logmetric] = exc else exc.each do |name, count| logmetric[name] = logmetric[name].to_i + count end end end @transaction[path] = [apx_stat, additionalInfo] if(dbl!=nil) if @db.length < @obj.config.dbmetric_overflow_t updatedb dbl,path elsif @db.length == @obj.config.dbmetric_overflow_t @obj.log.debug "DB metric overflow. Current Size: #{@obj.config.dbmetric_overflow_t} #{path}" #@obj.log.info "data = #{@db}" of = Hash.new stats = Array.new stats = [0,0,0,0,0] of["tpath"] = @obj.constants.mf_overflow #of["tpath"] = @obj.constants.mf_transaction + @obj.constants.mf_separator + @obj.constants.mf_overflow #using this for testing purpose of["path"] = @obj.constants.mf_db + @obj.constants.mf_separator + @obj.constants.mf_overflow + @obj.constants.mf_separator + "-" + @obj.constants.mf_separator of["metrics"] = stats @db[@obj.constants.mf_overflow]=of #@obj.log.info "data updated = #{@db}" end end rescue Exception=>e @obj.log.info "#{e.}" @obj.log.logException "[Format] [ updatetransaction ] #{e.}",e end # Apmagent::ApmLogger.instance.info "update transaction end" end |