class MiqVimPerfHistory
Attributes
invObj[R]
Public Class Methods
new(invObj)
click to toggle source
# File lib/VMwareWebService/MiqVimPerfHistory.rb, line 9 def initialize(invObj) @invObj = invObj @sic = invObj.sic @perfManager = @sic.perfManager end
Public Instance Methods
availMetricsForEntity(mor, *aa)
click to toggle source
# File lib/VMwareWebService/MiqVimPerfHistory.rb, line 107 def availMetricsForEntity(mor, *aa) if aa.length > 0 ah = aa[0] intervalId = ah[:intervalId] || nil beginTime = ah[:beginTime] || nil endTime = ah[:endTime] || nil end logger.info "MiqVimPerfHistory(#{@invObj.server}, #{@invObj.username}).availMetricsForEntity: calling queryAvailablePerfMetric" pmids = @invObj.queryAvailablePerfMetric(@perfManager, mor, beginTime, endTime, intervalId) logger.info "MiqVimPerfHistory(#{@invObj.server}, #{@invObj.username}).availMetricsForEntity: returned from queryAvailablePerfMetric" (pmids) end
cInfoMap()
click to toggle source
# File lib/VMwareWebService/MiqVimPerfHistory.rb, line 73 def cInfoMap perfCounterInfo if @cInfoMap.nil? @cInfoMap end
getCounterInfo(group, name, rollupType, statsType = nil)
click to toggle source
# File lib/VMwareWebService/MiqVimPerfHistory.rb, line 88 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
groupInfo()
click to toggle source
# File lib/VMwareWebService/MiqVimPerfHistory.rb, line 83 def groupInfo perfCounterInfo if @groupInfo.nil? @groupInfo end
id2Counter()
click to toggle source
# File lib/VMwareWebService/MiqVimPerfHistory.rb, line 78 def id2Counter perfCounterInfo if @id2Counter.nil? @id2Counter end
intervalMap()
click to toggle source
# File lib/VMwareWebService/MiqVimPerfHistory.rb, line 27 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
intervals()
click to toggle source
Interval processing
# File lib/VMwareWebService/MiqVimPerfHistory.rb, line 19 def intervals if @intervals.nil? @intervals = @invObj.getMoProp(@perfManager, "historicalInterval")["historicalInterval"] @intervals = @intervals["PerfInterval"] if @intervals.kind_of?(Hash) end @intervals end
perfCounterInfo()
click to toggle source
Counter processing
# File lib/VMwareWebService/MiqVimPerfHistory.rb, line 46 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)
click to toggle source
Query an single metric from a single entity.
# File lib/VMwareWebService/MiqVimPerfHistory.rb, line 123 def queryPerf(entnty, ah) ah[:entity] = entnty pqs = getPerfQuerySpec(ah) logger.info "MiqVimPerfHistory(#{@invObj.server}, #{@invObj.username}).queryPerf: calling queryPerf" umPem = @invObj.queryPerf(@perfManager, pqs)[0] logger.info "MiqVimPerfHistory(#{@invObj.server}, #{@invObj.username}).queryPerf: returned from queryPerf" # # 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)
click to toggle source
# File lib/VMwareWebService/MiqVimPerfHistory.rb, line 167 def queryPerfComposite(entnty, ah) ah[:entity] = entnty pqs = getPerfQuerySpec(ah) logger.info "MiqVimPerfHistory(#{@invObj.server}, #{@invObj.username}).queryPerfComposite: calling queryPerfComposite" umPem = @invObj.queryPerfComposite(@perfManager, pqs) logger.info "MiqVimPerfHistory(#{@invObj.server}, #{@invObj.username}).queryPerfComposite: returned from queryPerfComposite" umPem['childEntity'] = [umPem['childEntity']] if umPem['childEntity'].kind_of? Hash (umPem) end
queryPerfMulti(aa)
click to toggle source
# File lib/VMwareWebService/MiqVimPerfHistory.rb, line 152 def queryPerfMulti(aa) querySpec = VimArray.new('ArrayOfPerfQuerySpec') do |pqsa| aa.each { |ah| pqsa << getPerfQuerySpec(ah) } end logger.info "MiqVimPerfHistory(#{@invObj.server}, #{@invObj.username}).queryPerfMulti: calling queryPerf" pema = @invObj.queryPerf(@perfManager, querySpec) logger.info "MiqVimPerfHistory(#{@invObj.server}, #{@invObj.username}).queryPerfMulti: returned from queryPerf" return(nil) unless pema pema = [pema] unless pema.kind_of? Array pema end
queryProviderSummary(mor)
click to toggle source
# File lib/VMwareWebService/MiqVimPerfHistory.rb, line 100 def queryProviderSummary(mor) logger.info "MiqVimPerfHistory(#{@invObj.server}, #{@invObj.username}).queryProviderSummary: calling queryPerfProviderSummary" psum = @invObj.queryPerfProviderSummary(@perfManager, mor) logger.info "MiqVimPerfHistory(#{@invObj.server}, #{@invObj.username}).queryProviderSummary: returned from queryPerfProviderSummary" (psum) end
release()
click to toggle source
# File lib/VMwareWebService/MiqVimPerfHistory.rb, line 180 def release # @invObj.releaseObj(self) end
Private Instance Methods
getPerfQuerySpec(ah)
click to toggle source
# File lib/VMwareWebService/MiqVimPerfHistory.rb, line 186 def getPerfQuerySpec(ah) raise "getPerfQuerySpec: intervalId not specified" unless ah[:intervalId] raise "getPerfQuerySpec: counterId not specified" if !ah[:counterId] && !ah[:metricId] pqSpec = VimHash.new('PerfQuerySpec') do |pqs| pqs.entity = ah[:entity] if ah[:entity] pqs.intervalId = ah[:intervalId] pqs.format = PerfFormat.const_get((ah[:format] || "normal").to_s.capitalize) pqs.endTime = ah[:endTime].to_s if ah[:endTime] pqs.startTime = ah[:startTime].to_s if ah[:startTime] pqs.maxSample = ah[:maxSample] if ah[:maxSample] pqs.metricId = VimArray.new('ArrayOfPerfMetricId') do |pmia| if ah[:counterId] ids = [ah] else ids = ah[:metricId] end ids.each do |midh| pmia << VimHash.new('PerfMetricId') do |pmi| pmi.counterId = midh[:counterId] pmi.instance = midh[:instance] || "" end end end end (pqSpec) end