Class: MiqVimPerfHistory

Inherits:
Object
  • Object
show all
Includes:
DRb::DRbUndumped, MiqBrokerObjRegistry, MiqBrokerVimConnectionCheck
Defined in:
lib/VMwareWebService/MiqVimBrokerMods.rb,
lib/VMwareWebService/MiqVimPerfHistory.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from MiqBrokerVimConnectionCheck

#connectionRemoved?

Methods included from MiqBrokerObjRegistry

#holdBrokerObj, #registerBrokerObj, #unregisterBrokerObj

Constructor Details

#initialize(invObj) ⇒ MiqVimPerfHistory

Returns a new instance of MiqVimPerfHistory.



6
7
8
9
10
# File 'lib/VMwareWebService/MiqVimPerfHistory.rb', line 6

def initialize(invObj)
  @invObj     = invObj
  @sic      = invObj.sic
  @perfManager  = @sic.perfManager
end

Instance Attribute Details

#invObjObject (readonly)

Returns the value of attribute invObj.



4
5
6
# File 'lib/VMwareWebService/MiqVimPerfHistory.rb', line 4

def invObj
  @invObj
end

Instance Method Details

#availMetricsForEntity(mor, *aa) ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/VMwareWebService/MiqVimPerfHistory.rb', line 104

def availMetricsForEntity(mor, *aa)
  if aa.length > 0
    ah = aa[0]
    intervalId = ah[:intervalId] || nil
    beginTime  = ah[:beginTime] || nil
    endTime    = ah[:endTime] || nil
  end
  $vim_log.info "MiqVimPerfHistory(#{@invObj.server}, #{@invObj.username}).availMetricsForEntity: calling queryAvailablePerfMetric" if $vim_log
  pmids = @invObj.queryAvailablePerfMetric(@perfManager, mor, beginTime, endTime, intervalId)
  $vim_log.info "MiqVimPerfHistory(#{@invObj.server}, #{@invObj.username}).availMetricsForEntity: returned from queryAvailablePerfMetric" if $vim_log
  (pmids)
end

#cInfoMapObject



70
71
72
73
# File 'lib/VMwareWebService/MiqVimPerfHistory.rb', line 70

def cInfoMap
  perfCounterInfo if @cInfoMap.nil?
  @cInfoMap
end

#getCounterInfo(group, name, rollupType, statsType = nil) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
# File 'lib/VMwareWebService/MiqVimPerfHistory.rb', line 85

def getCounterInfo(group, name, rollupType, statsType = nil)
  raise "getCounterInfo: counter group #{group}, not found" unless (nh = cInfoMap[group])
  raise "getCounterInfo: counter #{group}.#{name}, not found" unless (ca = nh[name])

  ca.each do |ci|
    next if ci['rollupType'] != rollupType
    next if statsType && ci['statsType'] != statsType
    return ci
  end
  raise "getCounterInfo: counter #{group}.#{name}, no counter matching rollupType and statsType"
end

#groupInfoObject



80
81
82
83
# File 'lib/VMwareWebService/MiqVimPerfHistory.rb', line 80

def groupInfo
  perfCounterInfo if @groupInfo.nil?
  @groupInfo
end

#id2CounterObject



75
76
77
78
# File 'lib/VMwareWebService/MiqVimPerfHistory.rb', line 75

def id2Counter
  perfCounterInfo if @id2Counter.nil?
  @id2Counter
end

#intervalMapObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/VMwareWebService/MiqVimPerfHistory.rb', line 24

def intervalMap
  if @intervalMap.nil?
    # Hash interval information by [name] and interval ID (samplingPeriod)
    @intervalMap = {}
    intervals.each do |i|
      @intervalMap[i['name']] = i
      # i['samplingPeriod'] = i['samplingPeriod'].to_i
      i['length'] = i['length'].to_i
      @intervalMap[i['samplingPeriod']] = i
      @intervalMap[i['samplingPeriod'].to_i] = i
    end
  end
  @intervalMap
end

#intervalsObject

Interval processing



16
17
18
19
20
21
22
# File 'lib/VMwareWebService/MiqVimPerfHistory.rb', line 16

def intervals
  if @intervals.nil?
    @intervals = @invObj.getMoProp(@perfManager, "historicalInterval")["historicalInterval"]
    @intervals = @intervals["PerfInterval"] if @intervals.kind_of?(Hash)
  end
  @intervals
end

#perfCounterInfoObject

Counter processing



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
# File 'lib/VMwareWebService/MiqVimPerfHistory.rb', line 43

def perfCounterInfo
  if @perfCounterInfo.nil?
    @perfCounterInfo = @invObj.getMoProp(@perfManager, "perfCounter")['perfCounter']
    @perfCounterInfo = @perfCounterInfo['PerfCounterInfo'] if @perfCounterInfo.kind_of?(Hash)

    #
    # Hash counter information by [group][name] and [counter ID].
    # Also, hash counter group info by group key.
    #
    @cInfoMap   = {}  # Counter info hashed by [group][name]
    @id2Counter = {}  # Counter info hashed by [id]
    @groupInfo  = {}  # Description of counter groups, hashed by group key
    @perfCounterInfo.each do |pci|
      # pci['key'] = pci['key'].to_i
      @id2Counter[pci['key']] = pci
      ginfo = pci['groupInfo']
      @groupInfo[ginfo['key']] = ginfo
      group = ginfo['key']
      @cInfoMap[group] = {} unless @cInfoMap[group]
      name = pci['nameInfo']['key']
      @cInfoMap[group][name] = [] unless @cInfoMap[group][name]
      @cInfoMap[group][name] << pci
    end if @perfCounterInfo
  end
  @perfCounterInfo
end

#queryPerf(entnty, ah) ⇒ Object

Query an single metric from a single entity.



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/VMwareWebService/MiqVimPerfHistory.rb', line 120

def queryPerf(entnty, ah)
  ah[:entity]     = entnty
  pqs             = getPerfQuerySpec(ah)

  $vim_log.info "MiqVimPerfHistory(#{@invObj.server}, #{@invObj.username}).queryPerf: calling queryPerf" if $vim_log
  umPem = @invObj.queryPerf(@perfManager, pqs)[0]
  $vim_log.info "MiqVimPerfHistory(#{@invObj.server}, #{@invObj.username}).queryPerf: returned from queryPerf" if $vim_log

  #
  # Construct an array of (timestamp, value) pairs.
  #
  ra = []
  return(ra) if !umPem || !umPem.xsiType
  return(ra) unless umPem.key?('value')
  return(ra) if umPem['value'].kind_of?(Hash) && !umPem['value'].key?('value')
  return(ra) unless umPem.key?('sampleInfo')

  va = umPem['value']
  va = va[0] if va.kind_of?(Array)
  va = va['value']
  umPem['sampleInfo'] = [umPem['sampleInfo']] unless umPem['sampleInfo'].kind_of?(Array)
  umPem['sampleInfo'].each_index do |i|
    si = umPem['sampleInfo'][i]
    ra << DateTime.parse(si['timestamp'])
    ra << va[i].to_i
  end
  (ra)
end

#queryPerfComposite(entnty, ah) ⇒ Object



164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/VMwareWebService/MiqVimPerfHistory.rb', line 164

def queryPerfComposite(entnty, ah)
  ah[:entity]     = entnty
  pqs             = getPerfQuerySpec(ah)

  $vim_log.info "MiqVimPerfHistory(#{@invObj.server}, #{@invObj.username}).queryPerfComposite: calling queryPerfComposite" if $vim_log
  umPem = @invObj.queryPerfComposite(@perfManager, pqs)
  $vim_log.info "MiqVimPerfHistory(#{@invObj.server}, #{@invObj.username}).queryPerfComposite: returned from queryPerfComposite" if $vim_log

  umPem['childEntity'] = [umPem['childEntity']] if umPem['childEntity'].kind_of? Hash

  (umPem)
end

#queryPerfMulti(aa) ⇒ Object



149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/VMwareWebService/MiqVimPerfHistory.rb', line 149

def queryPerfMulti(aa)
  querySpec = VimArray.new('ArrayOfPerfQuerySpec') do |pqsa|
    aa.each { |ah| pqsa << getPerfQuerySpec(ah) }
  end

  $vim_log.info "MiqVimPerfHistory(#{@invObj.server}, #{@invObj.username}).queryPerfMulti: calling queryPerf" if $vim_log
  pema = @invObj.queryPerf(@perfManager, querySpec)
  $vim_log.info "MiqVimPerfHistory(#{@invObj.server}, #{@invObj.username}).queryPerfMulti: returned from queryPerf" if $vim_log

  return(nil) unless pema

  pema = [pema] unless pema.kind_of? Array
  pema
end

#queryProviderSummary(mor) ⇒ Object



97
98
99
100
101
102
# File 'lib/VMwareWebService/MiqVimPerfHistory.rb', line 97

def queryProviderSummary(mor)
  $vim_log.info "MiqVimPerfHistory(#{@invObj.server}, #{@invObj.username}).queryProviderSummary: calling queryPerfProviderSummary" if $vim_log
  psum = @invObj.queryPerfProviderSummary(@perfManager, mor)
  $vim_log.info "MiqVimPerfHistory(#{@invObj.server}, #{@invObj.username}).queryProviderSummary: returned from queryPerfProviderSummary" if $vim_log
  (psum)
end

#releaseObject



177
178
179
# File 'lib/VMwareWebService/MiqVimPerfHistory.rb', line 177

def release
  # @invObj.releaseObj(self)
end

#release_origObject



130
# File 'lib/VMwareWebService/MiqVimBrokerMods.rb', line 130

alias_method :release_orig, :release