Get full resource usage VMWare VCloud API

662 views Asked by At

We are using a VDC that allows us to over-commit CPU resources and we would like to monitor how much we are using (the information is not provided to us). They have given us access to the VMWare VCloud API and I am using the python script here along with the following code to get the CPU usage (in mHz) of all the VMs:

new_vcloud_login("USERNAME", "PASSWORD")

# demo query, get all VMs and print them to screen
vms = get_vcloud_request("query?type=vm&fields=name&pageSize=1000").decode('utf-8')
vm_ids = re.findall('"https://mycloud.syd.zettagrid.com/api/vApp/(vm-.*?)"', vms)

total = 0

xml = """<?xml version="1.0" encoding="UTF-8"?>
<CurrentUsageSpec xmlns="http://www.vmware.com/vcloud/v1.5">
   <MetricPattern>cpu.usagemhz.average</MetricPattern>
</CurrentUsageSpec>"""

for id in vm_ids:
    metric_data = get_vcloud_request("vApp/" + id + "/metrics/current", xml).decode('utf-8')
    cpu = re.findall('.*"cpu.usagemhz.average".*value="(.*?)".*', metric_data)

    total += float(cpu[0])

print(total)

The issue with this is that it's very slow and quickly eats away at the API limits because it's having to send a request for each VM. Is there an VMWare VCloud API function that would provide this information in a single request? I tried using this all the CPU related data was 0.

Any help would be much appreciated thanks!

1

There are 1 answers

3
Emin4ik On

Maybe you don`t need to gather all used CPU from every VM, just get CPU from organization VDC ? I think this cant help you:

   GET /vdc/{id}

Get VDC Information