Class: ManageEngine::APMMetricsFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/agent/metrics/am_metricsformatter.rb

Instance Method Summary collapse

Instance Method Details

#apxarray(apx_stat, rt) ⇒ Object



184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# File 'lib/agent/metrics/am_metricsformatter.rb', line 184

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    

  apx_stat[4] = (apx_stat[5].to_f + (apx_stat[6].to_f/2).to_f)/apx_stat[3].to_f
  #  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] DBtrans Vs #[rspTime,min rt,max rt,cnt] 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.message}",e
  end
  @transaction.clear
  @db.clear
  @instance.clear
  result
end

#intializeObject



5
6
7
8
# File 'lib/agent/metrics/am_metricsformatter.rb', line 5

def intialize
  @obj = ManageEngine::APMObjectHolder.instance
  @apdex_threshold = 0
end

#keysToRemoveObject



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]



215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
# File 'lib/agent/metrics/am_metricsformatter.rb', line 215

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
      stat = Array.new
      stat = [rt,rt,rt,0]
    end
    stat = updatert stat,rt
    val["tpath"] = tpath
    val["path"] = dpath
    val["metrics"] = stat
    @db[path] = val
    updatedboperations rt, pl["operation"]
  end
  #Apmagent::ApmLogger.instance.info "updatedb : end"
end

#updatedbinstanceObject



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/agent/metrics/am_metricsformatter.rb', line 128

def updatedbinstance
  cnt = 0;
  rt = 0;
  min = -1;
  max = 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]
    end
    @dbinstance[":apdex"]=[rt.round(2),min,max,cnt]
  end
end

#updatedboperations(rt, operation) ⇒ Object



243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
# File 'lib/agent/metrics/am_metricsformatter.rb', line 243

def updatedboperations rt,operation
  opstats = Array.new;
  #puts "#{operation} "
  if(@dboperations.has_key?(operation))
    opstats = @dboperations[operation]
  else
    opstats = [0.0,rt,rt,0]
  end
  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
  @dboperations[operation]=opstats
end

#updateinstanceObject



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
# File 'lib/agent/metrics/am_metricsformatter.rb', line 97

def updateinstance
  ins_apdx = Array.new
  cnt = 0;
  rt = 0;
  s=0;
  t=0;
  f=0;
  min = -1;
  max = 0;
  @transaction.each do |key,value|
    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]

    s = s + value[5]  
    t = t + value[6]  
    f = f + value[7]  
  end
  apx = (s.to_f + (t/2).to_f).to_f/cnt.to_f
  @instance[":apdex"]=[rt.round(2),min,max,cnt,apx,s,t,f]
end

#updatert(apx_stat, rt) ⇒ Object



201
202
203
204
205
206
207
208
209
210
211
212
213
# File 'lib/agent/metrics/am_metricsformatter.rb', line 201

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(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



153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/agent/metrics/am_metricsformatter.rb', line 153

def updatetransaction d
  begin
    pl = d["td"]
    dbl = d["db"]

    rt = pl["rt"].round(2)
    path = pl["path"]
    name = pl["name"]

    path = @obj.constants.mf_transaction + @obj.constants.mf_separator + path + " " +name


    apx_stat =  nil
    if(@transaction.has_key?(path))
      apx_stat = @transaction[path]
    else
      apx_stat = Array.new
      apx_stat = [0,rt,rt,0,0,0,0,0]
    end
    apx_stat = apxarray apx_stat,rt
    @transaction[path] = apx_stat
    if(dbl!=nil)
      updatedb dbl,path
    end
  rescue Exception=>e
    @obj.log.info "#{e.message}"
    @obj.log.logException "[Format] [ updatetransaction ] #{e.message}",e
  end
  #  Apmagent::ApmLogger.instance.info "update transaction end"
end