fix: 修正虚拟机指标宿主机参数
This commit is contained in:
@@ -2000,6 +2000,19 @@ const loadHostOptions = async () => {
|
|||||||
} catch { /* */ }
|
} catch { /* */ }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const readHostId = value => Number(value?.host_id ?? value?.hostId ?? value?.HostId ?? 0) || 0
|
||||||
|
const resolveVmHostId = responseData => {
|
||||||
|
const vm = responseData?.data ?? responseData?.vm ?? responseData
|
||||||
|
const volumes = responseData?.volumes || []
|
||||||
|
const networks = responseData?.networks || []
|
||||||
|
const systemVolume = volumes.find(volume => (volume.is_system ?? volume.isSystem) && readHostId(volume))
|
||||||
|
const anyVolume = volumes.find(volume => readHostId(volume))
|
||||||
|
const anyNetwork = networks.find(network => readHostId(network))
|
||||||
|
return readHostId(responseData) || readHostId(responseData?.host) || readHostId(vm) ||
|
||||||
|
readHostId(systemVolume) || readHostId(anyVolume) || readHostId(anyNetwork) ||
|
||||||
|
Number(route.query.host_id) || 0
|
||||||
|
}
|
||||||
|
|
||||||
const loadDetail = async () => {
|
const loadDetail = async () => {
|
||||||
if (!vmId.value) return
|
if (!vmId.value) return
|
||||||
loading.value = true
|
loading.value = true
|
||||||
@@ -2024,7 +2037,7 @@ const loadDetail = async () => {
|
|||||||
}
|
}
|
||||||
vmPortGroup.value = d.in_port_group || null
|
vmPortGroup.value = d.in_port_group || null
|
||||||
vmOutPortGroup.value = d.out_port_group || null
|
vmOutPortGroup.value = d.out_port_group || null
|
||||||
vmHostId.value = detail.value?.host_id || vmVolumes.value[0]?.host_id || vmNetworks.value[0]?.host_id || 0
|
vmHostId.value = resolveVmHostId(d)
|
||||||
handleDetailMigrateState()
|
handleDetailMigrateState()
|
||||||
} else ElMessage.error(extractApiError(res?.data, '加载失败'))
|
} else ElMessage.error(extractApiError(res?.data, '加载失败'))
|
||||||
} catch (e) { ElMessage.error(extractApiError(e?.response?.data, '加载失败')) } finally { loading.value = false }
|
} catch (e) { ElMessage.error(extractApiError(e?.response?.data, '加载失败')) } finally { loading.value = false }
|
||||||
@@ -2162,6 +2175,10 @@ const vmMemPercent = (m) => {
|
|||||||
|
|
||||||
const loadHistoricalMetrics = async () => {
|
const loadHistoricalMetrics = async () => {
|
||||||
if (!serviceId.value || !detail.value?.name) return
|
if (!serviceId.value || !detail.value?.name) return
|
||||||
|
if (!vmHostId.value) {
|
||||||
|
ElMessage.warning('未获取到虚拟机所属宿主机,无法加载监控指标')
|
||||||
|
return
|
||||||
|
}
|
||||||
const range = getMonitorTimeRange()
|
const range = getMonitorTimeRange()
|
||||||
if (!range) return
|
if (!range) return
|
||||||
historicalMetricsLoading.value = true
|
historicalMetricsLoading.value = true
|
||||||
|
|||||||
@@ -987,6 +987,18 @@ const handleExitRescue = (row) => {
|
|||||||
}).catch(() => {})
|
}).catch(() => {})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const readHostId = value => Number(value?.host_id ?? value?.hostId ?? value?.HostId ?? 0) || 0
|
||||||
|
const resolveVmHostId = responseData => {
|
||||||
|
const vm = responseData?.data ?? responseData?.vm ?? responseData
|
||||||
|
const volumes = responseData?.volumes || []
|
||||||
|
const networks = responseData?.networks || []
|
||||||
|
const systemVolume = volumes.find(volume => (volume.is_system ?? volume.isSystem) && readHostId(volume))
|
||||||
|
const anyVolume = volumes.find(volume => readHostId(volume))
|
||||||
|
const anyNetwork = networks.find(network => readHostId(network))
|
||||||
|
return readHostId(responseData) || readHostId(responseData?.host) || readHostId(vm) ||
|
||||||
|
readHostId(systemVolume) || readHostId(anyVolume) || readHostId(anyNetwork) || 0
|
||||||
|
}
|
||||||
|
|
||||||
const handleViewDetail = async (row) => {
|
const handleViewDetail = async (row) => {
|
||||||
detailVisible.value = true
|
detailVisible.value = true
|
||||||
detailLoading.value = true
|
detailLoading.value = true
|
||||||
@@ -1001,6 +1013,7 @@ const handleViewDetail = async (row) => {
|
|||||||
vm.volumes = d.volumes || []
|
vm.volumes = d.volumes || []
|
||||||
vm.image = d.image || null
|
vm.image = d.image || null
|
||||||
vm.in_port_group = d.in_port_group || null
|
vm.in_port_group = d.in_port_group || null
|
||||||
|
vm.host_id = resolveVmHostId(d) || Number(hostId.value) || 0
|
||||||
if (!vm.ips && vm.networks?.length) vm.ips = vm.networks.map(n => n.address?.split('/')[0]).filter(Boolean).join(', ')
|
if (!vm.ips && vm.networks?.length) vm.ips = vm.networks.map(n => n.address?.split('/')[0]).filter(Boolean).join(', ')
|
||||||
currentDetail.value = vm
|
currentDetail.value = vm
|
||||||
}
|
}
|
||||||
@@ -1023,11 +1036,16 @@ const fetchVmStatus = async (vm) => {
|
|||||||
|
|
||||||
const fetchVmMetrics = async (vm) => {
|
const fetchVmMetrics = async (vm) => {
|
||||||
try {
|
try {
|
||||||
|
const metricsHostId = readHostId(vm) || Number(hostId.value) || 0
|
||||||
|
if (!metricsHostId) {
|
||||||
|
ElMessage.warning('未获取到虚拟机所属宿主机,无法查看指标')
|
||||||
|
return
|
||||||
|
}
|
||||||
const now = new Date()
|
const now = new Date()
|
||||||
const start = new Date(now.getTime() - 60 * 60 * 1000)
|
const start = new Date(now.getTime() - 60 * 60 * 1000)
|
||||||
const res = await getMetricsHistory({
|
const res = await getMetricsHistory({
|
||||||
service_id: serviceId.value,
|
service_id: serviceId.value,
|
||||||
host_id: vm.host_id || hostId.value,
|
host_id: metricsHostId,
|
||||||
vm_name: vm.name,
|
vm_name: vm.name,
|
||||||
start: start.toISOString(),
|
start: start.toISOString(),
|
||||||
end_time: now.toISOString(),
|
end_time: now.toISOString(),
|
||||||
|
|||||||
Reference in New Issue
Block a user