fix: Fix the issue of abnormal time filtering in GPU monitoring (#11139)

This commit is contained in:
ssongliu 2025-12-01 16:43:38 +08:00 committed by GitHub
parent 94f7d78cc9
commit d4edf2f874
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 19 additions and 15 deletions

View file

@ -20,6 +20,7 @@ import (
"github.com/1Panel-dev/1Panel/agent/utils/common" "github.com/1Panel-dev/1Panel/agent/utils/common"
"github.com/1Panel-dev/1Panel/agent/utils/controller" "github.com/1Panel-dev/1Panel/agent/utils/controller"
"github.com/1Panel-dev/1Panel/agent/utils/ntp" "github.com/1Panel-dev/1Panel/agent/utils/ntp"
"github.com/1Panel-dev/1Panel/agent/utils/psutil"
"github.com/shirou/gopsutil/v4/mem" "github.com/shirou/gopsutil/v4/mem"
) )
@ -134,6 +135,7 @@ func (u *DeviceService) Update(key, value string) error {
if err := cmd.RunDefaultBashCf("%s hostnamectl set-hostname %s", cmd.SudoHandleCmd(), value); err != nil { if err := cmd.RunDefaultBashCf("%s hostnamectl set-hostname %s", cmd.SudoHandleCmd(), value); err != nil {
return err return err
} }
_, _ = psutil.HOST.GetHostInfo(true)
case "Ntp", "LocalTime": case "Ntp", "LocalTime":
if cmd.CheckIllegal(value) { if cmd.CheckIllegal(value) {
return buserr.New("ErrCmdIllegal") return buserr.New("ErrCmdIllegal")

View file

@ -178,7 +178,6 @@ const chartsOption = ref({
loadSpeedChart: null, loadSpeedChart: null,
}); });
const searchTime = ref();
const searchInfo = reactive<Host.MonitorGPUSearch>({ const searchInfo = reactive<Host.MonitorGPUSearch>({
productName: '', productName: '',
startTime: new Date(new Date().setHours(0, 0, 0, 0)), startTime: new Date(new Date().setHours(0, 0, 0, 0)),
@ -201,27 +200,30 @@ const loadOptions = async () => {
}; };
const search = async () => { const search = async () => {
if (searchTime.value && searchTime.value.length === 2) { if (timeRangeGlobal.value && timeRangeGlobal.value.length === 2) {
searchInfo.startTime = searchTime.value[0]; searchInfo.startTime = timeRangeGlobal.value[0];
searchInfo.endTime = searchTime.value[1]; searchInfo.endTime = timeRangeGlobal.value[1];
} }
loading.value = true; loading.value = true;
await loadGPUMonitor(searchInfo) await loadGPUMonitor(searchInfo)
.then((res) => { .then((res) => {
loading.value = false; loading.value = false;
let baseDate = res.data.date.length === 0 ? loadEmptyDate(timeRangeGlobal.value) : res.data.date; let baseDate = res.data.date || [];
if (baseDate.length === 0) {
baseDate = loadEmptyDate(timeRangeGlobal.value);
}
let date = baseDate.map(function (item: any) { let date = baseDate.map(function (item: any) {
return dateFormatWithoutYear(item); return dateFormatWithoutYear(item);
}); });
initCPUCharts(date, res.data.gpuValue); initCPUCharts(date, res.data.gpuValue || []);
initMemoryCharts(date, res.data.memoryValue); initMemoryCharts(date, res.data.memoryValue || []);
if (gpuType.value === 'gpu') { if (gpuType.value === 'gpu') {
initPowerCharts(date, res.data.powerValue); initPowerCharts(date, res.data.powerValue || []);
} else { } else {
initXpuPowerCharts(date, res.data.powerValue); initXpuPowerCharts(date, res.data.powerValue || []);
} }
initSpeedCharts(date, res.data.speedValue); initSpeedCharts(date, res.data.speedValue || []);
initTemperatureCharts(date, res.data.temperatureValue); initTemperatureCharts(date, res.data.temperatureValue || []);
}) })
.catch(() => { .catch(() => {
loading.value = false; loading.value = false;
@ -370,8 +372,8 @@ function loadEmptyData() {
} }
function loadEmptyData2() { function loadEmptyData2() {
return [ return [
{ value: 0, data: {} }, { value: 0, data: { total: 0, used: 0 } },
{ value: 0, data: {} }, { value: 0, data: { total: 0, used: 0 } },
]; ];
} }

View file

@ -9,7 +9,7 @@
<template #footer> <template #footer>
<span class="dialog-footer"> <span class="dialog-footer">
<el-button @click="drawerVisible = false">{{ $t('commons.button.cancel') }}</el-button> <el-button @click="drawerVisible = false">{{ $t('commons.button.cancel') }}</el-button>
<el-button :disabled="loading" type="primary" @click="onSaveHostame(formRef)"> <el-button :disabled="loading" type="primary" @click="onSaveHostname(formRef)">
{{ $t('commons.button.confirm') }} {{ $t('commons.button.confirm') }}
</el-button> </el-button>
</span> </span>
@ -43,7 +43,7 @@ const acceptParams = (params: DialogProps): void => {
drawerVisible.value = true; drawerVisible.value = true;
}; };
const onSaveHostame = async (formEl: FormInstance | undefined) => { const onSaveHostname = async (formEl: FormInstance | undefined) => {
if (!formEl) return; if (!formEl) return;
formEl.validate(async (valid) => { formEl.validate(async (valid) => {
if (!valid) return; if (!valid) return;