Last active
September 28, 2022 15:26
-
-
Save noonedeadpunk/0f76de1ff8a29545bd8d299bbba15ecc to your computer and use it in GitHub Desktop.
Get data about current overcommit per hypervisor from OpenStack
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
import os | |
from openstack import connect | |
from pprint import pprint | |
def main(): | |
conn = connect() | |
allocation_ratios = { | |
hv.name: { | |
"CPU": round(hv.vcpus_used / hv.vcpus, 2), | |
"RAM": round(hv.memory_used / hv.memory_size, 2) | |
} | |
for hv in conn.compute.hypervisors(details=True) | |
} | |
pprint(allocation_ratios) | |
if __name__ == "__main__": | |
os.environ['OS_COMPUTE_DEFAULT_MICROVERSION'] = '2.86' | |
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
from openstack import connect | |
from pprint import pprint | |
from joblib import Parallel, delayed | |
def fetch_ratios(conn, provider, allocation_ratios): | |
inv = conn.placement.get(f"/resource_providers/{provider.id}/inventories").json()['inventories'] | |
usage = conn.placement.get(f"/resource_providers/{provider.id}/usages").json()['usages'] | |
allocation_ratios.update({provider.name: { | |
"CPU": round((usage['VCPU'] - inv['VCPU']['reserved']) / inv['VCPU']['total'], 2), | |
"RAM": round((usage['MEMORY_MB'] - inv['MEMORY_MB']['reserved']) / inv['MEMORY_MB']['total'], 2) | |
}}) | |
def main(): | |
conn = connect() | |
allocation_ratios = {} | |
providers = conn.placement.resource_providers() | |
Parallel(n_jobs=5, prefer="threads")( | |
delayed(fetch_ratios)(conn, provider, allocation_ratios) | |
for provider in providers) | |
pprint(allocation_ratios) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment