主要是依据两个api ,ganglia API 和 openstack API
Ganglia-api
a small standalone python application that takes XML data from a number of Ganglia gmetad processes and presents a RESTful JSON API of the most recently received data.
Address:https://github.com/guardian/ganglia-api
Configuration
Download the source code and configure as follows:
virtualenv ve
source ve/bin/activate
pip install -r requirements.txt
python ganglia/ganglia_api.py
Api use
import urllib2
url = "http://192.168.1.11:8080/ganglia/api/v1/metrics?environment=PROD&metric=load_one"
req = urllib2.Request(req_url)
Metrics Data format (返回数据格式)
{u'response': {
u'metrics': [
{u'group': u'load',
u'description': u'One minute load average',
u'service': u'unspecified',
u'title': u'One Minute Load Average',
u'type': u'gauge',
u'metric': u'load_one',
u'sampleTime': u'2014-08-20T21:04:46.000Z',
u'value': 0.08,
u'environment': u'PROD',
u'instance': u'',
u'host': u'192.168.1.31',
u'graphUrl': u'http://controller/ganglia/graph.......',
u'units': u' ',
u'dataUrl': u'http://ganglia.guprod.gnl:8080/g.......',
u'cluster': u'openstack',
u'id': u'prod.unspecified.openstack.192.168.1.31.load.load_one'
},
u'status': u'ok',
u'total': 1,
u'localTime': u'2014-08-20T21:06:01.703541',
u'time': u'0.001'
}
}
Openstack-api
Install api(linux):
apt-get install python-pip
pip install python-novaclient
pip install python-keystoneclient
……
How to use openstack-api
import novaclient.v1_1.client as nvclient
nova = nvclient.Client(auth_url="http://controller:35357/v2.0", username="admin",\
api_key="ADMIN_PASS", project_id="admin")
nova.servers.live_migrate(vm, host_name, False, True)
调度的核心代码
get_daemon()
gangliaClient = sche_ganglia.GangliaClient()
localNovaClient = sche_nova.LocalNovaClient()
while(True):
busy_hosts, idle_hosts= gangliaClient.get_busy_idle_hosts()
localNovaClient.migrate_hosts(busy_hosts)
#localNovaClient.live_migrate_hosts(busy_hosts,idle_hosts)
time.sleep(50)
做虚拟机调度需要注意的4个问题:
In general, the problem of dynamic VM consolidation can be split into 4 sub-problems:
1、Deciding when a host is considered to be underloaded, so that all the VMs should be migrated from it, and the host should be switched to a low power mode, such as the sleep mode.
2、Deciding when a host is considered to be overloaded, so that some VMs should be migrated from the host to other hosts to avoid performance degradation.
3、Selecting VMs to migrate from an overloaded host out of the full set of the VMs currently served by the host.
4、Placing VMs selected for migration to other active or re-activated hosts.
本文介绍了如何利用Ganglia API和OpenStack API进行虚拟机调度,包括配置、使用方法及核心代码实现。重点讨论了在虚拟机调度过程中面临的问题及其解决方案,涉及动态VM合并、负载均衡、VM选择与迁移等关键步骤。
18

被折叠的 条评论
为什么被折叠?



