Advertisement
Guest User

Untitled

a guest
Feb 5th, 2017
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.77 KB | None | 0 0
  1. vim = RbVmomi::VIM.connect host: vcenter.hostname, user: vcenter.username, password: vcenter.password, insecure: true
  2. pm = vim.serviceInstance.content.perfManager
  3.  
  4. # this is for a single cluster with hosts directly in one cluster. 'first' returns the cluster object.
  5. hosts = vim.serviceInstance.find_datacenter.hostFolder.children.first.host
  6.  
  7. pm.retrieve_stats([hosts[0]], ['cpu.usagemhz'], {interval: '300', start_time: (Time.now - 6.hours)}).first[1][:metrics]['cpu.usagemhz']
  8. # This above query queries for the 'cpu.usagemhz' counter, which by default matches the (none) rollup counter (NOT THE AVERAGE) in vSphere API.
  9. # This is a problem with the RbVmomi gem helper function "retrieve_stats" only. To override this, use the following manual counter selection:
  10.  
  11. pqs = RbVmomi::VIM::PerfQuerySpec(maxSample: 1, entity: hosts[0], metricId: [{counterId: 6, instance: '*'}], intervalId: '300', startTime: (Time.now-1.hour).to_datetime, endTime: Time.now.to_datetime)
  12. # => #<RbVmomi::VIM::PerfQuerySpec:0x00000004f24e38 @props={:maxSample=>1, :entity=>HostSystem("host-13"), :metricId=>[{:counterId=>6, :instance=>"*"}], :intervalId=>"300", :startTime=>Thu, 01 Aug 2013 22:00:27 +0000, :endTime=>Thu, 01 Aug 2013 23:00:27 +0000}>
  13. pm.QueryPerf({querySpec: [pqs]})
  14. # => [#<RbVmomi::VIM::PerfEntityMetric:0x00000004c01a58 @props={:dynamicProperty=>[], :sampleInfo=>[#<RbVmomi::VIM::PerfSampleInfo:0x0000000404a188 @props={:dynamicProperty=>[], :timestamp=>2013-08-01 22:05:00 UTC, :interval=>300}>, #<RbVmomi::VIM::PerfSampleInfo:0x00000004051190 @props={:dynamicProperty=>[], :timestamp=>2013-08-01 22:10:00 UTC, :interval=>300}>, #<RbVmomi::VIM::PerfSampleInfo:0x00000004057928 @props={:dynamicProperty=>[], :timestamp=>2013-08-01 22:15:00 UTC, :interval=>300}>, #<RbVmomi::VIM::PerfSampleInfo:0x000000040549d0 @props={:dynamicProperty=>[], :timestamp=>2013-08-01 22:20:00 UTC, :interval=>300}>, #<RbVmomi::VIM::PerfSampleInfo:0x0000000405c4c8 @props={:dynamicProperty=>[], :timestamp=>2013-08-01 22:25:00 UTC, :interval=>300}>, #<RbVmomi::VIM::PerfSampleInfo:0x000000040629e0 @props={:dynamicProperty=>[], :timestamp=>2013-08-01 22:30:00 UTC, :interval=>300}>, #<RbVmomi::VIM::PerfSampleInfo:0x00000004bec0b8 @props={:dynamicProperty=>[], :timestamp=>2013-08-01 22:35:00 UTC, :interval=>300}>, #<RbVmomi::VIM::PerfSampleInfo:0x00000004be91d8 @props={:dynamicProperty=>[], :timestamp=>2013-08-01 22:40:00 UTC, :interval=>300}>, #<RbVmomi::VIM::PerfSampleInfo:0x00000004bee598 @props={:dynamicProperty=>[], :timestamp=>2013-08-01 22:45:00 UTC, :interval=>300}>, #<RbVmomi::VIM::PerfSampleInfo:0x00000004bf5780 @props={:dynamicProperty=>[], :timestamp=>2013-08-01 22:50:00 UTC, :interval=>300}>, #<RbVmomi::VIM::PerfSampleInfo:0x00000004bfc5a8 @props={:dynamicProperty=>[], :timestamp=>2013-08-01 22:55:00 UTC, :interval=>300}>], :value=>[#<RbVmomi::VIM::PerfMetricIntSeries:0x00000004c02020 @props={:dynamicProperty=>[], :value=>[1064, 1026, 1001, 1124, 1061, 1072, 1068, 1065, 1069, 1081, 0], :id=>#<RbVmomi::VIM::PerfMetricId:0x00000004bfafc8 @props={:dynamicProperty=>[], :counterId=>6, :instance=>""}>}>], :entity=>HostSystem("host-13")}>]
  15.  
  16. # I will work this into a gem pull request in the coming weeks
  17.  
  18. # => [1721, 1797, 2041, 2983, 1807, 1814, 1870, 1816, 1799, 1882, 1963, 1886, 1770, 1753, 3673, 3459,
  19. # 1828, 1812, 1807, 1869, 2026, 1888, 2085, 1809, 1826, 1785, 2330, 3315, 1776, 1861, 1807, 1842,
  20. # 1797, 1858, 1836, 1922, 1782, 1843, 3906, 3413, 1867, 2273, 1961, 1736, 1833, 1813, 1846, 2063,
  21. # 1852, 1854, 2208, 3276, 1933, 1776, 2544, 1751, 1815, 1830, 1740, 1764, 1703, 1766, 3661, 2981,
  22. # 1769, 1890, 2273, 1764, 1747, 1827, 0]
  23.  
  24. # Notes:
  25. # - that that last result is always 0 in this vcenter I've seen
  26. # - sometimes the entire metrics is {} when statistics are not being saved in the vCenter performance database properly
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement