From 251a353e983f94a1e47b240307fd6c6027ad30a2 Mon Sep 17 00:00:00 2001 From: xusongfu Date: Tue, 2 Aug 2022 14:26:43 +0800 Subject: [PATCH] feat: show stats of a zun container Show stats of a zun container Change-Id: I508a97d1a86217a590ccb624a0009cc44daef95f --- src/client/zun/index.js | 9 +++-- src/locales/en.json | 7 ++++ src/locales/zh.json | 7 ++++ .../Containers/Detail/BaseDetail.jsx | 39 ++++++++++++++++++- src/stores/zun/containers.js | 6 +++ 5 files changed, 63 insertions(+), 5 deletions(-) diff --git a/src/client/zun/index.js b/src/client/zun/index.js index 5586a842..960ae98a 100644 --- a/src/client/zun/index.js +++ b/src/client/zun/index.js @@ -27,12 +27,10 @@ export class ZunClient extends Base { get resources() { return [ { - name: 'capsules', key: 'capsules', responseKey: 'capsule', }, { - name: 'containers', key: 'containers', responseKey: 'container', extendOperations: [ @@ -69,14 +67,17 @@ export class ZunClient extends Base { method: 'post', }, ], + subResources: [ + { + key: 'stats', + }, + ], }, { - name: 'hosts', key: 'hosts', responseKey: 'host', }, { - name: 'quotas', key: 'quotas', }, ]; diff --git a/src/locales/en.json b/src/locales/en.json index 98cd647c..fba5c186 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -191,6 +191,7 @@ "Average PGs per OSD": "Average PGs per OSD", "Awaiting Transfer": "Awaiting Transfer", "Azerbaijan": "Azerbaijan", + "BLOCK I/O(B)": "BLOCK I/O(B)", "Back": "Back", "Back End": "Back End", "Back to Home": "Back to Home", @@ -269,6 +270,7 @@ "COE": "COE", "COE Version": "COE Version", "CPU": "CPU", + "CPU %": "CPU %", "CPU (Core)": "CPU (Core)", "CPU Arch": "CPU Arch", "CPU Cores": "CPU Cores", @@ -1357,6 +1359,9 @@ "MAC Address": "MAC Address", "MAC Learning State": "MAC Learning State", "MAPRFS": "MAPRFS", + "MEM %": "MEM %", + "MEM LIMIT(MiB)": "MEM LIMIT(MiB)", + "MEM USAGE(MiB)": "MEM USAGE(MiB)", "MTU": "MTU", "Mac Address": "Mac Address", "MacVTap": "MacVTap", @@ -1471,6 +1476,7 @@ "MySQL Actions": "MySQL Actions", "Myanmar": "Myanmar", "N/A": "N/A", + "NET I/O(B)": "NET I/O(B)", "NFS": "NFS", "NOOP": "NOOP", "NUMA Node": "NUMA Node", @@ -2152,6 +2158,7 @@ "Startup Parameters": "Startup Parameters", "State": "State", "Static Routes": "Static Routes", + "Stats Information": "Stats Information", "Status": "Status", "Status Code": "Status Code", "Status Detail": "Status Detail", diff --git a/src/locales/zh.json b/src/locales/zh.json index 1e1218c7..cef18fa6 100644 --- a/src/locales/zh.json +++ b/src/locales/zh.json @@ -191,6 +191,7 @@ "Average PGs per OSD": "每个OSD平均PG数量", "Awaiting Transfer": "等待转让", "Azerbaijan": "阿塞拜疆", + "BLOCK I/O(B)": "块 I/O(B)", "Back": "返回", "Back End": "后端", "Back to Home": "返回首页", @@ -269,6 +270,7 @@ "COE": "COE", "COE Version": "COE版本", "CPU": "CPU", + "CPU %": "CPU使用率(%)", "CPU (Core)": "CPU (核)", "CPU Arch": "CPU架构", "CPU Cores": "CPU核数", @@ -1357,6 +1359,9 @@ "MAC Address": "MAC地址", "MAC Learning State": "MAC学习状态", "MAPRFS": "", + "MEM %": "内存使用率(%)", + "MEM LIMIT(MiB)": "总内存(MiB)", + "MEM USAGE(MiB)": "已用内存(MiB)", "MTU": "", "Mac Address": "Mac地址", "MacVTap": "", @@ -1471,6 +1476,7 @@ "MySQL Actions": "", "Myanmar": "缅甸", "N/A": "", + "NET I/O(B)": "网络 I/O(B)", "NFS": "", "NOOP": "", "NUMA Node": "NUMA节点", @@ -2152,6 +2158,7 @@ "Startup Parameters": "启动参数", "State": "状态", "Static Routes": "静态路由", + "Stats Information": "统计信息", "Status": "状态", "Status Code": "状态码", "Status Detail": "状态详情", diff --git a/src/pages/container-service/containers/Containers/Detail/BaseDetail.jsx b/src/pages/container-service/containers/Containers/Detail/BaseDetail.jsx index 6fc35909..d1d5df9f 100644 --- a/src/pages/container-service/containers/Containers/Detail/BaseDetail.jsx +++ b/src/pages/container-service/containers/Containers/Detail/BaseDetail.jsx @@ -20,7 +20,7 @@ import { isEmpty } from 'lodash'; export class BaseDetail extends Base { get leftCards() { - const cards = [this.baseInfoCard, this.miscellaneousCard]; + const cards = [this.baseInfoCard, this.statsCard, this.miscellaneousCard]; return cards; } @@ -170,6 +170,43 @@ export class BaseDetail extends Base { options, }; } + + get statsCard() { + const options = [ + { + label: t('BLOCK I/O(B)'), + dataIndex: 'BLOCK I/O(B)', + }, + { + label: t('NET I/O(B)'), + dataIndex: 'NET I/O(B)', + }, + { + label: t('CPU %'), + dataIndex: 'CPU %', + render: (value = 0) => value.toFixed(4), + }, + { + label: t('MEM LIMIT(MiB)'), + dataIndex: 'MEM LIMIT(MiB)', + }, + { + label: t('MEM USAGE(MiB)'), + dataIndex: 'MEM USAGE(MiB)', + render: (value = 0) => value.toFixed(4), + }, + { + label: t('MEM %'), + dataIndex: 'MEM %', + render: (value = 0) => value.toFixed(4), + }, + ]; + + return { + title: t('Stats Information'), + options, + }; + } } export default inject('rootStore')(observer(BaseDetail)); diff --git a/src/stores/zun/containers.js b/src/stores/zun/containers.js index 1bf36a91..e68013db 100644 --- a/src/stores/zun/containers.js +++ b/src/stores/zun/containers.js @@ -75,6 +75,12 @@ export class ContainersStore extends Base { async execute(id, data) { return this.client.execute(id, data); } + + async detailDidFetch(item) { + const { uuid } = item; + const stats = (await this.client.stats.list(uuid)) || {}; + return { ...item, ...stats }; + } } const globalContainersStore = new ContainersStore();