pyvmomi Get RAM/CPU Usage VSphere SDK 5.5?

。_饼干妹妹 提交于 2019-12-24 03:43:10

问题


I am trying to get some information from a few ESXi Servers through Python. I found pyvmomi(https://github.com/vmware/pyvmomi) which is a great and easy to understand tool for this purpose. However, I cannot seem to find a way to get "real-time" info on the CPU/RAM/Storage usage. I am going through the SDK of VMware (http://pubs.vmware.com/vsphere-55/topic/com.vmware.sdk.doc/GUID-19793BCA-9EAB-42E2-8B9F-F9F2129E7741.html) but I can only find how many cpus or how much memory the host has.

Has anyone ever done this through Python?


回答1:


Check the pyvmomi-community-samples. There's a python script in there called esxi_perf_sample.py with an example on how to retrieve a specific metric in a specified period of time.

Along with that example, check this implementation.

The trick here resides on the counterId mapping into human-readable names of the available metrics that are currently implemented on the target machine. You should first retrieve the available counters before you attempt to retrieve their values.

In my opinion, the implementation of the second link of this post is one of the best public examples that you'll find based on pyVmomi at the time of this writing. Take a careful look into it as it will probably answer all your doubts for itself.

Also note that although the Geeklee vminfo implementation is Guest oriented, all the metrics are still valid for the Host. You just need to adapt the script to specify the Host entity instead of the Guest (or allow both) when you perform the query.

Finally, the "real-time" granularity for the retrieved metrics can be specified by a time interval when performing the query call. You should specify an interval based on your needs, but note that for the latest vSphere versions, the minimum (default) interval between samples is 20 seconds, so you should not specify a time interval lesser than this value.




回答2:


I have added script to extract cpu usage of esxhosts with multithreading. You can find it on my github https://github.com/dograga/ESXPerfData



来源:https://stackoverflow.com/questions/28502855/pyvmomi-get-ram-cpu-usage-vsphere-sdk-5-5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!