vmware / vsphere-automation-sdk-python

Python samples, language bindings, and API reference documentation for vSphere, VMC, and NSX-T using the VMware REST API
MIT License
745 stars 313 forks source link

How to Get VM current CPU and Memory Usage by Python SDK #416

Closed x-zhao-res closed 6 months ago

x-zhao-res commented 6 months ago

Is your feature request related to a problem? Please describe.

Vision vCenter: 7.0.3 Hi,I want get vm CPU current usage but i use this code:

vsphere_client = create_vsphere_client(server='192.168.75.82', username='username', password='password')

vmName = ''
# List all VMs inside the vCenter Server
vmList = vsphere_client.vcenter.VM.list()
for item in vmList:
    print(item)
    vmName = item.vm
instanceVM = vsphere_client.vcenter.VM.get(vmName)

only get _[cpu : {count : 1, cores_per_socket : 1, hot_add_enabled : False, hot_removeenabled : False}]

By the way, i search maybe it use CID like this 'cpu.usage.PCPU' but i don`t know how to use it.....

Describe the solution you'd like

i want get VM current usage CPU,Memory,Disk like this ↓

2762882f19991c1380c90f83608e3380

Describe alternatives you've considered

No response

Additional context

No response

jobingeo commented 6 months ago

You can try pyVmomi SDK to obtain VM CPU and Memory. Checkout this example https://github.com/vmware/pyvmomi-community-samples/blob/master/samples/vm_perf_example.py