VMware ESX performance collection with govmomi

blov · · 403 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>Hi all,</p> <p>I&#39;m trying to figure out how to get performance information about ESX hosts using <a href="https://github.com/vmware/govmomi">govmomi</a>. I feel like I&#39;m super close, but I can&#39;t quite understand how to get from where I&#39;m at to where I want to be. It&#39;s the first time I&#39;ve tried to do anything mildly interesting with Go.</p> <p>I have managed to get a response back from the API that I presume includes performance information. I created a query and invoked <a href="https://github.com/vmware/govmomi/blob/master/vim25/methods/methods.go#L8253"><code>methods.QueryPerf</code></a>, which returns a <a href="https://raw.githubusercontent.com/vmware/govmomi/master/vim25/types/types.go"><code>types.QueryPerfResponse</code></a>. <code>QueryPerfResponse</code> has a <code>Returnval</code> of type <a href="https://github.com/vmware/govmomi/blob/master/vim25/types/if.go#L2075"><code>[]types.BasePerfEntityMetricBase</code></a>.</p> <p>When I print out the type of <code>Returnval[0]</code> using <code>%T</code>, I see that it&#39;s <code>*types.PerfEntityMetric</code>. I can see that it has exactly what I want to access (<code>SampleInfo</code> and <code>Value</code>) when I print it with <code>%+v</code>. But presumably because of the <code>[]BasePerfEntityMetricBase</code> type for <code>Returnval</code>, <code>go build</code> barks about <code>BasePerfEntityMetricBase</code> not having those properties that are of interest.</p> <p>Anyone have any pointers for how I can convince <code>go build</code> that <code>Returnval[0]</code> is a <code>types.PerfEntityMetric</code>?</p> <p>I&#39;ve tried things like <code>types.PerfEntityMetric(res.Returnval[0])</code> and <code>res.Returnval[0].(types.PerfEntityMetric)</code>, but they don&#39;t work. I&#39;m guessing that will be obvious to more experienced Go developers, but I can add error messages for those attempts if it will help.</p> <p>I will work on cleaning up the code to be less derpy, and I&#39;ll post a gist when it&#39;s ready.</p> <p>Thanks!</p> <p>Edit: The gist, as promised: <a href="https://gist.github.com/codekoala/1a10ed7071a8e50dfcc0">https://gist.github.com/codekoala/1a10ed7071a8e50dfcc0</a></p> <hr/>**评论:**<br/><br/>codekoala: <pre><p>I was hoping it would be as easy as something like casting, but I must be doing all the wrong things. I have very similar code working with pyvmomi, but no casting is required. I can simply dig into the various objects without fuss.</p> <p>I&#39;m mobile with a toddler rolling around on me, and what follows comes from memory. Please forgive mistakes. The Returnval array is an array of an interface. PerfEntityMetric does not directly implement the interface, but PerfEntityMetricBase does. PerfEntityMetric has an anonymous PerfEntityMetricBase field. I can use the GetPerfEntityMetricBase function on one of the Returnval items, but I don&#39;t know how to access the fields of interest in PerfEntityMetric from that point.</p> <p>Very vexing.</p></pre>
403 次点击  
加入收藏 微博
0 回复
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传