Explorar el Código

实现 Guest 内存使用量采集

James Iter hace 8 años
padre
commit
b0445243cd

+ 22 - 2
api/guest.py

@@ -741,6 +741,22 @@ def r_migrate(uuids, destination_host):
     try:
         ji.Check.previewing(args_rules, {'uuids': uuids, 'destination_host': destination_host})
 
+        ret = dict()
+        ret['state'] = ji.Common.exchange_state(20000)
+
+        # 取全部活着的 hosts
+        available_hosts = Host.get_available_hosts(nonrandom=None)
+
+        if available_hosts.__len__() == 0:
+            ret['state'] = ji.Common.exchange_state(50351)
+            return ret
+
+        available_hosts_mapping_by_node_id = dict()
+
+        for host in available_hosts:
+            if host['node_id'] not in available_hosts_mapping_by_node_id:
+                available_hosts_mapping_by_node_id[host['node_id']] = host
+
         guest = Guest()
         for uuid in uuids.split(','):
             guest.uuid = uuid
@@ -754,6 +770,12 @@ def r_migrate(uuids, destination_host):
             guest.uuid = uuid
             guest.get_by('uuid')
 
+            # 忽略宕机计算节点 上面的 虚拟机 迁移请求
+            # 忽略目标计算节点 等于 当前所在 计算节点 的虚拟机 迁移请求
+            if guest.node_id not in available_hosts_mapping_by_node_id or \
+                    available_hosts_mapping_by_node_id[guest.node_id]['hostname'] == destination_host:
+                continue
+
             message = {
                 '_object': 'guest',
                 'action': 'migrate',
@@ -765,8 +787,6 @@ def r_migrate(uuids, destination_host):
 
             Utils.emit_instruction(message=json.dumps(message))
 
-        ret = dict()
-        ret['state'] = ji.Common.exchange_state(20000)
         return ret
 
     except ji.PreviewingError, e:

+ 1 - 0
docs/todo.md

@@ -87,4 +87,5 @@
 - [ ] IP 地址池管理功能。对 IP 池中的 IP 有查看、添加、禁用、解禁等功能
 - [x] 安装脚本加入中国本土仓库
 - [ ] 对某个 Guest 进行快照操作时,禁止对该镜像做其它快照方面的操作
+- [ ] 修复宿主机重启后,jimvc 快速 lpop 异常的问题
 

+ 4 - 0
misc/v0.5_to_v0.6/upgrade.sh

@@ -0,0 +1,4 @@
+#!/usr/bin/env bash
+
+# 在所有 计算节点 上执行
+yum install python-dmidecode -y

+ 1 - 0
models/event_processor.py

@@ -138,6 +138,7 @@ class EventProcessor(object):
             'system_load': cls.message['message']['system_load'],
             'memory': cls.message['message']['memory'],
             'memory_available': cls.message['message']['memory_available'],
+            'dmidecode': cls.message['message']['dmidecode'],
             'interfaces': cls.message['message']['interfaces'],
             'disks': cls.message['message']['disks'],
             'boot_time': cls.message['message']['boot_time'],

+ 6 - 6
templates/guest_detail.html

@@ -457,7 +457,7 @@
                     },
                     yAxis: {
                         min: 0,
-                        max: 'dataMax',
+                        max: {{ guest_ret.data.memory }},
                         minInterval: 2,
                         axisTick: {
                             show: false
@@ -492,7 +492,7 @@
                             $.each(data.data, function (i, ele) {
                                 d.push([
                                     ele['timestamp'] * 1000,
-                                    ele['memory_unused'] !== null ? Math.floor(ele['memory_unused'] / 1024) / 1000 : null
+                                    ele['memory_available'] !== null ? Math.floor(ele['memory_available'] / 1024) / 1000 : null
                                 ])
                             });
                             return d;
@@ -871,11 +871,11 @@
 
         cpu_chart = echarts.init(document.getElementById('cpu_chart'));
         traffic_chart = echarts.init(document.getElementById('traffic_chart'));
-        // memory_chart = echarts.init(document.getElementById('memory_chart'));
+        memory_chart = echarts.init(document.getElementById('memory_chart'));
         render_cpu_chart(uuid, 'hour');
         render_traffic_chart(uuid, 'hour');
-        render_disks_chart(uuid, 'hour')
-        // render_memory_chart(uuid, 'hour');
+        render_disks_chart(uuid, 'hour');
+        render_memory_chart(uuid, 'hour');
 
         $("#disks_table thead").on('click', ".all_selector", function() {
             if ($("#disks_table thead .all_selector").is(':checked')) {
@@ -1196,8 +1196,8 @@
                     <div>
                         <div id="cpu_chart" style="width: 800px;height:280px;"></div>
                         <div id="traffic_chart" style="width: 800px;height:280px;"></div>
+                        <div id="memory_chart" style="width: 800px;height:280px;"></div>
                     </div>
-                    <!--<div id="memory_chart" style="width: 800px;height:280px;"></div>-->
                     <div id="disks_chart"></div>
                 </div>
             </div>

+ 4 - 4
templates/guests_show.html

@@ -170,7 +170,7 @@
             $('#migrate_instance_uuid').val(
                 $(me.relatedTarget).parent().parent().parent().parent().parent().children()[0].textContent);
             $.ajax({
-                url : '/api/hosts',
+                url : '/api/hosts?alive',
                 type : 'GET',
                 contentType: "application/json; charset=utf-8",
                 dataType: 'json',
@@ -960,7 +960,7 @@
                                     </a>
                                 </li>
                                 <li class="divider"></li>
-                                <li class="">
+                                <li class="{% if item.status not in [1] %} disabled {% endif %}">
                                     <a href="/guest/vnc/{{ item.uuid }}" target="_blank">远程连接</a>
                                 </li>
                                 <li class="divider"></li>
@@ -971,14 +971,14 @@
                                        分配带宽
                                     </a>
                                 </li>
-                                <li class="">
+                                <li class="{% if item.status not in [5] %} disabled {% endif %}">
                                     <a href="javascript:;" data-toggle="modal" data-target="#adjust_ability_modal"
                                        onclick="$('#instance_uuid').val($($(this).parent().parent().parent().parent().parent().children()[0]).text());
                                                 $('#adjust_ability_instance_desc').text($($(this).parent().parent().parent().parent().parent().children()[2]).find('div a')[0].textContent + '/' + $($(this).parent().parent().parent().parent().parent().children()[2]).find('div p')[0].textContent)">
                                        变更配置
                                     </a>
                                 <li class="divider"></li>
-                                <li class="">
+                                <li class="{% if item.status not in [1] %} disabled {% endif %}">
                                     <a href="javascript:;" data-toggle="modal" data-target="#reset_password_modal"
                                        onclick="$('#reset_password_type').val('single')">
                                         密码重置