pyvmomi Get RAM/CPU Usage VSphere SDK 5.5?

Question:

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?

Asked By: Benjamin Vison

||

Answers:

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.

Answered By: pah

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

Answered By: Gaurav
Categories: questions Tags: , , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.