Explorar o código

实现了 Guest 内存 top 10 展现

James Iter %!s(int64=8) %!d(string=hai) anos
pai
achega
c596b662d2

+ 9 - 0
api/guest_performance.py

@@ -220,6 +220,7 @@ def r_current_top_10():
     ret['state'] = ji.Common.exchange_state(20000)
     ret['data'] = {
         'cpu_load': list(),
+        'memory_rate': list(),
         'rw_bytes': list(),
         'rw_req': list(),
         'rt_bytes': list(),
@@ -242,6 +243,14 @@ def r_current_top_10():
 
         ret['data']['cpu_load'].append(rows[i])
 
+    rows.sort(key=lambda k: k['memory_rate'], reverse=True)
+
+    for i in range(effective_range):
+        if rows[i]['memory_rate'] == 0:
+            break
+
+        ret['data']['memory_rate'].append(rows[i])
+
     rows, _ = GuestDiskIO.get_by_filter(limit=limit, filter_str=filter_str)
     for i in range(rows.__len__()):
         rows[i]['rw_bytes'] = rows[i]['rd_bytes'] + rows[i]['wr_bytes']

+ 2 - 0
docs/todo.md

@@ -88,4 +88,6 @@
 - [x] 安装脚本加入中国本土仓库
 - [ ] 对某个 Guest 进行快照操作时,禁止对该镜像做其它快照方面的操作
 - [ ] 修复宿主机重启后,jimvc 快速 lpop 异常的问题
+- [ ] 计算节点以 JimV-C 为第一 NTP 服务器
+- [ ] 数据库时间戳,采用 JimV-N 的时间。避免 JimV-C 挂掉后,监控数据批量集中在同一个时间点上
 

+ 3 - 1
misc/init.sql

@@ -236,7 +236,7 @@ CREATE TABLE IF NOT EXISTS guest_cpu_memory(
     guest_uuid CHAR(36) NOT NULL,
     cpu_load INT UNSIGNED NOT NULL,
     memory_available BIGINT UNSIGNED NOT NULL,
-    memory_unused BIGINT UNSIGNED NOT NULL,
+    memory_rate TINYINT UNSIGNED NOT NULL DEFAULT 0,
     timestamp BIGINT UNSIGNED NOT NULL,
     PRIMARY KEY (id))
     ENGINE=Innodb
@@ -244,6 +244,8 @@ CREATE TABLE IF NOT EXISTS guest_cpu_memory(
 
 ALTER TABLE guest_cpu_memory ADD INDEX (guest_uuid);
 ALTER TABLE guest_cpu_memory ADD INDEX (cpu_load);
+ALTER TABLE guest_cpu_memory ADD INDEX (memory_available);
+ALTER TABLE guest_cpu_memory ADD INDEX (memory_rate);
 ALTER TABLE guest_cpu_memory ADD INDEX (timestamp);
 ALTER TABLE guest_cpu_memory ADD INDEX (guest_uuid, timestamp);
 

+ 5 - 0
misc/v0.5_to_v0.6/update.sql

@@ -0,0 +1,5 @@
+
+ALTER TABLE guest_cpu_memory CHANGE COLUMN memory_unused memory_rate TINYINT UNSIGNED NOT NULL DEFAULT 0;
+
+ALTER TABLE guest_cpu_memory ADD INDEX (memory_available);
+ALTER TABLE guest_cpu_memory ADD INDEX (memory_rate);

+ 1 - 1
models/event_processor.py

@@ -367,7 +367,7 @@ class EventProcessor(object):
                 cls.guest_cpu_memory.guest_uuid = item['guest_uuid']
                 cls.guest_cpu_memory.cpu_load = item['cpu_load']
                 cls.guest_cpu_memory.memory_available = item['memory_available']
-                cls.guest_cpu_memory.memory_unused = item['memory_unused']
+                cls.guest_cpu_memory.memory_rate = item['memory_rate']
                 cls.guest_cpu_memory.timestamp = timestamp
                 cls.guest_cpu_memory.create()
 

+ 3 - 1
models/guest_performance.py

@@ -22,7 +22,7 @@ class GuestCPUMemory(ORM):
         self.guest_uuid = None
         self.cpu_load = None
         self.memory_available = None
-        self.memory_unused = None
+        self.memory_rate = None
         self.timestamp = None
 
     @staticmethod
@@ -31,6 +31,8 @@ class GuestCPUMemory(ORM):
             'id': FilterFieldType.INT.value,
             'guest_uuid': FilterFieldType.STR.value,
             'cpu_load': FilterFieldType.INT.value,
+            'memory_available': FilterFieldType.INT.value,
+            'memory_rate': FilterFieldType.INT.value,
             'timestamp': FilterFieldType.INT.value
         }
 

+ 34 - 4
templates/dashboard.html

@@ -107,7 +107,7 @@
             <div class="row">
                 <div class="col-md-4">
                     <div class="content-box">
-                        <h3 class="content-box-header bg-blue-alt">
+                        <h3 class="content-box-header btn-blue-alt">
                             CPU
                         </h3>
                         <div class="content-box-wrapper" style="padding-top: 0;">
@@ -175,7 +175,7 @@
                 </div>
                 <div class="col-md-4">
                     <div class="content-box">
-                        <h3 class="content-box-header" style="background-color: #9e9e9e; opacity: 0.9; color: #fff;">
+                        <h3 class="content-box-header btn-warning" style="background-color: #9e9e9e; opacity: 0.9; color: #fff;">
                             磁盘吞吐量
                         </h3>
                         <div class="content-box-wrapper" style="padding-top: 0;">
@@ -219,7 +219,7 @@
             <div class="row">
                 <div class="col-md-4">
                     <div class="content-box">
-                        <h3 class="content-box-header bg-green" style="opacity: 0.72;">
+                        <h3 class="content-box-header btn-success" style="opacity: 0.72;">
                             网络流量
                         </h3>
                         <div class="content-box-wrapper" style="padding-top: 0;">
@@ -259,6 +259,36 @@
                     </div>
                 </div>
                 <div class="col-md-4">
+                    <div class="content-box">
+                        <h3 class="content-box-header btn-warning" style="opacity: 0.72;">
+                            内存使用率
+                        </h3>
+                        <div class="content-box-wrapper" style="padding-top: 0;">
+                            <table class="table mrg0B mrg10T" style="table-layout: fixed;">
+                                <thead>
+                                <tr>
+                                    <td style="width: 65%;">实例</td>
+                                    <td style="width: 35%;">使用率</td>
+                                </tr>
+                                </thead>
+                                <tbody>
+                                {% for item in guests_current_top_10_ret.data.memory_rate %}
+                                    {% if item.guest_uuid not in guests_mapping_by_uuid %}{% continue %}{% endif %}
+                                    <tr>
+                                        <td class="text-left" style="text-overflow: ellipsis; white-space: nowrap; overflow: hidden;">
+                                            <a href="/guest/detail/{{ item.guest_uuid }}">
+                                                {{ guests_mapping_by_uuid[item.guest_uuid].label }}/{{ guests_mapping_by_uuid[item.guest_uuid].remark }}
+                                            </a>
+                                        </td>
+                                        <td>
+                                            {{ item.memory_rate }}%
+                                        </td>
+                                    </tr>
+                                {% endfor %}
+                                </tbody>
+                            </table>
+                        </div>
+                    </div>
                 </div>
                 <div class="col-md-4">
                 </div>
@@ -383,7 +413,7 @@
             <div class="row">
                 <div class="col-md-4">
                     <div class="content-box">
-                        <h3 class="content-box-header bg-green">
+                        <h3 class="content-box-header btn-success">
                             网络流量
                         </h3>
                         <div class="content-box-wrapper" style="padding-top: 0;">

+ 12 - 0
templates/layout.html

@@ -62,6 +62,18 @@
             pointer-events: none;
         }
 
+        select {
+            padding: 0 0 !important;
+        }
+
+        option {
+            font-weight: normal;
+            display: block;
+            white-space: pre;
+            min-height: 1.2em;
+            padding: 0 2px 1px;
+        }
+
     </style>