[OpenStack] Resource statistics implementation

Source: Internet
Author: User

Statement:

This blog is welcome to forward, but please keep the original author information! The content of my study, research and summary, if there is similar, it is honored.

Original address: http://blog.csdn.net/gtt116/article/details/9618403


This article describes how Nova in the OpenStack (Grizzly) version counts the available resources of a host for debug and operational OpenStack.

In OpenStack, there are two layers of management of virtual machines: OpenStack itself and hypervisor (Libvirt). Because different levels can result in data disunity, such as VMs in Libvirt, but not in OpenStack, or vice versa. How to deal with the resource statistics at this time. OpenStack's approach is to count both, but the real thing to consider (write to the database) is the results of OpenStack itself. The next step is to describe in detail how openstack is resource-counted.


OpenStack focuses on the following resources for host: Vcpus vcpus_used memory_mb memory_mb_used local_gb local_gb_used cpu_info disk_available_least FREE_RAM_MB FREE_DISK_GB


This data is periodically updated in the periodic task to the database, which is 60s at a time by default. The next step is to explain how these data are obtained.


The core code in Nova/virt/libvirt/driver.py:libvirtdriver.get_available_resource (), interested students can see their own code,
Here are just a list of how each resource is counted.
Vcpus: Get vcpus_used directly from Libvirt nodeinfo: List all VMS by Libvirt and then traverse the Vcpus memory_mb that overlay all VMS: Get Libvirt directly from NodeInfo memory_ Mb_used: Calculates the information in the/proc/meminfo, calculates the available (Memfree + buffers + cached), then uses the above MEMORY_MB-available, and the rest is used LOCAL_GB: View the size of the instance directory via Python's OS.STATVFG interface local_gb_used: As with LOCAL_GB Cpu_info: Get Libvirt from Disk_available_least: it and Local_ The difference between GB is that LOCAL_GB is the actual size of the mirror, which is the amount remaining after the virtual size is calculated. Therefore must be less than (local_gb-local_gb_used). Free_ram_mb:memory_mb-memory_mb_used free_disk_gb:local_gb-local_gb_used

But, but. Instead of simply putting this data into the database, Nova calculates the Vcpus, memory, and LOCAL_GB in addition.

After getting the basic data above for the first time, Nova will get all the instance from the database theoretically on this host, and then recalculate these resource usage based on instance.


1. First, reset the usage of Vcpus, memory, LOCAL_GB.

vcpus_used = 0
memory_mb_used = conf.reserved_host_memory_mb
local_gb_used = conf.reserved_host_disk_mb/1024
free_ram_mb = memory_mb-memory_mb_used
FREE_DISK_GB = local_gb-local_gb_used

2. Then, find out all the instance that have not been deleted,
Based on the details of each instance calculation vcpus_used,local_gb_used, memory_mb_used, then calculate FREE_RAM_MB, FREE_DISK_GB


So in the log, you can find that there are two formats for reporting resources:
Format 1.
2013-07-29 17:03:25.486 DEBUG Nova.compute.resource_tracker [-] hypervisor:free RAM (MB): 10253 from (pid=17247) _report_ hypervisor_resource_view/opt/stack/nova/nova/compute/resource_tracker.py:331
2013-07-29 17:03:25.487 DEBUG Nova.compute.resource_tracker [-] hypervisor:free disk (GB): From (pid=17247) _report_hypervisor_resource_view/opt/ stack/nova/nova/compute/resource_tracker.py:332
2013-07-29 17:03:25.487 DEBUG Nova.compute.resource_tracker [- ] Hypervisor:free vcpus:4 from (pid=17247) _report_hypervisor_resource_view/opt/stack/nova/nova/compute/resource_ tracker.py:337

Format 2.
2013-07-29 17:03:25.556 AUDIT nova.compute.resource_tracker [-] free RAM (MB): 10482
2013-07-29 17:03:25.557 AUDIT No Va.compute.resource_tracker [-] free disk (GB):
2013-07-29 17:03:25.557 AUDIT nova.compute.resource_tracker [-] Free Vcpus:2

The data in format 1 is the resource situation directly from Libvirt, and the data in format 2 is the resource in OpenStack.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.