Просмотр исходного кода

加入磁盘吞吐量及IOPS的展现

James Iter 9 лет назад
Родитель
Сommit
5a93672b68
2 измененных файлов с 107 добавлено и 5 удалено
  1. 85 4
      templates/dashboard.html
  2. 22 1
      views/dashboard.py

+ 85 - 4
templates/dashboard.html

@@ -115,14 +115,14 @@
                                 <thead>
                                 <thead>
                                 <tr>
                                 <tr>
                                     <td style="width: 65%;">实例</td>
                                     <td style="width: 65%;">实例</td>
-                                    <td>负载</td>
+                                    <td style="width: 35%;">负载</td>
                                 </tr>
                                 </tr>
                                 </thead>
                                 </thead>
                                 <tbody>
                                 <tbody>
                                 {% for item in guests_current_top_10_ret.data.cpu_load %}
                                 {% for item in guests_current_top_10_ret.data.cpu_load %}
                                     {% if item.guest_uuid not in guests_mapping_by_uuid %}{% continue %}{% endif %}
                                     {% if item.guest_uuid not in guests_mapping_by_uuid %}{% continue %}{% endif %}
                                 <tr>
                                 <tr>
-                                    <td class="text-left">
+                                    <td class="text-left" style="text-overflow: ellipsis; white-space: nowrap; overflow: hidden;">
                                         <a href="/guest/detail/{{ item.guest_uuid }}">
                                         <a href="/guest/detail/{{ item.guest_uuid }}">
                                             {{ guests_mapping_by_uuid[item.guest_uuid].label }}/{{ guests_mapping_by_uuid[item.guest_uuid].remark }}
                                             {{ guests_mapping_by_uuid[item.guest_uuid].label }}/{{ guests_mapping_by_uuid[item.guest_uuid].remark }}
                                         </a>
                                         </a>
@@ -140,6 +140,83 @@
                         </div>
                         </div>
                     </div>
                     </div>
                 </div>
                 </div>
+                <div class="col-md-4">
+                    <div class="content-box">
+                        <h3 class="content-box-header bg-black-opacity-alt">
+                            磁盘 IOPS
+                        </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%;">IOPS</td>
+                                </tr>
+                                </thead>
+                                <tbody>
+                                {% for item in guests_current_top_10_ret.data.rw_req %}
+                                    {% if item.disk_uuid not in disks_mapping_by_uuid %}{% continue %}{% endif %}
+                                    {% if disks_mapping_by_uuid[item.disk_uuid].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="/disk/detail/{{ item.disk_uuid }}">
+                                                {{ guests_mapping_by_uuid[disks_mapping_by_uuid[item.disk_uuid].guest_uuid].label }}/{{ disks_mapping_by_uuid[item.disk_uuid].remark }}
+                                            </a>
+                                        </td>
+                                        <td>
+                                            {{ item.rw_req }}
+                                        </td>
+                                    </tr>
+                                {% endfor %}
+                                </tbody>
+                            </table>
+                        </div>
+                    </div>
+                </div>
+                <div class="col-md-4">
+                    <div class="content-box">
+                        <h3 class="content-box-header bg-black-opacity-alt">
+                            磁盘吞吐量
+                        </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.rw_bytes %}
+                                    {% if item.disk_uuid not in disks_mapping_by_uuid %}{% continue %}{% endif %}
+                                    {% if disks_mapping_by_uuid[item.disk_uuid].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="/disk/detail/{{ item.disk_uuid }}">
+                                                {{ guests_mapping_by_uuid[disks_mapping_by_uuid[item.disk_uuid].guest_uuid].label }}/{{ disks_mapping_by_uuid[item.disk_uuid].remark }}
+                                            </a>
+                                        </td>
+                                        <td>
+                                            <!-- 速率参考链接:https://en.wikipedia.org/wiki/Data_rate_units#Examples_of_bit_rates -->
+                                            {% if item.rw_bytes >= 1024**3 %}
+                                                {{ '%0.1f'| format(item.rw_bytes / 1024**3) }} GBps
+                                            {% elif item.rw_bytes >= 1024**2 %}
+                                                {{ '%0.1f'| format(item.rw_bytes / 1024**2) }} MBps
+                                            {% elif item.rw_bytes >= 1024 %}
+                                                {{ '%0.1f'| format(item.rw_bytes / 1024) }} KBps
+                                            {% else %}
+                                                {{ item.rw_bytes }} Bps
+                                            {% endif %}
+                                        </td>
+                                    </tr>
+                                {% endfor %}
+                                </tbody>
+                            </table>
+                        </div>
+                    </div>
+                </div>
+            </div>
+            <div class="row">
                 <div class="col-md-4">
                 <div class="col-md-4">
                     <div class="content-box">
                     <div class="content-box">
                         <h3 class="content-box-header bg-green">
                         <h3 class="content-box-header bg-green">
@@ -150,14 +227,14 @@
                                 <thead>
                                 <thead>
                                 <tr>
                                 <tr>
                                     <td style="width: 65%;">实例</td>
                                     <td style="width: 65%;">实例</td>
-                                    <td>流量</td>
+                                    <td style="width: 35%;">流量</td>
                                 </tr>
                                 </tr>
                                 </thead>
                                 </thead>
                                 <tbody>
                                 <tbody>
                                 {% for item in guests_current_top_10_ret.data.rt_bytes %}
                                 {% for item in guests_current_top_10_ret.data.rt_bytes %}
                                     {% if item.guest_uuid not in guests_mapping_by_uuid %}{% continue %}{% endif %}
                                     {% if item.guest_uuid not in guests_mapping_by_uuid %}{% continue %}{% endif %}
                                     <tr>
                                     <tr>
-                                        <td class="text-left">
+                                        <td class="text-left" style="text-overflow: ellipsis; white-space: nowrap; overflow: hidden;">
                                             <a href="/guest/detail/{{ item.guest_uuid }}">
                                             <a href="/guest/detail/{{ item.guest_uuid }}">
                                                 {{ guests_mapping_by_uuid[item.guest_uuid].label }}/{{ guests_mapping_by_uuid[item.guest_uuid].remark }}
                                                 {{ guests_mapping_by_uuid[item.guest_uuid].label }}/{{ guests_mapping_by_uuid[item.guest_uuid].remark }}
                                             </a>
                                             </a>
@@ -181,6 +258,10 @@
                         </div>
                         </div>
                     </div>
                     </div>
                 </div>
                 </div>
+                <div class="col-md-4">
+                </div>
+                <div class="col-md-4">
+                </div>
             </div>
             </div>
         </div>
         </div>
     </div>
     </div>

+ 22 - 1
views/dashboard.py

@@ -64,6 +64,27 @@ def show():
     for guest in guests_ret['data']:
     for guest in guests_ret['data']:
         guests_mapping_by_uuid[guest['uuid']] = guest
         guests_mapping_by_uuid[guest['uuid']] = guest
 
 
+    disks_url = host_url + url_for('api_disks.r_get_by_filter')
+
+    disks_uuid = list()
+    for k, v in guests_current_top_10_ret['data'].items():
+        for item in v:
+            if 'disk_uuid' not in item:
+                break
+
+            if item['disk_uuid'] not in disks_uuid:
+                disks_uuid.append(item['disk_uuid'])
+
+    disks_url = disks_url + '?filter=uuid:in:' + ','.join(disks_uuid)
+
+    disks_ret = requests.get(url=disks_url)
+    disks_ret = json.loads(disks_ret.content)
+
+    # Disk uuid 与 Disk 的映射
+    disks_mapping_by_uuid = dict()
+    for disk in disks_ret['data']:
+        disks_mapping_by_uuid[disk['uuid']] = disk
+
     hosts_sum = {'cpu': 0, 'memory': 0}
     hosts_sum = {'cpu': 0, 'memory': 0}
 
 
     for host in hosts_ret['data']:
     for host in hosts_ret['data']:
@@ -74,5 +95,5 @@ def show():
                            guests_distribute_count_ret=guests_distribute_count_ret,
                            guests_distribute_count_ret=guests_distribute_count_ret,
                            disks_distribute_count_ret=disks_distribute_count_ret,
                            disks_distribute_count_ret=disks_distribute_count_ret,
                            guests_current_top_10_ret=guests_current_top_10_ret,
                            guests_current_top_10_ret=guests_current_top_10_ret,
-                           guests_mapping_by_uuid=guests_mapping_by_uuid)
+                           guests_mapping_by_uuid=guests_mapping_by_uuid, disks_mapping_by_uuid=disks_mapping_by_uuid)