Skip to content

Commit 6c0b63f

Browse files
authored
Merge pull request #9268 from GuoLiBin6/feat/glb-to-4.0/src
feat: server show numa info
2 parents 48c7c28 + 7550eca commit 6c0b63f

File tree

6 files changed

+96
-0
lines changed

6 files changed

+96
-0
lines changed

containers/Compute/locales/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,7 @@
626626
"compute.text_606": "Resource Statistics",
627627
"compute.text_607": "Transparent Device",
628628
"compute.text_608": "Metrics",
629+
"compute.text_609": "NUMA binding",
629630
"compute.passthrough_device_count": "#Passthrough Device",
630631
"compute.host.host_type.title": "Virtualization",
631632
"compute.host.host_enable_numa_allocate.title": "NUMA Core Binding",

containers/Compute/locales/ja-JP.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,7 @@
626626
"compute.text_606": "リソース統計",
627627
"compute.text_607": "透明伝送装置",
628628
"compute.text_608": "モニター",
629+
"compute.text_609": "NUMAバインド",
629630
"compute.passthrough_device_count": "透過伝送装置数",
630631
"compute.host.host_type.title": "仮想化",
631632
"compute.host.host_enable_numa_allocate.title": "NUMAコアバインディング",

containers/Compute/locales/zh-CN.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,7 @@
626626
"compute.text_606": "资源统计",
627627
"compute.text_607": "透传设备",
628628
"compute.text_608": "监控",
629+
"compute.text_609": "NUMA绑核",
629630
"compute.passthrough_device_count": "透传设备数量",
630631
"compute.host.host_type.title": "虚拟化技术",
631632
"compute.host.host_enable_numa_allocate.title": "NUMA绑核",

containers/Compute/views/vminstance-container/sidepage/Detail.vue

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import WindowsMixin from '@/mixins/windows'
3636
import { findPlatform } from '@/utils/common/hypervisor'
3737
import { HYPERVISORS_MAP } from '@/constants'
3838
import { sizestr } from '@/utils/utils'
39+
import { formatCpuNumaPin } from '@Compute/views/vminstance/utils'
3940
4041
export default {
4142
name: 'VmContainerInstanceDetail',
@@ -229,6 +230,13 @@ export default {
229230
},
230231
hidden: () => this.$isScopedPolicyMenuHidden('server_hidden_columns.vmem_size'),
231232
},
233+
{
234+
field: 'cpu_numa_pin',
235+
title: this.$t('compute.text_609'),
236+
formatter: ({ row }) => {
237+
return formatCpuNumaPin(row)
238+
},
239+
},
232240
{
233241
field: 'dataDisk',
234242
title: this.$t('compute.text_50'),

containers/Compute/views/vminstance/sidepage/Detail.vue

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import { findPlatform } from '@/utils/common/hypervisor'
3636
import { BRAND_MAP, HYPERVISORS_MAP } from '@/constants'
3737
import { sizestr, sizestrWithUnit } from '@/utils/utils'
3838
import { hasPermission } from '@/utils/auth'
39+
import { formatCpuNumaPin } from '@Compute/views/vminstance/utils'
3940
4041
export default {
4142
name: 'VmInstanceDetail',
@@ -426,6 +427,13 @@ export default {
426427
},
427428
hidden: () => this.$isScopedPolicyMenuHidden('server_hidden_columns.vmem_size'),
428429
},
430+
{
431+
field: 'cpu_numa_pin',
432+
title: this.$t('compute.text_609'),
433+
formatter: ({ row }) => {
434+
return formatCpuNumaPin(row)
435+
},
436+
},
429437
{
430438
field: 'sysDisk',
431439
title: this.$t('compute.text_49'),

containers/Compute/views/vminstance/utils.js

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1+
import Vue from 'vue'
12
import { typeClouds } from '@/utils/common/hypervisor'
23
import i18n from '@/locales'
4+
import { sizestr } from '@/utils/utils'
5+
6+
const __cpuNumaPinHVm = new Vue()
7+
const _cpuNumaPinH = (...args) => __cpuNumaPinHVm.$createElement(...args)
38

49
const hypervisorMap = typeClouds.hypervisorMap
510

@@ -924,3 +929,75 @@ export const validateRescueMode = (val) => {
924929
}
925930
return ret
926931
}
932+
933+
/** cpu_numa_pin:每项一行;内存 sizestr;绑定 CPU 取全部 pcpu 排序后合并连续区间 */
934+
export const formatSortedPcpuRanges = (sortedPcpus) => {
935+
if (!sortedPcpus.length) return '-'
936+
const parts = []
937+
let start = sortedPcpus[0]
938+
let end = sortedPcpus[0]
939+
for (let i = 1; i < sortedPcpus.length; i++) {
940+
const cur = sortedPcpus[i]
941+
if (cur === end + 1) {
942+
end = cur
943+
} else {
944+
parts.push(start === end ? String(start) : `${start}-${end}`)
945+
start = cur
946+
end = cur
947+
}
948+
}
949+
parts.push(start === end ? String(start) : `${start}-${end}`)
950+
return parts.join(',')
951+
}
952+
953+
const getCpuNumaPinLineData = (item) => {
954+
const nodeId = item.node_id
955+
const sizeMb = item.size_mb
956+
const pin = item.vcpu_pin || []
957+
const pcpus = [...new Set(
958+
pin
959+
.filter(p => p && typeof p.pcpu === 'number')
960+
.map(p => p.pcpu),
961+
)].sort((a, b) => a - b)
962+
const cpuStr = formatSortedPcpuRanges(pcpus)
963+
const memStr = sizestr(sizeMb, 'M', 1024)
964+
return { nodeId, memStr, cpuStr }
965+
}
966+
967+
export const formatCpuNumaPinLine = (item) => {
968+
const { nodeId, memStr, cpuStr } = getCpuNumaPinLineData(item)
969+
return `node:${nodeId} mem: ${memStr} cpu: ${cpuStr}`
970+
}
971+
972+
const CPU_NUMA_PIN_LINE_GAP = '12px'
973+
974+
export const formatCpuNumaPin = (row) => {
975+
const raw = row.cpu_numa_pin
976+
if (raw === undefined || raw === null || raw === '') return '-'
977+
let arr = raw
978+
if (typeof raw === 'string') {
979+
try {
980+
arr = JSON.parse(raw)
981+
} catch (e) {
982+
return '-'
983+
}
984+
}
985+
if (!Array.isArray(arr) || arr.length === 0) return '-'
986+
return _cpuNumaPinH('div', arr.map((item, idx) => {
987+
const { nodeId, memStr, cpuStr } = getCpuNumaPinLineData(item)
988+
return _cpuNumaPinH('div', {
989+
key: idx,
990+
style: {
991+
display: 'flex',
992+
flexWrap: 'wrap',
993+
alignItems: 'center',
994+
columnGap: CPU_NUMA_PIN_LINE_GAP,
995+
rowGap: '4px',
996+
},
997+
}, [
998+
_cpuNumaPinH('span', `node: ${nodeId}`),
999+
_cpuNumaPinH('span', `mem: ${memStr}`),
1000+
_cpuNumaPinH('span', `cpu: ${cpuStr}`),
1001+
])
1002+
}))
1003+
}

0 commit comments

Comments
 (0)